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