Subject: | Negative lookahead not working |
Hello,
unless I completely missed the point about negative look-aheads (and
this may well be!), I think there might be a bug in its handling inside
Parse::RecDescent. Please find attached a minimal test file, complete
with its output with "prove -v" (perl 5.8.8 and P::RD 1.96.0).
Cheers,
Flavio.
Subject: | prd.t |
# vim: filetype=perl :
use strict;
use warnings;
use Test::More tests => 1;
use Parse::RecDescent;
$::RD_TRACE = 1;
my $grammar = <<'END_OF_GRAMMAR';
foo : 'a'
bar : 'z'
not_before_bar : foo ...!bar
whatever : not_before_bar foo
END_OF_GRAMMAR
my $parser = Parse::RecDescent->new($grammar);
ok($parser->whatever($_), $_) for qw( aa );
__END__
$ prove prd.t
prd...... Parse::RecDescent: Treating "foo :" as a rule declaration
Parse::RecDescent: Treating "a" as a literal terminal
Parse::RecDescent: Treating "bar :" as a rule declaration
Parse::RecDescent: Treating "z" as a literal terminal
Parse::RecDescent: Treating "not_before_bar :" as a rule declaration
Parse::RecDescent: Treating "foo" as a subrule match
Parse::RecDescent: Treating "...!" as a negative lookahead
Parse::RecDescent: Treating "bar" as a subrule match
Parse::RecDescent: Treating "whatever :" as a rule declaration
Parse::RecDescent: Treating "not_before_bar" as a subrule match
Parse::RecDescent: Treating "foo" as a subrule match
printing code (20115) to RD_TRACE
1| whatever |Trying rule: [whatever] |
1| whatever | |"aa"
1| whatever |Trying production: [not_before_bar |
| |foo] |
1| whatever |Trying subrule: [not_before_bar] |
2|not_before|Trying rule: [not_before_bar] |
2|not_before|Trying production: [foo bar] |
2|not_before|Trying subrule: [foo] |
3| foo |Trying rule: [foo] |
3| foo |Trying production: ['a'] |
3| foo |Trying terminal: ['a'] |
3| foo |>>Matched terminal<< (return value: |
| |[a]) |
3| foo | |"a"
3| foo |>>Matched production: ['a']<< |
3| foo |>>Matched rule<< (return value: [a]) |
3| foo |(consumed: [a]) |
2|not_before|>>Matched subrule: [foo]<< (return |
| |value: [a] |
2|not_before|Trying subrule: [bar] |
3| bar |Trying rule: [bar] |
3| bar |Trying production: ['z'] |
3| bar |Trying terminal: ['z'] |
3| bar |<<Didn't match terminal>> |
3| bar |<<Didn't match rule>> |
2|not_before|>>Matched subrule: [bar]<< (return |
| |value: [] |
2|not_before|>>Matched production: [foo bar]<< |
2|not_before|>>Matched rule<< (return value: []) |
2|not_before|(consumed: [a]) |
1| whatever |<<Didn't match subrule: |
| |[not_before_bar]>> |
1| whatever |<<Didn't match rule>> |
prd......1/1
# Failed test 'aa'
# at prd.t line 16.
# Looks like you failed 1 test of 1.
prd...... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests
Test Summary Report
-------------------
prd.t (Wstat: 256 Tests: 1 Failed: 1)
Failed test: 1
Non-zero exit status: 1
Files=1, Tests=1, 0 wallclock secs ( 0.01 usr 0.01 sys + 0.00 cusr 0.07 csys = 0.09 CPU)
Result: FAIL