Fix specifying an action for an empty rule #10

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@arodland

Hi,

this code example that I think should work:

my $g = Marpa::R2::Grammar->new({
    actions => "main",
    start => "start",
    rules => "start ::= action => act"
});
$g->precompute;
my $r = Marpa::R2::Recognizer->new({grammar => $g});
print ${$r->value};
sub act { 123 }

actually dies with Can't use string ("act") as an ARRAY ref while "strict refs" in use at .../Marpa/R2/Stuifzand.pm line 149.

because the do_empty_rule action is doing something with the $action that doesn't make much in the way of sense. I've changed it to what I think it was trying to do, and this change makes my sample work and print "123".

@jeffreykegler
Owner

Fixed in commit f310016. Your example
is now part of the test suite, as a regression test. It's also a very
good "corner case", which may catch other bugs involving trivial
grammars and/or null parses.

Thanks, jeffrey kegler

Andrew Rodland wrote:

Hi,

this code example that I think should work:

|my $g = Marpa::R2::Grammar->new({
actions => "main",
start => "start",
rules => "start ::= action => act"
});
$g->precompute;
my $r = Marpa::R2::Recognizer->new({grammar => $g});
print ${$r->value};
sub act { 123 }
|

actually dies with |Can't use string ("act") as an ARRAY ref while
"strict refs" in use at .../Marpa/R2/Stuifzand.pm line 149.|

because the |do_empty_rule| action is doing something with the
|$action| that doesn't make much in the way of sense. I've changed it
to what I think it was trying to do, and this change makes my sample
work and print "123".


    You can merge this Pull Request by running:

git pull https://github.com/arodland/Marpa--R2 master

Or view, comment on, or merge it at:

#10

    Commit Summary

* Don't try to treat the action arg of an empty rule as an array


    File Changes

* *M* r2/lib/Marpa/R2/Stuifzand.pm (2)


    Patch Links

* https://github.com/jeffreykegler/Marpa--R2/pull/10.patch
* https://github.com/jeffreykegler/Marpa--R2/pull/10.diff


Reply to this email directly or view it on GitHub
#10.

@jeffreykegler
Owner

The fix is included in CPAN's Marpa-R2-2.025_001.tar.gz, just uploaded.

@arodland

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment