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/definition.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/definition.dart
diff --git a/petitparser/lib/src/core/definition.dart b/packages/petitparser/lib/src/petitparser/definition.dart
similarity index 53%
rename from petitparser/lib/src/core/definition.dart
rename to packages/petitparser/lib/src/petitparser/definition.dart
index bd94d69f033ab67e331ca2b3af45579033742553..44b7d72fe0c7a55c2b598a23ff952f1090554517 100644
--- a/petitparser/lib/src/core/definition.dart
+++ b/packages/petitparser/lib/src/petitparser/definition.dart
@@ -1,62 +1,56 @@
part of petitparser;
-/**
- * Helper to conveniently define and build complex, recursive grammars using
- * plain Dart code.
- *
- * To create a new grammar definition subclass [GrammarDefinition]. For every
- * production create a new method returning the primitive parser defining it.
- * The method called [start] is supposed to return the start production of the
- * grammar. To refer to a production defined in the same definition use [ref]
- * with the function reference as the first argument.
- *
- * Consider the following example to parse a list of numbers:
- *
- * class ListGrammarDefinition extends GrammarDefinition {
- * start() => ref(list).end();
- * list() => ref(element) & char(',') & ref(list)
- * | ref(element);
- * element() => digit().plus().flatten();
- * }
- *
- * Since this is plain Dart code, common refactorings such as renaming a production
- * updates all references correctly. Also code navigation and code completion
- * works as expected.
- *
- * To attach custom production actions you might want to further subclass your
- * grammar definition and override overriding the necessary productions defined
- * in the superclass:
- *
- * class ListParserDefinition extends ListGrammarDefinition {
- * element() => super.element().map((value) => int.parse(value));
- * }
- *
- * Note that productions can be parametrized. Define such productions with positional
- * arguments and reference to multiple instances by passing the arguments to [ref].
- *
- * Consider extending the above grammar with a parametrized token production:
- *
- * class TokenizedListGrammarDefinition extends GrammarDefinition {
- * start() => ref(list).end();
- * list() => ref(element) & ref(token, char(',')) & ref(list)
- * | ref(element);
- * element() => ref(token, digit().plus());
- * token(p) => p.token().trim();
- * }
- */
+/// Helper to conveniently define and build complex, recursive grammars using
+/// plain Dart code.
+///
+/// To create a new grammar definition subclass [GrammarDefinition]. For every
+/// production create a new method returning the primitive parser defining it.
+/// The method called [start] is supposed to return the start production of the
+/// grammar. To refer to a production defined in the same definition use [ref]
+/// with the function reference as the first argument.
+///
+/// Consider the following example to parse a list of numbers:
+///
+/// class ListGrammarDefinition extends GrammarDefinition {
+/// start() => ref(list).end();
+/// list() => ref(element) & char(',') & ref(list)
+/// | ref(element);
+/// element() => digit().plus().flatten();
+/// }
+///
+/// Since this is plain Dart code, common refactorings such as renaming a production
+/// updates all references correctly. Also code navigation and code completion
+/// works as expected.
+///
+/// To attach custom production actions you might want to further subclass your
+/// grammar definition and override overriding the necessary productions defined
+/// in the superclass:
+///
+/// class ListParserDefinition extends ListGrammarDefinition {
+/// element() => super.element().map((value) => int.parse(value));
+/// }
+///
+/// Note that productions can be parametrized. Define such productions with positional
+/// arguments and reference to multiple instances by passing the arguments to [ref].
+///
+/// Consider extending the above grammar with a parametrized token production:
+///
+/// class TokenizedListGrammarDefinition extends GrammarDefinition {
+/// start() => ref(list).end();
+/// list() => ref(element) & ref(token, char(',')) & ref(list)
+/// | ref(element);
+/// element() => ref(token, digit().plus());
+/// token(p) => p.token().trim();
+/// }
abstract class GrammarDefinition {
const GrammarDefinition();
- /**
- * The starting production of this definition.
- */
+ /// The starting production of this definition.
Parser start();
- /**
- * Returns a parser reference to a production defined by a [function].
- *
- * The optional arguments parametrize the called production.
- */
+ /// Returns a parser reference to a production defined by a [function].
+ ///
+ /// The optional arguments parametrize the called production.
Parser ref(Function function, [arg1, arg2, arg3, arg4, arg5, arg6]) {
var arguments = [arg1, arg2, arg3, arg4, arg5, arg6]
.takeWhile((each) => each != null)
@@ -64,20 +58,16 @@ abstract class GrammarDefinition {
return new _Reference(function, arguments);
}
- /**
- * Builds a composite parser from this definition.
- *
- * The optional [start] reference specifies a different starting production into
- * the grammar. The optional [arguments] list parametrizes the called production.
- */
+ /// Builds a composite parser from this definition.
+ ///
+ /// The optional [start] reference specifies a different starting production into
+ /// the grammar. The optional [arguments] list parametrizes the called production.
Parser build({Function start: null, List arguments: const []}) {
return _resolve(
new _Reference(start != null ? start : this.start, arguments));
}
- /**
- * Internal helper to resolve a complete parser graph.
- */
+ /// Internal helper to resolve a complete parser graph.
Parser _resolve(_Reference reference) {
var mapping = new Map();
@@ -122,9 +112,7 @@ abstract class GrammarDefinition {
}
}
-/**
- * A helper to build a parser from a {@link GrammarDefinition}.
- */
+/// A helper to build a parser from a {@link GrammarDefinition}.
class GrammarParser extends DelegateParser {
GrammarParser(GrammarDefinition definition) : super(definition.build());
}
« no previous file with comments | « packages/petitparser/lib/src/petitparser/context.dart ('k') | packages/petitparser/lib/src/petitparser/expression.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698