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

Erroneous behavior when creating tokens named “before” or “after” (token TOP { <before> }; token before { . }) #5841

Open
p6rt opened this issue Nov 29, 2016 · 2 comments
Labels
regex Regular expressions, pattern matching, user-defined grammars, tokens and rules

Comments

@p6rt
Copy link

p6rt commented Nov 29, 2016

Migrated from rt.perl.org#130218 (status was 'new')

Searchable as RT130218$

@p6rt
Copy link
Author

p6rt commented Nov 29, 2016

From @AlexDaniel

Code​:
grammar G {
  token TOP { <before> }
  token before { . }
}
say G.parse(�f�)

Result​:
===SORRY!===
Cannot find method 'ann' on object of type NQPMu

In other words, using <before> is a compile-time error. If we try the same thing with <after>, it may seem to work, but there is another issue with it​:

Code​:
grammar G {
  token TOP { <!after \d> }
  token after { . }
}
say G.parse(�f�)

Result​:
Too many positionals passed; expected 1 argument but got 2
  in regex after at -e line 3
  in regex TOP at -e line 2
  in block <unit> at -e line 5

So it is a run-time error, huh!

Obviously, both examples work if you name your tokens differently​:

Code​:
grammar G {
  token TOP { <!after \d> }
  token aftermath { . }
}
say G.parse(�f�)

Result​:
Nil

Code​:
grammar G {
  token TOP { <beforehead> }
  token beforehead { . }
}
say G.parse(�f�)

Result​:
ï½¢fï½£
beforehead => ï½¢fï½£

@p6rt
Copy link
Author

p6rt commented Nov 29, 2016

From @AlexDaniel

I forgot to mention this is actually something one of the users stumbled upon, see this IRC log​: https://irclog.perlgeek.de/perl6/2016-11-20#i_13598215

On 2016-11-29 15​:45​:50, alex.jakimenko@​gmail.com wrote​:

Code​:
grammar G {
token TOP { <before> }
token before { . }
}
say G.parse(‘f’)

Result​:
===SORRY!===
Cannot find method 'ann' on object of type NQPMu

In other words, using <before> is a compile-time error. If we try the
same thing with <after>, it may seem to work, but there is another
issue with it​:

Code​:
grammar G {
token TOP { <!after \d> }
token after { . }
}
say G.parse(‘f’)

Result​:
Too many positionals passed; expected 1 argument but got 2
in regex after at -e line 3
in regex TOP at -e line 2
in block <unit> at -e line 5

So it is a run-time error, huh!

Obviously, both examples work if you name your tokens differently​:

Code​:
grammar G {
token TOP { <!after \d> }
token aftermath { . }
}
say G.parse(‘f’)

Result​:
Nil

Code​:
grammar G {
token TOP { <beforehead> }
token beforehead { . }
}
say G.parse(‘f’)

Result​:
ï½¢fï½£
beforehead => ï½¢fï½£

@p6rt p6rt added the regex Regular expressions, pattern matching, user-defined grammars, tokens and rules label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regex Regular expressions, pattern matching, user-defined grammars, tokens and rules
Projects
None yet
Development

No branches or pull requests

1 participant