Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: packages/petitparser/lib/src/petitparser/token.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: packages/petitparser/lib/src/petitparser/token.dart
diff --git a/petitparser/lib/src/core/token.dart b/packages/petitparser/lib/src/petitparser/token.dart
similarity index 50%
rename from petitparser/lib/src/core/token.dart
rename to packages/petitparser/lib/src/petitparser/token.dart
index 683cbe71a89ab573d24edbf7ba23a6da8188efb4..5fd8dcfa972f78100fe050a643b47109eaacdfe6 100644
--- a/petitparser/lib/src/core/token.dart
+++ b/packages/petitparser/lib/src/petitparser/token.dart
@@ -1,60 +1,40 @@
part of petitparser;
-/**
- * A token represents a parsed part of the input stream.
- *
- * The token holds the resulting value of the input, the input buffer,
- * and the start and stop position in the input buffer. It provides many
- * convenience methods to access the state of the token.
- */
+/// A token represents a parsed part of the input stream.
+///
+/// The token holds the resulting value of the input, the input buffer,
+/// and the start and stop position in the input buffer. It provides many
+/// convenience methods to access the state of the token.
class Token {
- /**
- * The parsed value of the token.
- */
+ /// The parsed value of the token.
final value;
- /**
- * The parsed buffer of the token.
- */
+ /// The parsed buffer of the token.
final buffer;
- /**
- * The start position of the token in the buffer.
- */
+ /// The start position of the token in the buffer.
final int start;
- /**
- * The stop position of the token in the buffer.
- */
+ /// The stop position of the token in the buffer.
final int stop;
- /**
- * Constructs a token from the parsed value, the input buffer, and the
- * start and stop position in the input buffer.
- */
+ /// Constructs a token from the parsed value, the input buffer, and the
+ /// start and stop position in the input buffer.
const Token(this.value, this.buffer, this.start, this.stop);
- /**
- * The consumed input of the token.
- */
+ /// The consumed input of the token.
get input => buffer is String
? buffer.substring(start, stop)
: buffer.sublist(start, stop);
- /**
- * The length of the token.
- */
+ /// The length of the token.
int get length => stop - start;
- /**
- * The line number of the token (only works for [String] buffers).
- */
+ /// The line number of the token (only works for [String] buffers).
int get line => Token.lineAndColumnOf(buffer, start)[0];
- /**
- * The column number of this token (only works for [String] buffers).
- */
+ /// The column number of this token (only works for [String] buffers).
int get column => Token.lineAndColumnOf(buffer, start)[1];
@override
@@ -71,17 +51,12 @@ class Token {
@override
int get hashCode => value.hashCode + start.hashCode + stop.hashCode;
- static final Parser _NEWLINE_PARSER =
- char('\n').or(char('\r').seq(char('\n').optional()));
+ /// Returns a parser for that detects newlines platform independently.
+ static Parser newlineParser() => _newlineParser;
- /**
- * Returns a parser for that detects newlines platform independently.
- */
- static Parser newlineParser() => _NEWLINE_PARSER;
+ static final Parser _newlineParser = char('\n') | (char('\r') & char('\n').optional());
- /**
- * Converts the [position] index in a [buffer] to a line and column tuple.
- */
+ /// Converts the [position] index in a [buffer] to a line and column tuple.
static List<int> lineAndColumnOf(String buffer, int position) {
var line = 1, offset = 0;
for (var token in newlineParser().token().matchesSkipping(buffer)) {
@@ -94,15 +69,13 @@ class Token {
return [line, position - offset + 1];
}
- /**
- * Returns a human readable string representing the [position] index in a [buffer].
- */
+ /// Returns a human readable string representing the [position] index in a [buffer].
static String positionString(buffer, int position) {
if (buffer is String) {
var lineAndColumn = Token.lineAndColumnOf(buffer, position);
return '${lineAndColumn[0]}:${lineAndColumn[1]}';
} else {
- return '${position}';
+ return '$position';
}
}
}
« no previous file with comments | « packages/petitparser/lib/src/petitparser/repeaters.dart ('k') | packages/petitparser/lib/src/reflection/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698