| OLD | NEW |
| (Empty) |
| 1 part of debug; | |
| 2 | |
| 3 /** | |
| 4 * Returns a transformed [parser] that when being used to read input prints a | |
| 5 * trace of all activated parsers and their respective parse results. | |
| 6 * | |
| 7 * For example, the snippet | |
| 8 * | |
| 9 * var parser = letter() & word().star(); | |
| 10 * trace(parser).parse('f1'); | |
| 11 * | |
| 12 * produces the following output: | |
| 13 * | |
| 14 * Instance of 'SequenceParser' | |
| 15 * Instance of 'CharacterParser'[letter expected] | |
| 16 * Success[1:2]: f | |
| 17 * Instance of 'PossessiveRepeatingParser'[0..*] | |
| 18 * Instance of 'CharacterParser'[letter or digit expected] | |
| 19 * Success[1:3]: 1 | |
| 20 * Instance of 'CharacterParser'[letter or digit expected] | |
| 21 * Failure[1:3]: letter or digit expected | |
| 22 * Success[1:3]: [1] | |
| 23 * Success[1:3]: [f, [1]] | |
| 24 * | |
| 25 * Indentation signifies the activation of a parser object. Reverse indentation | |
| 26 * signifies the returning of a parse result either with a success or failure | |
| 27 * context. | |
| 28 */ | |
| 29 Parser trace(Parser parser, [OutputHandler output = print]) { | |
| 30 var level = 0; | |
| 31 return transformParser(parser, (each) { | |
| 32 return new ContinuationParser(each, (continuation, context) { | |
| 33 output('${_repeat(level, ' ')}${each}'); | |
| 34 level++; | |
| 35 var result = continuation(context); | |
| 36 level--; | |
| 37 output('${_repeat(level, ' ')}${result}'); | |
| 38 return result; | |
| 39 }); | |
| 40 }); | |
| 41 } | |
| OLD | NEW |