Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar 'ident' override behaviour #3246

Open
p6rt opened this issue Oct 8, 2013 · 7 comments
Open

Grammar 'ident' override behaviour #3246

p6rt opened this issue Oct 8, 2013 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 8, 2013

Migrated from rt.perl.org#120146 (status was 'open')

Searchable as RT120146$

@p6rt
Copy link
Author

p6rt commented Oct 8, 2013

From @dwarring

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.

@p6rt
Copy link
Author

p6rt commented Oct 9, 2013

From @dwarring

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

@p6rt
Copy link
Author

p6rt commented Oct 9, 2013

@dwarring - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 31, 2013

From @dwarring

I've added a failing (todo) test to S05-grammar/protoregex.t in perl6/roast.

@p6rt
Copy link
Author

p6rt commented Sep 21, 2014

From @dwarring

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.

@p6rt
Copy link
Author

p6rt commented Sep 21, 2014

From @dwarring

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);

@p6rt p6rt added the Bug label Jan 5, 2020
@dwarring
Copy link

dwarring commented Feb 27, 2020

Maybe the built-in rules should('ve) be uppercase anyway, e.g. "abc" ~~ /<IDENT>/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants