6

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?

Marty
  • 2,788
  • 11
  • 17

1 Answers1

4

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?

Matt Oates
  • 778
  • 4
  • 6
  • It does help - and I've +1'd for the clue to use STD - but it leaves open how to rebuild perl6 such that it uses STD. – Marty Apr 13 '16 at 21:35
  • 1
    So you dont want tracing of Perl 6 but tracing of Rakudos parse step as it's doing it? --target=parse is essentially that if you look at the first grammar link I gave and your output. You can use Grammar.parse() with STD to parse some code outside of the compile step - that you could trace - but it doesnt necessarily reflect what Rakudo is doing. If you go on the IRC channel #perl6 on freenode they might have some better suggestions. – Matt Oates Apr 14 '16 at 06:48