Re: parsing in different modes

2018-08-12 Thread yary
> > 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

Re: Special token names, or my mistake

2018-08-12 Thread yary
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+ } }

Re: Special token names, or my mistake

2018-08-12 Thread Timo Paulssen
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

Re: Special token names, or my mistake

2018-08-12 Thread Laurent Rosenfeld via perl6-users
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

Special token names, or my mistake

2018-08-12 Thread yary
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