On Tue Apr 12 02:01:28 2011, moritz wrote:
> 10:49 < moritz> rakudo: say 'aaaa' ~~ /(\w)+$0/; say $0
> 10:49 <+p6eval> rakudo 4bf132: OUTPUT«aaaa␤a a a␤»
> 10:50 < moritz> huh. Is that correct?
> 10:50 < masak> don't think so.
> 10:51  * moritz facepalms
> 10:51 < moritz> $0 is an array
> 10:51 < moritz> what happens when you interpolate an array into a regex?
> 10:51 < moritz> you get an alternation, no?
> 10:52  * moritz presents the case to the Regex High Court of TimToady, 
> pmichaud and sorear
> 10:52 < moritz> is that another "doctor, it hurts when I do this"? :-)
> 10:52 < masak> no.
> 10:52 < masak> this is bad.
> 10:53 < masak> you're clearly not intending $0 as an array, but as a 
> submatch string.
> 10:54 < moritz> rakudo: say 'abcd' ~~ /(.)+$0/; say $0
> 10:54 <+p6eval> rakudo 4bf132: OUTPUT«␤␤»
> 10:54 < moritz> rakudo: say 'abca' ~~ /(.)+$0/; say $0
> 10:54 <+p6eval> rakudo 4bf132: OUTPUT«␤␤»
> 10:54 < moritz> rakudo: say 'abcc' ~~ /(.)+$0/; say $0
> 10:54 <+p6eval> rakudo 4bf132: OUTPUT«abcc␤a b c␤»
> 10:55 < moritz> ok that's not what it does
> 10:55 < moritz> it just takes the last item
> 
> I think it is inconsistent that $0 in the regex only matches $0[*-1], 
> but is reported as the full array outside the regex.
> 
> I'm not sure what the desired behavior is.

The new behavior is that we take the latest contiguous sequence of captures and 
the backref is the string ranging from the .from of the first capture in that 
sequence to the .to of the last capture in that sequence. So now:

$ perl6-m -e "say 'aaaa' ~~ /(\w)+$0/; say $0"
「aaaa」
 0 => 「a」
 0 => 「a」
[「a」 「a」]

Note the contiguous constraint is needed to fix this case while also not 
breaking cases like:

"bookkeeper" ~~ m/(((\w)$0)+)/

Which should match "ookkee".

Tests in S05-capture/dot.t.

/jnthn

Reply via email to