Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop Pair util class
Browse files Browse the repository at this point in the history
kevmoo committed Aug 28, 2024

Verified

This commit was signed with the committer’s verified signature.
binbin-li Binbin Li
1 parent a645c39 commit fcc52e0
Showing 3 changed files with 9 additions and 22 deletions.
8 changes: 3 additions & 5 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
@@ -174,9 +174,7 @@ class Parser {

// Parse an explicit document.
var start = token.span;
var pair = _processDirectives();
var versionDirective = pair.first;
var tagDirectives = pair.last;
var (versionDirective, tagDirectives) = _processDirectives();
token = _scanner.peek()!;
if (token.type != TokenType.documentStart) {
throw YamlException('Expected document start.', token.span);
@@ -667,7 +665,7 @@ class Parser {
ScalarEvent(location.pointSpan() as FileSpan, '', ScalarStyle.PLAIN);

/// Parses directives.
Pair<VersionDirective?, List<TagDirective>> _processDirectives() {
(VersionDirective?, List<TagDirective>) _processDirectives() {
var token = _scanner.peek()!;

VersionDirective? versionDirective;
@@ -707,7 +705,7 @@ class Parser {
TagDirective('!!', 'tag:yaml.org,2002:'), token.span.start.pointSpan(),
allowDuplicates: true);

return Pair(versionDirective, tagDirectives);
return (versionDirective, tagDirectives);
}

/// Adds a tag directive to the directives stack.
12 changes: 6 additions & 6 deletions lib/src/scanner.dart
Original file line number Diff line number Diff line change
@@ -1142,8 +1142,8 @@ class Scanner {
// Scan the leading line breaks to determine the indentation level if
// needed.
var pair = _scanBlockScalarBreaks(indent);
indent = pair.first;
var trailingBreaks = pair.last;
indent = pair.indent;
var trailingBreaks = pair.trailingBreaks;

// Scan the block scalar contents.
var buffer = StringBuffer();
@@ -1194,8 +1194,8 @@ class Scanner {

// Eat the following indentation and spaces.
var pair = _scanBlockScalarBreaks(indent);
indent = pair.first;
trailingBreaks = pair.last;
indent = pair.indent;
trailingBreaks = pair.trailingBreaks;
}

// Chomp the tail.
@@ -1210,7 +1210,7 @@ class Scanner {
///
/// Determines the intendation level if needed. Returns the new indentation
/// level and the text of the line breaks.
Pair<int, String> _scanBlockScalarBreaks(int indent) {
({int indent, String trailingBreaks}) _scanBlockScalarBreaks(int indent) {
var maxIndent = 0;
var breaks = StringBuffer();

@@ -1238,7 +1238,7 @@ class Scanner {
// be supported by the spec.
}

return Pair(indent, breaks.toString());
return (indent: indent, trailingBreaks: breaks.toString());
}

// Scans a quoted scalar.
11 changes: 0 additions & 11 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -7,17 +7,6 @@

import 'package:source_span/source_span.dart';

/// A pair of values.
class Pair<E, F> {
final E first;
final F last;

Pair(this.first, this.last);

@override
String toString() => '($first, $last)';
}

/// Print a warning.
///
/// If [span] is passed, associates the warning with that span.

0 comments on commit fcc52e0

Please sign in to comment.