Skip to content

Commit

Permalink
Merge pull request #6 from zmughal/uniq-match
Browse files Browse the repository at this point in the history
Unique match positions
  • Loading branch information
zmughal committed Sep 2, 2022
2 parents 70ff22b + 1661bb2 commit 9593fe1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Babble/Match.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Babble::Match;
use Babble::Grammar;
use Babble::SymbolGenerator;
use Mu;
use List::Util 1.45;
use re 'eval';

ro 'top_rule';
Expand Down Expand Up @@ -92,7 +93,9 @@ sub match_positions_of {
/${\$self->top_re} ${wrapped}/x;
@F;
};
return @found;
return map { [ split ',', $_ ] }
List::Util::uniqstr
map { join ",", @$_ } @found;
}

sub each_match_of {
Expand Down
2 changes: 2 additions & 0 deletions t/plugin-definedor.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ my @cand = (
'my $x; my $y = 3; defined($_) or $_ = $y for $x; say $x;', ],
[ 'my $x; my $y = 3; $x //= $y if $z; say $x;',
'my $x; my $y = 3; do { defined($_) or $_ = $y for $x } if $z; say $x;', ],
[ 'sub foo { return $x // 3 }',
'sub foo { return (map +(defined($_) ? $_ : 3), $x)[0] }', ],
);

foreach my $cand (@cand) {
Expand Down

0 comments on commit 9593fe1

Please sign in to comment.