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

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

Open
p6rt opened this issue Dec 6, 2016 · 3 comments

Comments

@p6rt
Copy link

p6rt commented Dec 6, 2016

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

Searchable as RT130273$

@p6rt
Copy link
Author

p6rt commented Dec 6, 2016

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 { <unit>+ }
  regex unit { <before> <form1> <after> }
  regex before { .*? }
  regex after { .*? }
  regex form1 { \s* <dd> <slash> <mon> <slash> <yy> \s* }
  regex slash { \s* <[ \- \/ \. ]> \s* }
  regex dd { \d ** 1..2 }
  regex yy { (19 | 20)? \d\d }
  proto regex mon {*}
  regex mon​:sym<jan> { \w 'an' \w* }
  regex mon​:sym<feb> { <sym> }
  regex mon​:sym<mar> { <[Mm]> 'ar' \w* }}class monAct {
  method TOP ($/) { make $&lt;unit>.map({.made}); }
  method unit ($/) { make $&lt;before> ~ $&lt;form1&gt;.made ~$&lt;after>; }
  method form1 ($/) { make $&lt;dd>.made ~ $&lt;mon&gt;.made ~ $&lt;yy>; }
  method dd ($/) {
  my $ddStr = $/.Str;
  if $ddStr.chars == 1 { make "0" ~ $ddStr; } else { make $ddStr; }
  }
  method mon​:sym<jan> ($/) { make "01"; };
  method mon​:sym<feb> ($/) { make "02"; };
  method mon​:sym<mar> ($/) { 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 / <before> /​:

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

$ perl6 -e '/ <before> /'===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
Copy link
Author

p6rt commented Dec 7, 2016

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 { <unit>+ }
regex unit { <before> <form1> <after> }
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 `<before some regex here>`. I've now made it more robust in Raku/nqp@768b20d 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
Copy link
Author

p6rt commented Dec 7, 2016

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

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

No branches or pull requests

1 participant