To get an idea how perl6 parses your code, you can use the --target
option:
$ perl6 --target=parse -e '"Hello World".say'
- statementlist: "Hello World".say
- statement: 1 matches
- EXPR: .say
- 0: "Hello World"
- value: "Hello World"
- quote: "Hello World"
- nibble: Hello World
- OPER: .say
- sym: .
- dottyop: say
- methodop: say
- longname: say
- name: say
- identifier: say
- O: <object>
- dotty: .say
- sym: .
- dottyop: say
- methodop: say
- longname: say
- name: say
- identifier: say
- O: <object>
$
Far better is the Grammar::Tracer
module described here. According to the module documentation, one simply adds use Grammar::Tracer
and any grammar defined in the scope where the use statement appears will be traced.
My question is simply this: If I'm using a "star release", what's the easiest way to get tracing (using Grammar::Tracer) on the Perl6 Grammar itself?
Alternatively, if I'm using rakudobrew, what's the easiest way to get tracing on the Perl6 Grammar itself?
It's recommended that perl6 users use star releases - would a desire to examine more closely how perl6 parses itself, using Grammar::Tracer, be worth building from source locally instead?
So the grammar in Rakudo is near enough a Perl 6 grammar, but its implemented at the NQP level https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Grammar.nqp So the magic of Grammar::Tracer wont work here. However, you can use the STD grammar https://github.com/perl6/std/blob/master/STD.pm6 to parse some code and that should work with Grammar::Tracer, I've been fiddling around trying to get it to work with Grammar::Highlighter. Hope that helps?
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