On Thu, Jun 11, 2015 at 02:53:15PM -0700, Alex Jakimenko wrote:
> say grammar Gram { regex TOP { ('XX')+ %% $<delim>=<[a..z]>* };
> }.parse('XXXXXX');
> 
> Output:
> 「XXXXXX」
>  0 => 「XX」
>  0 => 「XX」
>  delim => 「」
>  0 => 「XX」
>  delim => 「」
>  delim => 「」
> 
> The order is wrong. 

I'm not entirely certain this is a bug, although it might be less than optimal. 
 By using 'say' we're seeing the .gist of the resulting Match object, which in 
turn is using .caps .  The .caps method sorts the captured parts based on the 
.from of each submatch.

In this case, $<delim>[0] and $0[1] both have a .from of 2.  Since their 
.from's result in a tie, the one that happens to be earlier in the capture hash 
('0' in this case) ends up appearing first (since sorting is stable).

I guess we can update .caps to sort based on both the .from and .to values of 
each submatch, although doing so will likely make .caps a fair bit slower.

Pm

Reply via email to