Subject: | |
Date: | Fri, 18 Sep 2009 08:41:08 +0200 |
To: | bug-regexp-grammars [...] rt.cpan.org |
From: | Stéphane Payrard <cognominal [...] gmail.com> |
=pod
Dear Damian,
I have a problem with Regexp::Grammars. I have reduced it :
it seems that a named subrule in a negative look-ahead does not work.
In the following program, I expected $gram1 and $gram2 to have the
same behavior but they don't. The json encoding of the parsings are
respectively:
{
"" : "abab",
"c" : [
"ab"
],
"!" : -1
}
{
"" : "abab",
"c" : [
"ab",
"ab"
]
}
The second parsing is correct, but the first is not because the array
should have two entries. I don't know the meaning of the key-value in
the encoding of the fisrt parse :
"!" : -1
Thanks for that (as usual) wonderful package. Having identified the
problem, I guess I can work around it. So, no hurry, I can wait for a
fix. Sorry, I have not yet the courage to look in your source code.
=cut
use strict;
use feature ':5.10';
use Regexp::Grammars;
use JSON::XS;
my $gram1 = qr{
<debug: on>
\A <[c]>+ \Z
<token: c> ( (?! <b> ) a )+ b
<token: b> b
}xms;
my $gram2 = qr{
<debug: on>
\A <[c]>+ \Z
<token: c> ( (?! b ) a )+ b
}xms;
my $json = JSON::XS->new->pretty(1);
"abab" =~ $gram1 ;
print $json->encode(\%/);
"abab" =~ $gram2 ;
print $json->encode(\%/);
--
cognominal stef