cazz has asked for the wisdom of the Perl Monks concerning the following question:
Yes, I know I should figure out how to implement my tests with a more detailed grammer... until I get around to that, I'm hoping I can figure out how to modify the error message from the action block.
I know how to fail parsing, just set $return to undef. However, I'm having a difficult time modifying the error message produced by P::RD.
Getting to the error production from inside the action isn't difficult since the error production is the last production in the rule:
Which, in my example is:$thisrule->{'prods'}[ $#{ $thisrule->{'prods'} } ]
I should be able to (though not very nicely) get to msg via this:$VAR1 = bless( { 'number' => '1', 'strcount' => 0, 'dircount' => 1, 'uncommit' => 0, 'error' => 1, 'patcount' => 0, 'actcount' => 0, 'items' => [ bless( { 'msg' => ' my message here', 'hashname' => '__DIRECTIVE1__', 'commitonly' => '', 'lookahead' => 0, 'line' => 82 }, 'Parse::RecDescent::Error' ) ], 'line' => 82 }, 'Parse::RecDescent::Production' );
Setting that to be a different value, then triggering the specific error I'm looking for causes the error message to be changed, in the data structure (so says DD) however, I still get the default error message.$thisrule->{'prods'}[ $#{ $thisrule->{'prods'} } ]->{'items'}- +>[0]->{'msg'}
Is there a better way than this ugly hack I'm struggling through? If not, what am I doing wrong in my ugly hack?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: changing P::RD error message from within an action
by ikegami (Patriarch) on May 31, 2005 at 22:21 UTC |