in reply to Re: Parse::RecDescent: autoactions and precompiled grammars
in thread Parse::RecDescent: autoactions and precompiled grammars
use Data::Dumper qw( Dumper ); use Parse::RecDescent (); { local $::RD_AUTOACTION = q { [@item] }; Parse::RecDescent->Precompile( 'parse: /a/ /b/ /c/', 'Grammar' ) or die("Bad grammar\n"); } { # Normally, this would be in another file. require Grammar; my $parser = Grammar->new(); print(Dumper($parser->parse('a b c'))); }
outputs
$VAR1 = [ 'parse', 'a', 'b', 'c' ];
If you comment out autoaction, the output is
$VAR1 = 'c';
|
|---|