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.
First the way the text is organized makes clear that the behaviour of the implementation must be deterministic (not random).
Second - and more important - describing the exact behaviour of existing implementations could fill an entire, hard-to-understand page as every corner case has to be described. In addition such a specification would limit degrees of freedom of the implementation. Let's assume some implementation supports a "fastest implementation" flag. Such an implementation can use unspecified parts to make short-cuts. So leaving the behaviour unspecified resp. restricted to the minimum has some advantages.
来源:https://stackoverflow.com/questions/49943078/whats-an-additional-tie-breaker-for-perl-6-longest-token-matching