Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Fwd: [BUG] [REGEX] error : “Cannot find method 'ann' on object of type NQPMu” #5861

Open p6rt opened 7 years ago

p6rt commented 7 years ago

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

Searchable as RT130273$

p6rt commented 7 years ago

From rongshenmd@gmail.com

---------- Forwarded message ---------- From​: Rong Shen \rongshenmd@​gmail\.com Date​: Thu, Nov 24, 2016 at 10​:11 PM Subject​: [BUG] [REGEX] error : “Cannot find method 'ann' on object of type NQPMu” To​: rakudobug@​perl.org

My system​:

uname -a Linux XubuntuVBox1404i32 3.13.0-24-generic #​46-Ubuntu SMP Thu Apr 10 19​:08​:14 UTC 2014 i686 i686 i686 GNU/Linux

My perl6 version​:

perl6 --version This is Rakudo version 2016.07.1 built on MoarVM version 2016.07 implementing Perl 6.c.



Okay, I am still having trouble with perl6 grammar and action. I want to find a pattern in a string, and as soon as it is is found, change the pattern according to action, and return the modified string.

my $test = "xx, 1-March-23, 23.feb.21, yy foo 12/january/2099 , zzz";# want this result​: xx, 010323, 230221, yy foo 120199 , zzz"; # 2 digits for day, month, year

grammar month {   regex TOP { \+ }   regex unit { \ \ \ }   regex before { .*? }   regex after { .*? }   regex form1 { \s* \

\ \ \ \ \s* }   regex slash { \s* \<[ \- \/ \. ]> \s* }   regex dd { \d ** 1..2 }   regex yy { (19 | 20)? \d\d }   proto regex mon {*}   regex mon​:sym\ { \w 'an' \w* }   regex mon​:sym\ { \ }   regex mon​:sym\ { \<[Mm]> 'ar' \w* }}class monAct {   method TOP ($/) { make $\.map({.made}); }   method unit ($/) { make $\ ~ $\.made ~$\; }   method form1 ($/) { make $\
.made ~ $\.made ~ $\; }   method dd ($/) {   my $ddStr = $/.Str;   if $ddStr.chars == 1 { make "0" ~ $ddStr; } else { make $ddStr; }   }   method mon​:sym\ ($/) { make "01"; };   method mon​:sym\ ($/) { make "02"; };   method mon​:sym\ ($/) { make "03"; };} my $m = month.parse($test, actions => monAct.new); say $m; say $m.made;

But it says​:

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

What did I do wrong ? Thank you for your help !!!



This looks like a bug in Rakudo to me, possibly related to before being part of the syntax for lookahead assertions \https://docs.perl6.org/language/regexes.html#Lookahead_assertions.

It can already be triggered with a simple / \ /​:

$ perl6 --versionThis is Rakudo version 2016.11-20-gbd42363 built on MoarVM version 2016.11-10-g0132729 implementing Perl 6.c.

$ perl6 -e '/ \ /'===SORRY!===Cannot find method 'ann' on object of type NQPMu

At the very least, it's a case of a less than awesome error message.

You should report this to rakudobug@​perl.org, cf How to report a bug \https://github.com/rakudo/rakudo/wiki/rt-introduction.

p6rt commented 7 years ago

From @jnthn

On Mon, 05 Dec 2016 22​:58​:27 -0800, rongshenmd@​gmail.com wrote​:

------------------------------------------------------------ ---------------------

Okay, I am still having trouble with perl6 grammar and action. I want to find a pattern in a string, and as soon as it is is found, change the pattern according to action, and return the modified string.

my $test = "xx, 1-March-23, 23.feb.21, yy foo 12/january/2099 , zzz";# want this result​: xx, 010323, 230221, yy foo 120199 , zzz"; # 2 digits for day, month, year

grammar month { regex TOP { \+ } regex unit { \ \ \ } regex before { .*? } regex after { .*? }

Both `before` and `after` happen to be the names of a couple of the standard rules (for doing lookahead and lookbehind), inherited from the base Grammar class. In theory overriding these as you have is fine enough (until you try to use the built-in ones and then get confused because yours took precedence, at least ;-)).

In practice, part of the regex compiler treated the name `before` specially and then got very upset when it was not something of the form `\`. I've now made it more robust in https://github.com/perl6/nqp/commit/768b20d9c756c636f58bc4d131e12e3ec60eebfa and with that patch your grammar seems to work nicely.

What needs a bit more discussion is whether we'd like to simply leave it at that and add a spectest to codify that overriding before/after this way is fine (I'm good with this), or treat those two names a bit more specially (but then where do we draw the line on which built-ins get such treatment?)

Thanks,

/jnthn

p6rt commented 7 years ago

The RT System itself - Status changed from 'new' to 'open'