I am using Grammar::Tracer with the following setup:
p.p6
use v6;
use lib '.';
use MyGrammar;
my $res = MyGrammar.parse('hello 6 9 bye');
say $res;
MyGrammar.pm6:
unit grammar MyGrammar;
use Grammar::Tracer;
rule TOP { [<number> || <word> ]* }
rule number { \d+ }
rule word { \w+}
But the tracing is not enabled. I guess it is because the grammer MyGrammar
is not in the lexical scope of the use Grammar::Tracer
statement?
The Grammar::Tracer
module works by exporting a custom metaclass to be used in place of the default one for the grammar
keyword. This must already be in place before the keyword grammar
is encountered, since that is when we resolve and commit to the metaclass to be used for the type being declared.
The solution is to put the use
statement ahead of the grammar
declaration:
use Grammar::Tracer;
unit grammar MyGrammar;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With