On Mon, 11 Sep 2017 09:48:01 -0700, dzw...@gmail.com wrote: > `|` matches the longest input: > > 'ab' ~~ / ^:ratchet [ . | .. ] $ / > 「ab」 > > If the regex contains empty code blocks, backtracking fails: > > 'ab' ~~ / ^:ratchet [ {}. | {}.. ] $ / > Nil
Not a bug. As the S05 design document explains¹, the longest-token matching performed by a `|` alternation only considers the declarative prefix of each branch when comparing their match length. The declarative prefix is everything from the start of the branch until just before the first atom that is considered "procedural" rather than "declarative" - such as a `{ }` closure. In your example, the declarative prefix of both branches is always zero-length, because they have a `{ }` closure right at the start - so the `|` considers both branches equally long and thus always chooses the first one (unless backtracking forces it to reconsider). Closing this ticket. --- [1] http://design.perl6.org/S05.html#Longest-token_matching