# New Ticket Created by  Aleks-Daniel Jakimenko-Aleksejev 
# Please include the string:  [perl #130081]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=130081 >


To demonstrate how it works, let's say we have this grammar:

grammar G { regex TOP { ‘a’ || ‘abc’ } };

So you might think that it will match either “a” or “abc”, but no, “abc”
will never work.

*Code:*
grammar G { regex TOP { ‘a’ || ‘abc’ } };
say G.parse(‘abc’)

*Result:*
Nil

Why? Well, see this:
https://github.com/rakudo/rakudo/blob/cb8f783eeb8ab25a5090fdc4e5cc318c36ee1afa/src/core/Grammar.pm#L23

Basically, TOP will first match ‘a’, and given that it is a good enough
result it will bail out without trying anything else. Then, .parse method
will see that it did not parse the whole string, so it fails.

I am not sure how this behavior could be useful or even how could anyone
expect this, to me it feels like the top rule should always have an
implicit $ on the end so that it knows that it should keep trying to find a
better solution.

But yes, we can close our eyes on this issue and add yet another trap to
the documentation.

Another closely related issue is method .subparse. As it seems, subparse is
supposed to return partial results (.partial-parse ?), but for some reason
instead of returning Nil it returns a failed Match, unlike .parse.

Reply via email to