Skip Menu |
Report information
Id: 120146
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: david.warring <david.warring [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Grammar parsing failure
Date: Tue, 8 Oct 2013 06:31:51 +1100
To: rakudobug [...] perl.org
From: David Warring <david.warring [...] gmail.com>
Download (untitled) / with headers
text/plain 1.1k
The final parse below is failing to match (golfed from CSS::Grammar):

    use v6;
   #use Grammar::Tracer;

    grammar G {

        token nmstrt   {<[_ a..z A..Z]>}
        token nmreg    {<[_ \- a..z A..Z 0..9]>+}
        token ident    {'-'?<nmstrt><nmreg>*}
        token num      {[\+|\-]? (\d* \.)? \d+}

        proto token term { <...> }
        token term:sym<ident>      {<ident>}
        token term:sym<num>        {<num>}

    }

    say G.parse("-my-ident", :rule<ident>);   # parsing
    use v6;

    grammar G {

        token nmstrt   {<[_ a..z A..Z]>}
        token nmreg    {<[_ \- a..z A..Z 0..9]>+}
        token ident    {'-'?<nmstrt><nmreg>*}
        token num      {[\+|\-]? (\d* \.)? \d+}

        proto token term { <...> }
        token term:sym<ident>      {<ident>}
        token term:sym<num>        {<num>}

    }

    say G.parse("-my-ident", :rule<ident>);   # parsing
    say G.parse("my-ident", :rule<term>);     # parsing
    say G.parse("-my-ident", :rule<term>);    # not parsing

Parse failing on both Parrot and JVM.This has been a problem since about 29th Sept.

Parse succeeds if I uncomment 'use Grammar::Tracer', ie Heisenbug.

Download (untitled) / with headers
text/plain 595b
Gaah, sorry about the jumble above. Sample case restated below: use v6; ## use Grammar::Tracer; grammar G { token nmstrt {<[_ a..z A..Z]>} token nmreg {<[_ \- a..z A..Z 0..9]>} token ident {['-']?<nmstrt><nmreg>*} token num {[\+|\-]? (\d* \.)? \d+} proto token term { <...> } token term:sym<ident> {<ident>} token term:sym<num> {<num>} } say G.parse("-my-ident", :rule<ident>); # ok say G.parse("my-ident", :rule<term>); # ok say G.parse("-my-ident", :rule<term>); # failing
I've added a failing (todo) test to S05-grammar/protoregex.t in perl6/roast.
I've converted the test case to NQP: # nqp bisection for RT #120146 # good 62b8cab951394beff10c6d481d63c1f9a945a1cb # bad 8f719a567c3c4ddba5ef202151fd37ba2ad41355 say("1..1"); grammar G { token nmstrt {<[ _ a..z ]>} token nmreg {<[ _ \- a..z 0..9]>+} token ident {'-'?<nmstrt><nmreg>*} token num {[\+|\-]?\d+} proto token term {*} token term:sym<ident> {<id=.ident>} token term:sym<num> {<num>} } my $result := 'nok'; my $exit-status := 1; if (G.parse("-my_id", :rule<term>)) { $result := 'ok'; $exit-status := 0; } say("$result - term parse"); nqp::exit($result eq 'ok' ?? 0 !! 1); ...and bisected in NQP: commit 9ee3ed7235c9f7110d119ef748cac39a62517e77 Author: jnthn <jnthn@jnthn.net> Date: Tue Oct 1 00:07:51 2013 +0200 Treat ident declaratively. timotimo++ and diakopter++ Aha. with that commit, ident is now treated more declatively, so re-declaring ident has become problematic.
Download (untitled) / with headers
text/plain 582b
I've added another test to S05-grammar/protoregex.t for the following variation - 'ident' as an alias: say("1..1"); grammar G { token nmstrt {<[ _ a..z ]>} token nmreg {<[ _ \- a..z 0..9]>+} token my-id {'-'?<nmstrt><nmreg>*} token num {[\+|\-]?\d+} proto token term {*} token term:sym<ident> {<ident=.my-id>} token term:sym<num> {<num>} } my $result := 'nok'; my $exit-status := 1; if (G.parse("-my_id", :rule<term>)) { $result := 'ok'; $exit-status := 0; } say("$result - term parse"); nqp::exit($result eq 'ok' ?? 0 !! 1);


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org