Subject: | Regression: Repetitions using a separator pattern now also return the separator |
When parsing a string using repetitions and separators, eg: 'some
(repeated, repeated, repeated, repeated) elements', using a grammar
like:
my $parser = Parse::RecDescent->new( q{
sep: some(?) '(' repeated(s? /,/) ')' 'elements'
{
$return = $item[3];
}
repeated: 'repeated'
some: 'some'
});
The $return used to just contain the list of 'repeated', since 1.962 it
also contains the separator ',' in this case. See attached file for a
simple test.
This is causing many test failures for SQL-Translator as we use lots of
P::RD in that fashion. See recent spate of fail reports: http://
static.cpantesters.org/distro/S/SQL-Translator.html
Subject: | separated_repitition.t |
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
use Data::Dumper;
use Parse::RecDescent;
my $parser = Parse::RecDescent->new( q{
sep: some(?) '(' repeated(s? /,/) ')' 'elements'
{
$return = $item[3];
}
repeated: 'repeated'
some: 'some'
});
ok($parser, 'Created parser');
my $str = 'some (repeated, repeated, repeated, repeated) elements';
my $result = $parser->sep($str);
my $expected = ['repeated', 'repeated', 'repeated', 'repeated'];
is_deeply($result, $expected);
print Data::Dumper::Dumper($result);