Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Pair util class #169

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions lib/src/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -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();

Expand Down Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down