jnthn / grammar-debugger

Grammar::Debugger and Grammer::Tracer Perl 6 modules
36 stars 20 forks source link

failure using Grammar::Tracer #40

Open tbrowder opened 6 years ago

tbrowder commented 6 years ago

The failing code is detailed in gist https://gist.github.com/tbrowder/db2a3a80d09e5fddaf755ecc42178953 and is repeated below:

# cat file: lib/Presenters.pm6
unit module Presenters;
use Grammar::Tracer;
grammar Presenters::PGrammar {
    token TOP {
        [
            | <entry>
            | <blank>
        ]+
    }
    token entry   { <key> <sep> <value> }
    token key     { \h* \w+ }
    token sep     { \h* ':' \h* }
    token value   { \N+ }
    token blank   { \h* \n }
}

# cat file: ./test-presenters.data
id: laue-d 
name: Lauer, Denny 
id: horn-a
name: Hornstein, Anne
id: bran-e
name: Branch, Eddie

# cat file: ./grammar-test-fail.p6
#!/usr/bin/env perl6
use lib <./lib>;
use Presenters;
my $pfil  = "test-presenters.data";
my $mp = Presenters::PGrammar.parse(slurp $pfil);
say "WARNING: Presenters grammar failed to match." if !$mp;
say $mp;

# executing
./grammar-test-fail.p6
TOP
Cannot invoke this object (REPR: Null; VMNull)
  in block  at /usr/local/rakudo.d/share/perl6/site/sources/C0DCFF5AEFDF38901A375AE53AF39C4F12B3F6FC (Grammar::Tracer) line 43
  in regex TOP at /usr/local/people/tbrowde/mydata/tbrowde-home-bzr/mydomains/domains/primary-web-servers/web-sites/computertechnwf.org/public/lib/Presenters.pm6 (Presenters) line 6
  in block  at /usr/local/rakudo.d/share/perl6/site/sources/C0DCFF5AEFDF38901A375AE53AF39C4F12B3F6FC (Grammar::Tracer) line 49
  in block <unit> at ./grammar-test-fail.p6 line 7

After removing "use Grammar::Tracer" the code runs to completion:

# executing
./grammar-test-fail.p6
「id: laue-d
name: Lauer, Denny
id: horn-a
name: Hornstein, Anne
id: bran-e
name: Branch, Eddie
」
 entry => 「id: laue-d」
  key => 「id」
  sep => 「: 」
  value => 「laue-d」
 blank => 「
」
 entry => 「name: Lauer, Denny」
  key => 「name」
  sep => 「: 」
  value => 「Lauer, Denny」
 blank => 「
」
 entry => 「id: horn-a」
  key => 「id」
  sep => 「: 」
  value => 「horn-a」
 blank => 「
」
 entry => 「name: Hornstein, Anne」
  key => 「name」
  sep => 「: 」
  value => 「Hornstein, Anne」
 blank => 「
」
 entry => 「id: bran-e」
  key => 「id」
  sep => 「: 」
  value => 「bran-e」
 blank => 「
」
 entry => 「name: Branch, Eddie」
  key => 「name」
  sep => 「: 」
  value => 「Branch, Eddie」
 blank => 「
」

Note that if I use "Grammar::Tracer::Compact"" all works well.

llelf commented 6 years ago

“me too” comment.

Grammar::Debugger:ver<1.0.1>:auth<github:jnthn>
Rakudo version 2018.02.1 built on MoarVM version 2018.02
jnthn commented 6 years ago

As a workaround, add no precompilation; above the use Grammar::Tracer line. (An easy fix will probably be to stick that line in `Grammar::Tracer itself, though that's probably only hiding the real issue).

ronaldxs commented 6 years ago

Hit more or less identical symptom playing with Grammar::Modelica . Switching from | to || (LTM to regular alternation) worked for the Grammar::Modelica case and also worked when I tried it with Presenters::PGrammar. no precompilation; also worked for the Grammar::Modelica example.