progress<R> function

  1. @useResult
Parser<R> progress<R>(
  1. Parser<R> root, {
  2. VoidCallback<ProgressFrame> output = print,
  3. Predicate<Parser>? predicate,
})

Returns a transformed Parser that when being used to read input visually prints its progress while progressing.

For example, the snippet

final parser = letter() & word().star();
progress(parser).parse('f123');

prints the following output:

* SequenceParser
* SingleCharacterParser[letter expected]
** PossessiveRepeatingParser[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,
        {VoidCallback<ProgressFrame> output = print,
        Predicate<Parser>? predicate}) =>
    transformParser(root, <R>(parser) {
      if (predicate == null || predicate(parser)) {
        return parser.callCC((continuation, context) {
          output(_ProgressFrame(parser, context));
          return continuation(context);
        });
      } else {
        return parser;
      }
    });