Skip Menu |
Report information
Id: 130218
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: alex.jakimenko [at] gmail.com
Cc:
AdminCc:

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



Subject: [REGEX] Erroneous behavior when creating tokens named “before” or “after” (token TOP { <before> }; token before { . })
Download (untitled) / with headers
text/plain 905b
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」
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:
Show quoted text
> 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」




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