Subject: | sometimes $item{__ACTIONn__} are not defined |
This is the smallest example of a bug dicovered in a bigger test suite. The bug never happend in the first grammar build. The bug may happend in the second grammar build but is dependant of what was in the first grammar.
use Parse::RecDescent;
new Parse::RecDescent("\n"); # this line is important for faillure
$parser = new Parse::RecDescent('
rule: {"ok"}
{ print $item{__ACTION1__}
}
'); # location and number of \n in grammar is important for faillure
$parser->rule(""); #should print "ok" but will print nothing
There is a bigger test join there is the result:
#
# Trying a grammar with 1 \n
#
Parse::RecDescent: Treating "rule:" as a rule declaration
Parse::RecDescent: Treating "{3}" as an action
Parse::RecDescent: Treating "{ show(\%item); $item{__ACTION1__} }" as an
action
printing code (4183) to RD_TRACE
1| rule |Trying rule: [rule] |
1| rule |Trying production: [] |
1| rule |Trying action |
1| rule |>>Matched action<< (return value: [3])|
1| rule |Trying action |
1| rule |>>Matched action<< (return value: [3])|
1| rule |>>Matched production: []<< |
1| rule |>>Matched rule<< (return value: [3]) |
1| rule |(consumed: []) |
ok 1 - %item access to action values, with 1 empty line(s)
# $VAR1 = {
# '__RULE__' => 'rule',
# '__ACTION1__' => 3
# };
#
# Trying a grammar with 3 \n
#
Parse::RecDescent: Treating "rule:" as a rule declaration
Parse::RecDescent: Treating "{3}" as an action
Parse::RecDescent: Treating "{ show(\%item); $item{__ACTION1__} }" as an
action
printing code (4133) to RD_TRACE
1| rule |Trying rule: [rule] |
1| rule |Trying production: [] |
1| rule |Trying action |
1| rule |>>Matched action<< (return value: [3])|
1| rule |Trying action |
1| rule |<<Didn't match action>> (return value:|
| |[undef]) |
1| rule |<<Didn't match rule>> |
not ok 2 - %item access to action values, with 3 empty line(s)
# Failed test (t/bug_hash_item.t at line 28)
# got: undef
# expected: '3'
# $VAR1 = {
# '__RULE__' => 'rule'
# };
1..2
# Looks like you failed 1 tests of 2.
use Test::More qw( no_plan);
use Parse::RecDescent;
use strict;
use warnings;
use Data::Dumper;
$::RD_TRACE =1;
use vars qw( $dump );
sub Parse::RecDescent::show { $dump = Dumper( $_[0]); }
my $grammar = 'rule: {3} { show(\%item); $item{__ACTION1__} }';
#foreach ( (3,1)){ # all working
#foreach ( (1,3)){ # only second fail
#foreach ( (0,1,2,3,4,5)){ # start failling at 3
#foreach ( (5,4,3,2,1,0)){ # all working
#foreach ( (0,1,2,4,5)){ # start failling at 4
foreach ( (1,3)){ # only second fail
diag( "\nTrying a grammar with $_ \\n\n\n");
my $parser = new Parse::RecDescent( $grammar . "\n" x $_);
is( $parser->rule(""), 3,
"\%item access to action values, with $_ empty line(s)");
diag($dump);
}