| OLD | NEW |
| (Empty) |
| 1 part of debug; | |
| 2 | |
| 3 /** | |
| 4 * Handler function for the [ContinuationParser]. | |
| 5 */ | |
| 6 typedef Result ContinuationHandler( | |
| 7 Result continuation(Context context), Context context); | |
| 8 | |
| 9 /** | |
| 10 * Continuation parser that when activated captures a continuation function | |
| 11 * and passes it together with the current context into the handler. | |
| 12 * | |
| 13 * Handlers are not required to call the continuation, but can completely ignore | |
| 14 * it, call it multiple times, and/or store it away for later use. Similarly | |
| 15 * handlers can modify the current context and/or modify the returned result. | |
| 16 * | |
| 17 * The following example shows a simple wrapper. Messages are printed before and | |
| 18 * after the `digit()` parser is activated: | |
| 19 * | |
| 20 * var wrapped = digit(); | |
| 21 * var parser = new ContinuationParser(wrapped, (continuation, context) { | |
| 22 * print('Parser will be activated, the context is $context.'); | |
| 23 * var result = continuation(context); | |
| 24 * print('Parser was activated, the result is $result.'); | |
| 25 * return result; | |
| 26 * }); | |
| 27 * | |
| 28 * See [profile], [progress], and [trace] for more elaborate examples. | |
| 29 */ | |
| 30 class ContinuationParser extends DelegateParser { | |
| 31 final ContinuationHandler handler; | |
| 32 | |
| 33 ContinuationParser(parser, this.handler) : super(parser); | |
| 34 | |
| 35 @override | |
| 36 Result parseOn(Context context) { | |
| 37 return handler((result) => super.parseOn(result), context); | |
| 38 } | |
| 39 | |
| 40 @override | |
| 41 Parser copy() => new ContinuationParser(children[0], handler); | |
| 42 } | |
| OLD | NEW |