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

Unified Diff: packages/petitparser/lib/src/debug/continuation.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
« no previous file with comments | « packages/petitparser/lib/src/dart/grammar.dart ('k') | packages/petitparser/lib/src/debug/profile.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/petitparser/lib/src/debug/continuation.dart
diff --git a/packages/petitparser/lib/src/debug/continuation.dart b/packages/petitparser/lib/src/debug/continuation.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b673bd916178d5599cf33908949d53491bf65344
--- /dev/null
+++ b/packages/petitparser/lib/src/debug/continuation.dart
@@ -0,0 +1,38 @@
+part of petitparser.debug;
+
+/// Handler function for the [ContinuationParser].
+typedef Result ContinuationHandler(
+ Result continuation(Context context), Context context);
+
+/// Continuation parser that when activated captures a continuation function
+/// and passes it together with the current context into the handler.
+///
+/// Handlers are not required to call the continuation, but can completely ignore
+/// it, call it multiple times, and/or store it away for later use. Similarly
+/// handlers can modify the current context and/or modify the returned result.
+///
+/// The following example shows a simple wrapper. Messages are printed before and
+/// after the `digit()` parser is activated:
+///
+/// var wrapped = digit();
+/// var parser = new ContinuationParser(wrapped, (continuation, context) {
+/// print('Parser will be activated, the context is $context.');
+/// var result = continuation(context);
+/// print('Parser was activated, the result is $result.');
+/// return result;
+/// });
+///
+/// See [profile], [progress], and [trace] for more elaborate examples.
+class ContinuationParser extends DelegateParser {
+ final ContinuationHandler handler;
+
+ ContinuationParser(parser, this.handler) : super(parser);
+
+ @override
+ Result parseOn(Context context) {
+ return handler((result) => super.parseOn(result), context);
+ }
+
+ @override
+ Parser copy() => new ContinuationParser(children[0], handler);
+}
« no previous file with comments | « packages/petitparser/lib/src/dart/grammar.dart ('k') | packages/petitparser/lib/src/debug/profile.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698