progress<R> function
- @useResult
- Parser<
R> root, { - void output(
- ProgressFrame frame
- bool predicate(
- Parser parser
Returns a transformed Parser that, when used to read input, visually prints its progress.
For example, the snippet
final parser = letter() & word().star();
progress(parser).parse('f123');
prints the following output:
* SequenceParser<dynamic>
* SingleCharacterParser[letter expected]
** PossessiveRepeatingParser<String>[0..*]
** SingleCharacterParser[letter or digit expected]
*** SingleCharacterParser[letter or digit expected]
**** SingleCharacterParser[letter or digit expected]
***** SingleCharacterParser[letter or digit expected]
Jumps backwards mean that the parser is back-tracking. Often choices can be reordered to avoid such expensive parses.
The optional output callback can be used to continuously receive
ProgressFrame updates with the current progress information.
Implementation
@useResult
Parser<R> progress<R>(
Parser<R> root, {
void Function(ProgressFrame frame) output = print,
bool Function(Parser parser)? predicate,
}) => transformParser(root, <P>(parser) {
if (predicate == null || predicate(parser)) {
return parser.callCC((continuation, context) {
output(_ProgressFrame(parser, context));
return continuation(context);
});
} else {
return parser;
}
});