dartpetitparser

Unsupported operation: References cannot be parsed


static const String tabChar = '\u0009';
Parser tab() => ref(token, tabChar);
expect(tab().accept(tabChar), isTrue);

with the token method from https://github.com/petitparser/dart-petitparser/blob/ddd9921d702dd18cda4e2f84190777b7dc20b3e2/example/dart/src/grammar.dart (with the default trim parser)

What needs to be changed to get rid of the error?

Unsupported operation: References cannot be parsed


Solution

  • There are unresolved references in your parser graph, you need to resolve them before you can parse an input.

    Your example code lacks context to tell exactly what is going wrong. If you subclass GrammarDefinition and call build() on the definition the resulting parser has all references resolved. Have a look at the documentation in GrammarDefinition and check out how the DartGrammarDefinition is used from its tests.