You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.)
Migrated from rt.perl.org#132219 (status was 'new')
Searchable as RT132219$
The text was updated successfully, but these errors were encountered: