The docs for Perl 6 longest alternation in regexes punt to Synopsis 5 to document the rules for longest token matching. There are three rules if different alternatives would match a substring of the same length:
- The longest declarative prefix breaks the tie
- The highest specificity breaks the tie
- "If it's still a tie, use additional tie-breakers."
- The left most alternation finally wins
It's that third rule that I'm curious about.
tie-together.pm6
containinggrammar tie { token TOP { <foo> }; proto token foo {*}; token foo:alt<A> { a . { say 'A' } } }; grammar tie-too is tie { token foo:alt<B> { a . { say 'B' } }
and a scriptuse tie-together; tie-too.parse: 'aa';
, then stdout displaysB
becausetie-too
comes beforetie
(sotie-too
is leftmost) in the MRO resolving the.parse
call. – Asseverateaugment
ed in one or more other compilation units and B) neither prefix length nor specificity resolve a tie. – Asseverate