dreadpiratepeter has asked for the wisdom of the Perl Monks concerning the following question:

I am having the wierdest problem.
I am writing a Parse::RecDescent parser. No big deal, I'm a language junkie and I write them all the time. But, this is the first time I am writing one under Windows using ActiveState Perl (latest version as of last week).
Here's the wierd part. Any errors in the grammar compilation or the parse are not reported properly. All I get for each error is the ':' char. At the place it would normally be in the error.
If I turn on trace, I get the structure of the trace, but not the data. I.e. I get all the '|' but everything else is blank. For example:
1| | | 2| | | 2| | |

The numbers on the left meander up and down, implying that the traces is running properly.
I tried the FAQ trick of redirecting the error output to a file, and the file contains the same erroneous results as the screen.
I am totally stumped, anyone seen this behavior? here's my code that sets up the parse:
use strict; use warnings; use Data::Dumper; use Parse::RecDescent; use File::Slurp; open (Parse::RecDescent::ERROR, ">errfile") or die "Can't redirect errors to file 'errfile'"; $::RD_ERRORS=1; $::RD_WARN=1; $::RD_HINT=1; $::RD_TRACE=$ARGV[0]; sub main { my $grammar=read_file("etc/parser.rd"); my $parser = new Parse::RecDescent($grammar); my $data = read_file("data/spec.spd"); $parser->program($data); } main();


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Replies are listed 'Best First'.
Re: Wierd Windows Parse::RecDescent output problem
by ikegami (Patriarch) on Dec 31, 2007 at 20:19 UTC

    The trace is printed to TRACE, not ERROR, so I don't see how you get the trace structure to be redirected in the first.

    But if I redirect TRACE in the same manner as you redirected ERROR it works fine in Active Perl 5.8.8 build 817. I'll see about trying other versions. (By the way, there's also TRACECONTEXT. It probably needs redirecting too.)

    use strict; use warnings; use Parse::RecDescent; $::RD_ERRORS=1; $::RD_WARN=1; $::RD_HINT=1; $::RD_TRACE=1; open(Parse::RecDescent::ERROR, '>', 'errfile') or die("Can't redirect errors to file 'errfile': $!\n"); open(Parse::RecDescent::TRACE, '>', 'tracefile') or die("Can't redirect errors to file 'tracefile': $!\n"); Parse::RecDescent->new('parse:')->parse('');
    >perl 659805a.pl printing code (3018) to RD_TRACE >type errfile Parse::RecDescent: Treating "parse:" as a rule declaration >type tracefile 1| parse |Trying rule: [parse] | 1| parse |Trying production: [] | 1| parse |>>Matched production: []<< | 1| parse |>>Matched rule<< (return value: | | |[parse]) | 1| parse |(consumed: []) |

    In any case, it's not an error with Parse::RecDescent. Taking out the relevant bits:

    use strict; use warnings; use vars '$tracemsg'; use vars '$tracecontext'; use vars '$tracerulename'; use vars '$tracelevel'; open (TRACE, ">&STDERR"); format TRACE = @>|@|||||||||@^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<| $tracelevel, $tracerulename, '|', $tracemsg | ~~ |^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<| $tracemsg . $tracemsg = 'tracemsg'; $tracecontext = 'tracecontext'; $tracerulename = 'tracerulename'; $tracelevel = 'tracelevel'; write TRACE; open(TRACE, ">tracefile") or die; $tracemsg = 'tracemsg'; $tracecontext = 'tracecontext'; $tracerulename = 'tracerulename'; $tracelevel = 'tracelevel'; write TRACE;
    >perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 817 [257965] provided by ActiveState http://www.ActiveSta +te.com Built Mar 20 2006 17:54:25 ... >perl 659805b.pl tr|tracerulen|tracemsg | >type tracefile tr|tracerulen|tracemsg |
      I did a little more digging. apparently it is the format that is not working. if I replace the 'write ERROR;' in the _error routine with a 'printf ERROR ...' the information prints properly.
      So for some reason, formats are not working in my version of Perl.


      -pete
      "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
Re: Wierd Windows Parse::RecDescent output problem
by ikegami (Patriarch) on Dec 31, 2007 at 20:30 UTC

    No problems with Perl 5.10.0 build 1001 either.

    >c:\progs\perl5100\bin\perl 659805a.pl printing code (3030) to RD_TRACE >type errfile Parse::RecDescent: Treating "parse:" as a rule declaration >type parsefile The system cannot find the file specified. >type tracefile 1| parse |Trying rule: [parse] | 1| parse |Trying production: [] | 1| parse |>>Matched production: []<< | 1| parse |>>Matched rule<< (return value: | | |[parse]) | 1| parse |(consumed: []) |
    >c:\progs\perl5100\bin\perl -v This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2007, Larry Wall Binary build 1001 [283495] provided by ActiveState http://www.ActiveSt +ate.com Built Dec 18 2007 08:46:15 ... >c:\progs\perl5100\bin\perl 659805b.pl tr|tracerulen|tracemsg | >type tracefile tr|tracerulen|tracemsg |
Re: Wierd Windows Parse::RecDescent output problem
by Khisanth (Novice) on Dec 31, 2008 at 05:48 UTC

    http://rt.cpan.org/Public/Bug/Display.html?id=36085
    Looks like the solution is to upgrade Parse::RecDescent

    (I know this is over a year old but someone with the same problem pointed to this node yesterday.)

      Thankyou very much for posting that... Just solved my problem too. ++

      Update: more info: exact same problem description, using ActivePerl under windows:

      This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 registered patches, see perl -V for more detail) ... Binary build 1004 [287188] provided by ActiveState http://www.ActiveSt +ate.com Built Sep 3 2008 13:16:37

      ... and Parse::RecDescent 1.94 (upgrading to 1.96 fixes the problem)

      Update: upgrade to 1.96, not 1.60 :)


      Life is denied by lack of attention,
      whether it be to cleaning windows
      or trying to write a masterpiece...
      -- Nadia Boulanger