Skip Menu |
Report information
Id: 126713
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: peschwa [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Literal array interpolation in regex doesn't match as expected.
Download (untitled) / with headers
text/plain 912b
Consider the following two regexen and their matching output, or lack thereof: 11:39 < psch> m: say "abcd" ~~ /^(a | b | bc | cd)*?$/; my @a = < a b bc cd >; say "abcd" ~~ /^(@a)*?$/ 11:39 <+camelia> rakudo-moar : OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 => 「cd」␤Nil␤» S05 says: An interpolated array: / @cmds / is matched as if it were an alternation of its literal elements. Ordinarily it matches using junctive semantics: / [ $(@cmds[0]) | $(@cmds[1]) | $(@cmds[2]) | ... ] / Taking this literal still matches when written as the long form: 11:51 <psch> m: my @a = < a b bc cd >; say "abcd" ~~ /^( $(@a[0]) | $(@a[1]) | $(@a[2]) | $(@a[3]) )*?$/ 11:51 <camelia> rakudo-moar : OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 => 「cd」␤» With the S05 quote I'd expect the array to interpolate into any of the two other regexen and produce the same match.
Download (untitled) / with headers
text/plain 1.9k
On Mon Nov 23 03:52:55 2015, peschwa@gmail.com wrote: Show quoted text
> Consider the following two regexen and their matching output, or lack > thereof: > > 11:39 < psch> m: say "abcd" ~~ /^(a | b | bc | cd)*?$/; my @a = < a b > bc cd >; say "abcd" ~~ /^(@a)*?$/ > 11:39 <+camelia> rakudo-moar : OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 => > 「cd」␤Nil␤» > > S05 says: > > An interpolated array: > > / @cmds / > > is matched as if it were an alternation of its literal elements. > Ordinarily it matches using junctive semantics: > > / [ $(@cmds[0]) | $(@cmds[1]) | $(@cmds[2]) | ... ] / > > Taking this literal still matches when written as the long form: > > 11:51 <psch> m: my @a = < a b bc cd >; say "abcd" ~~ /^( $(@a[0]) | > $(@a[1]) | $(@a[2]) | $(@a[3]) )*?$/ > 11:51 <camelia> rakudo-moar : OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 => > 「cd」␤» > > With the S05 quote I'd expect the array to interpolate into any of the > two other regexen and produce the same match.
03:39 < Juerd> psch: In bug reports I try to read significance in every character. So given ^(@a)*?$ I wonder why it's anchored, and why there's a ? after the * 03:39 < psch> the ? after * allows backtracking 03:39 < Juerd> Yes, but I'm trying to figure out why that was needed for the bug to trigger 03:40 < Juerd> And if it wasn't, then it's not golfed enough yet :) 03:40 < psch> m: my @a = < a b bc cd >; say "abcd" ~~ /(@a)*/ 03:40 <+camelia> rakudo-moar 091ee7: OUTPUT«「abc」␤ 0 => 「a」␤ 0 => 「bc」␤» 03:40 < psch> right, the report could've been more golfed i guess 03:41 < Juerd> And it might have been clearer if the two attempts were not in a single m: 03:41 < psch> i'm not confident enough to predict the right behavior i'd say. quoting the synopsis alludes to that 03:41 < psch> yes, that's definitely true 03:41 < Juerd> 'cause it took me, well, a few minutes, to realise that I should have been looking at that Nil in the output, not the rest.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 2.6k
On Sat Dec 19 19:44:53 2015, peschwa@gmail.com wrote: Show quoted text
> On Mon Nov 23 03:52:55 2015, peschwa@gmail.com wrote:
> > Consider the following two regexen and their matching output, or lack > > thereof: > > > > 11:39 < psch> m: say "abcd" ~~ /^(a | b | bc | cd)*?$/; my @a = < a b > > bc cd >; say "abcd" ~~ /^(@a)*?$/ > > 11:39 <+camelia> rakudo-moar : OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 > > => > > 「cd」␤Nil␤» > > > > S05 says: > > > > An interpolated array: > > > > / @cmds / > > > > is matched as if it were an alternation of its literal elements. > > Ordinarily it matches using junctive semantics: > > > > / [ $(@cmds[0]) | $(@cmds[1]) | $(@cmds[2]) | ... ] / > > > > Taking this literal still matches when written as the long form: > > > > 11:51 <psch> m: my @a = < a b bc cd >; say "abcd" ~~ /^( $(@a[0]) | > > $(@a[1]) | $(@a[2]) | $(@a[3]) )*?$/ > > 11:51 <camelia> rakudo-moar : OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 => > > 「cd」␤» > > > > With the S05 quote I'd expect the array to interpolate into any of > > the > > two other regexen and produce the same match.
> > 03:39 < Juerd> psch: In bug reports I try to read significance in > every character. So given ^(@a)*?$ I wonder why it's anchored, and > why there's a ? after the * > 03:39 < psch> the ? after * allows backtracking > 03:39 < Juerd> Yes, but I'm trying to figure out why that was needed > for the bug to trigger > 03:40 < Juerd> And if it wasn't, then it's not golfed enough yet :) > 03:40 < psch> m: my @a = < a b bc cd >; say "abcd" ~~ /(@a)*/ > 03:40 <+camelia> rakudo-moar 091ee7: OUTPUT«「abc」␤ 0 => 「a」␤ 0 => > 「bc」␤» > 03:40 < psch> right, the report could've been more golfed i guess > 03:41 < Juerd> And it might have been clearer if the two attempts were > not in a single m: > 03:41 < psch> i'm not confident enough to predict the right behavior > i'd say. quoting the synopsis alludes to that > 03:41 < psch> yes, that's definitely true > 03:41 < Juerd> 'cause it took me, well, a few minutes, to realise that > I should have been looking at that Nil in the output, not the rest.
19:24 < psch> m: my @a = < a b bc cd >; say "abcd" ~~ /^([||@a])*?$/ 19:24 <+camelia> rakudo-moar d075c8: OUTPUT«「abcd」␤ 0 => 「a」␤ 0 => 「b」␤ 0 => 「cd」␤» 19:25 < psch> m: my @a = < a b bc cd >; say "abcd" ~~ /^([|@a])*?$/ 19:25 <+camelia> rakudo-moar d075c8: OUTPUT«Nil␤» 19:25 < psch> so, yeah, i suppose it's "explicit or implicit LTM alternating interpolation of arrays matches differently than bareword LTM alternations" 19:26 < psch> but well, it's still about what S05 actually means, in a way


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org