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
Regex bug: auto-reference to a capture used in a conditional expression #7754
Comments
From philippe.verdret@xps-pro.comCreated by pverdret@xps-pro.comHi, In a capture a reference to this capture is perfectly possible: "baaa" =~ (\1|a)+ the result of this match is b<aaa>. "baaa" =~ ((?(1)a|a))+ the result is the same. The tested condition is "baaa" =~ ((?(1)a|b))+ the result should be "<baaaa>". But the matched string is <b>aaaa. By introducing a (?{}) behind "b" the result is now right: "baaa" =~ ((?(1)a|b(?{})))+ use re 'debug' indicates that the empty code block changes the Philippe Verdret Perl Info
|
From @jkeenanOn Mon Jan 17 08:49:39 2005, philippe.verdret@xps-pro.com wrote:
When I try out this code (or any of the subsequent examples) *as is*, I ##### But when I modify each of the code samples to make a proper regular
##### $ perl -e '"baaa" =~ m/"baaa" =~ ((?(1)a|b(?{})))+/;print "$1\n"' ##### Which? Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Thu Jan 19 18:54:33 2012, jkeenan wrote:
I think you made a copy-and-paste error there. You have "baaa" =~ $ ./perl -Ilib -e '"baaa" =~ /((?(1)a|b))+/;print "$1\n"' -- Father Chrysostomos |
From @tamiasOn Thu, Jan 19, 2012 at 06:54:34PM -0800, James E Keenan via RT wrote:
I think you are misinterpreting the OP. You should be printing $&, not $1. Ronald |
From @khwilliamsonAnd for those of you following along at home, if you do this, you get |
@khwilliamson This is the one liner we're describing?
|
What he is saying is that perl -Dr -le ' "baaa" =~ /((?(1)a|b))+/; print $&' should print "baaa" but instead prints just "b". But if he adds what effectively should be a no-op, like so The current code generated in the first case is And in the second it is My suspicions fall on the difference between CURLYM and CURLYX |
And I'm right (probably). It is getting compiled to CURLYM, which according to regexec.c: |
@khwilliamson in this case it is fixed width tho. Both branches of the condition are a single char. It looks to me like CURLYM is broken somehow.
I assume that CURLYM is doing something wrong. |
We have to close the paren immediately after each time we match A, or conditional patterns will break. See #7754
Should be fixed by #20654 |
CURLYM fakes an OPEN/CLOSE paren, and was deferring updating its close paren data until after it finished looping. This meant that tests against the capture buffer would not work. Changed it to close the parens each time. An alternative solution would be to exclude cases containing conditional logic from the CURLYX->CURLYM conversion, just like EVAL is excluded. |
@demerphq if your commit message in your PR has the string |
Thanks @toddr I added one. |
We have to close the paren immediately after each time we match A, or conditional patterns will break. An alternative and possibly more efficient solution would be to block CURLYX -> CURLYM conversion when the inside contains a conditional check just like we do with EVAL. Fixes Perl#7754 aka Perl#7754
We have to close the paren immediately after each time we match A, or conditional patterns will break. An alternative and possibly more efficient solution would be to block CURLYX -> CURLYM conversion when the inside contains a conditional check just like we do with EVAL. Fixes Perl#7754 aka Perl#7754
We have to close the paren immediately after each time we match A, or conditional patterns will break. An alternative and possibly more efficient solution would be to block CURLYX -> CURLYM conversion when the inside contains a conditional check just like we do with EVAL. Fixes Perl#7754 aka Perl#7754
Migrated from rt.perl.org#33820 (status was 'open')
Searchable as RT33820$
The text was updated successfully, but these errors were encountered: