OLD | NEW |
| (Empty) |
1 part of petitparser.debug; | |
2 | |
3 /// Returns a transformed [parser] that when being used to read input | |
4 /// visually prints its progress while progressing. | |
5 /// | |
6 /// For example, the snippet | |
7 /// | |
8 /// var parser = letter() & word().star(); | |
9 /// progress(parser).parse('f123'); | |
10 /// | |
11 /// produces the following output: | |
12 /// | |
13 /// * Instance of 'SequenceParser' | |
14 /// * Instance of 'CharacterParser'[letter expected] | |
15 /// ** Instance of 'PossessiveRepeatingParser'[0..*] | |
16 /// ** Instance of 'CharacterParser'[letter or digit expected] | |
17 /// *** Instance of 'CharacterParser'[letter or digit expected] | |
18 /// **** Instance of 'CharacterParser'[letter or digit expected] | |
19 /// ***** Instance of 'CharacterParser'[letter or digit expected] | |
20 /// | |
21 /// Jumps backwards mean that the parser is back-tracking. Often choices can | |
22 /// be reordered to such expensive parses. | |
23 Parser progress(Parser parser, [OutputHandler output = print]) { | |
24 return transformParser(parser, (each) { | |
25 return new ContinuationParser(each, (continuation, context) { | |
26 output('${_repeat(1 + context.position, '*')} $each'); | |
27 return continuation(context); | |
28 }); | |
29 }); | |
30 } | |
OLD | NEW |