|To:||Rakudo Bugtracker <rakudobug [...] perl.org>|
|From:||Sam S <smls75 [...] gmail.com>|
|Subject:||[@LARRY] [REGEX] `!` modifier on right-hand branch of `||` causes backtracking into the alternation|
|Date:||Wed, 4 Oct 2017 21:30:35 +0200|
When backtracking is disabled for an alternation (via `:` modifier or `:ratchet` mode), this obviously means that once the alternation has matched once it may no longer reconsider which branch it wants to select: say "ab" ~~ / [ab || a ]: b /; # Nil But does it also mean that once the alternation has matched, the selected branch *itself* may no longer do any backtracking? I would have thought so, but Rakudo's current behavior is inconsistent: say "ab" ~~ / [ .+ | x ]: b /; # Nil say "ab" ~~ / [ .+ || x ]: b /; # Nil say "ab" ~~ / [ x | .+ ]: b /; # Nil say "ab" ~~ / [ x || .+ ]: b /; # ｢ab｣ I.e. in most cases, it commits to what the alternation matched the first time. But when 1) it is an `||` alternation, 2) and its *last* branch matched, 3) and said branch is a backtrackable atom which (unlike the alternation itself) is not affected by `:ratchet`, then it looks like that backtrackable atom can reconsider what it wants to match even after the regex execution has moved past the alternation. I suppose another way to phrase the @LARRY design question is this: Does an alternation select a particular match value (like a "function"), or does it select a subregex (like a "macro")? (PS: I should note that the backtracking behaviors of || and | were even less consistent before my NQP commit 263257a9c¹ [see RT #130117²], which was supposed to bring `||` in line. But I didn't discover this edge case until now, and indeed am not sure how to fix it no matter which way it *should* be fixed.) ---  --- This is Rakudo version 2017.09-203-g98fae3d84 built on MoarVM version 2017.09.1-553-ga4fef0bd implementing Perl 6.c.