Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to get Grammar::Tracer working on Perl6 itself?

Tags:

grammar

raku

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?

like image 331
Marty Avatar asked Mar 29 '16 21:03

Marty


1 Answers

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?

like image 143
Matt Oates Avatar answered Oct 16 '22 07:10

Matt Oates