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

() vs [] influences matching behavior #3703

Open
p6rt opened this issue Feb 25, 2015 · 4 comments
Open

() vs [] influences matching behavior #3703

p6rt opened this issue Feb 25, 2015 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Feb 25, 2015

Migrated from rt.perl.org#123933 (status was 'open')

Searchable as RT123933$

@p6rt
Copy link
Author

p6rt commented Feb 25, 2015

From beasley@web.de

say "asdfEnd" ~~ /​:ratchet ( xyz || .+! ) End /
Results in​: Nil

say "asdfEnd" ~~ /​:ratchet [ xyz || .+! ] End /
Results in​: 「asdfEnd」

I'd expect them to give the same result.

@p6rt
Copy link
Author

p6rt commented May 21, 2016

From @smls

Simpler test-case​:

  say "abcd" ~~ /​:ratchet .+! "d" /; # 「abcd」
  say "abcd" ~~ /​:ratchet [.+!] "d" /; # 「abcd」
  say "abcd" ~~ /​:ratchet (.+!) "d" /; # Nil

I think this may actually not be a bug.
The () creates a proper subpattern, and the :ratchet modifier prevent backtracking back into that subpattern.
The [], on the other hand, is simply for grouping.

One thing that is slightly surprising, though, is that the following still matches​:

  say "abcd" ~~ /​:ratchet ["foo" || .+!] "d" /; # 「abcd」

S05 suggests that :ratchet should prevent backtracking into an alternation​:

  The new :r or :ratchet modifier [...] imply a : after every atom, including [...] alternations.

Does that only refer to declarative alternations with `|`, and not to sequential ones with `||` ?

@p6rt
Copy link
Author

p6rt commented May 21, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 21, 2016

From @smls

Turns out there is already ticket #​123934 for the question of whether both `|` and `||` style alternations should be affected by the :ratchet modifier.

So *this* ticket can be reduced to the question of whether the following two should behave the same as far as matching is concerned​:

say "abcd" ~~ /​:r [.+!] "d" /; # 「abcd」
say "abcd" ~~ /​:r (.+!) "d" /; # Nil

As I stated in my previous comment, I'm not convinced they should.

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

No branches or pull requests

1 participant