Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-ratchet right-hand branch of || causes backtracking into the alternation #6570

Open
p6rt opened this issue Oct 4, 2017 · 1 comment
Open

Comments

@p6rt
Copy link

@p6rt p6rt commented Oct 4, 2017

Migrated from rt.perl.org#132219 (status was 'new')

Searchable as RT132219$

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 4, 2017

From @smls

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.)


[1] Raku/nqp@263257a
[2] https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130117


This is Rakudo version 2017.09-203-g98fae3d84 built on MoarVM version
2017.09.1-553-ga4fef0bd
implementing Perl 6.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant