in reply to changing P::RD error message from within an action
Looking at the code (grammar.pm) generated by
use Parse::RecDescent; my $grammar = <<'__EOI__'; parse: <error:FOO!> __EOI__ Parse::RecDescent->Precompile($grammar, "grammar") or die("Bad grammar\n");
reveals (rearranged to avoid forced line breaks)
$_tok = do { if (1) { do { push @{$thisparser->{errors}}, [qq{FOO!},$thisline]; } unless $_noactions; undef } else { 0 } };
Let's test it:
use Parse::RecDescent; my $grammar = <<'__EOI__'; parse: { # Create error message. my $msg = 'FOO!'; # Create error. push(@{$thisparser->{errors}}, [ $msg, $thisline ]) unless $_noactions; # Fail the action. undef; } __EOI__ my $parser = Parse::RecDescent->new($grammar) or die("Bad grammar\n"); $parser->parse('');
Output:
ERROR (line 1): FOO!
bingo!
|
---|