Skip to content

Commit

Permalink
update Match.caps and Match.chunks to meet current spec
Browse files Browse the repository at this point in the history
Normal operation blocks on %($/).pairs, which stringifies the Match objects
  • Loading branch information
moritz committed Mar 29, 2009
1 parent 7af829f commit bc32a56
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/setting/Match.pm
Expand Up @@ -55,22 +55,29 @@ class Match is also {
}

multi method caps() {
my @caps = @(self), %(self).values;
# in regexes like [(.) ...]+, the capture for (.) is a List
# flatten that.
@caps = @caps.map: { $_ ~~ List ?? @($_) !! $_ };
return @caps.sort({ .from });
my @caps = gather {
for @(self).pairs, %(self).pairs -> $p {
# in regexes like [(.) ...]+, the capture for (.) is
# a List. flatten that.
if $p.value ~~ List {
take ($p.key => $_.value) for @($p);
} else {
take $p;
}
}
}
@caps.sort({ .value.from });
}

multi method chunks() {
my $prev = 0;
gather {
for @.caps {
if .from > $prev {
take self.substr($prev, .from - $prev)
if .value.from > $prev {
take '~' => self.substr($prev, .value.from - $prev)
}
take $_;
$prev = $_.to;
$prev = .value.to;
}
take self.substr($prev) if $prev < self.chars;
}
Expand Down

0 comments on commit bc32a56

Please sign in to comment.