Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: How to grab Parse::RecDescent error output in a variable?

by Pic (Scribe)
on Sep 15, 2008 at 17:12 UTC ( #711504=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to grab Parse::RecDescent error output in a variable?
in thread How to grab Parse::RecDescent error output in a variable?

The reason local breaks it is that local replaces the variable in that lexical scope, and the references to P::RD::ERROR in P/RD.pm are outside the lexical scope of the local invocation (I think).

It's an interesting question though, and IMO the right solution would be to get a patch committed for P::RD that allows the user to specify an alternative filehandle for error output.

Replies are listed 'Best First'.
Re^5: How to grab Parse::RecDescent error output in a variable?
by vrk (Chaplain) on Sep 17, 2008 at 08:21 UTC

    Done, and also received feedback already! Here's the bug report: https://rt.cpan.org/Ticket/Display.html?id=39323

    And here's the solution I was seeking, based on demo/demo_errors.pl:

    use strict; use Data::Dumper; use Parse::RecDescent; # Simple Lisp S-expressions (as an example) my $grammar = q# start: expression(s?) | { die join("\n", map { $_->[0] } @{ $thisparser->{errors} } +)."\n" } expression: /\w+/ | '(' expression(s?) ')' { $item[2] } | <error> #; my $p = Parse::RecDescent->new($grammar); # This will die if there is an error. print Dumper($p->start('(foo (bar))')); # Like so: $p->start('(foo');

    --
    say "Just Another Perl Hacker";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://711504]
help
Chatterbox?
[james28909]: good lord :(
[Lady_Aleena]: james28909, bare name...
[james28909]: /msg username message did it
[LanX]: James not /msg [beech] but /msg beech
[james28909]: i havent used the /msg [username] message</c> format
[LanX]: you can also click on beech and message him. ..
[james28909]: jebus
[LanX]: sorry again not [msg://beech]

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-05-24 22:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?