>
> I am working with a grammar that I would like to have operate in two
> different modes. In both modes the rules are identical, but the methods
> should behave differently.
...
> As an illustration (not the actual problem), say we want to proces
> arithmetical expressions in two modes: normall
Thanks! Timo's explanation nailed it, the problem is with the action not
defining a method for "sum" so Any.sum becomes the action.
The parsing works in grammar B without actions; "sum" is fine as a token
name in that case.
grammar B {
rule TOP { }
token sum { + % '+' }
token int { \d+ }
}
The grammar will never by itself try to call a subroutine, it only looks
for methods in the action object. However, there is a "sum" method that
An-Action inherits from Any. You can find it here:
https://github.com/rakudo/rakudo/blob/master/src/core/Any.pm6#L440
It's probably a good idea to put an
Hi Yary,
I'm not sure whether this is really the reason, but sum is the name of a
built-in function (see https://docs.perl6.org/routine/sum). It seems that
the compiler interprets your token as a subroutine call of that builtin.
HTH,
Laurent.
2018-08-12 9:28 GMT+02:00 yary :
> If I call a toke
If I call a token "sum", this example gives an error. If I call it
"something-else", it doesn't. I didn't expect an error in either case.
What's going on?
~~ actions-test.p6 ~~
grammar A {
rule TOP { }
token something-else { + % '+' }
token int { \d+ }
}
grammar B {
rule TOP { }
token