Closed adimit closed 4 years ago
In your example, trace
is trying to transform the grammar before it is built. As a workaround you could build your grammar starting at bar
(instead of the default start
). Something along these lines:
class MyGrammarDefinition extends GrammarDefinition {
Parser start() => ref(bar);
Parser foo() => letter();
Parser bar() => ref(foo);
}
void main() {
final grammar = MyGrammarDefinition();
final bar = grammar.build(start: grammar.bar);
final traced = trace(bar);
traced.parse('a');
}
Nice, thanks for your quick reply. I didn't know the grammar definition first had to be built. I guess the step was implicit.
Hi, I'm trying to debug a grammar that has several
ref
s everywhere. This is pretty much just how the examples do it, so I figured I'd take the same approach.Unfortunately, with something like
I can't just do e.g.
trace(bar)
, as that will tell me that References cannot be copied.I guess copying a function reference doesn't make much sense (in Dart.) Is there another way to debug parsers that contain
ref
s? Which I imagine is most of the non-trivial ones. Or am I overlooking something? Thanks!