Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's an "additional tie breaker" for Perl 6 longest token matching?

Tags:

regex

raku

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.

like image 446
brian d foy Avatar asked Apr 20 '18 13:04

brian d foy


1 Answers

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.

like image 137
rwitzel Avatar answered Oct 20 '22 21:10

rwitzel