| Newsgroups |
perl.recdescent |
| Message-ID |
<[email protected]> |
So, this works to set RD_TRACE:
perl -MParse::RecDescent -s - -RD_TRACE grammar NewMakepp::Grammar
Unfortunately, it looks like the path taken by the precompilation fails to actually check for undefined rules. This may be a bug, or may have been intentional, I'll have to follow up with Damian.
Even if this were fixed, I'm not sure how useful the '-s' command line option is, as -RD_AUTOSTUB will set $::RD_AUTOSTUB to '1'. An undocumented feature of $::RD_AUTOSTUB is that if it has a boolean-true value, an undefined rule named 'foo' will not get the production
foo: 'foo'
but instead get the production:
foo: $::RD_AUTOSTUB
Which, for -s -RD_AUTOSTUB, will generate:
foo: '1'
1: '1'
Which probably isn't what you wanted in the first place.
Long story short, RD_AUTOSTUB doesn't currently work with precompilation of parsers. You'll have to either not precompile, or define your own stub productions.
Please file a ticket for this issue. I'm out of town for the next week, but will try to get this into a bugfix release next week. I've included details on the issue below, feel free to include them in the bug. You can find the ticket tracker for Parse::RecDescent here:
https://rt.cpan.org/Public/Dist/Display.html?Name=Parse-RecDescent
Note that this isn't unique to the command line, but appears to be a problem with the Precompile method. The callstack is something like:
script: Parse::RecDescent->Precompile($grammar, $class, $sourcefile)
Precompile: $self = Parse::RecDescent->new($grammar,1,$class)
new: $self->Replace($grammar, 1, $class)
Replace: _generate($self, $grammar, 1(fromsplice), 1, $class);
_generate: my ($self, $grammar, $replace, $isimplicit, $isleftop) = (@_, 0);
So, the '1' added to @_ from Precompile in the call to new() ends up becoming $isimplicit.
$isimplicit prevents $self->_check_grammar() from being called, which is the function that does the RD_AUTOSTUB checking/generation. I'll have to look into why _check_grammar is skipped for $isimplicit cases.
There also appears to be another bug here, where the $class parameter gets incorrectly propagated from Precompile into $isleftop inside of _generate, which is probably not correct. Unless I've misread the code somewhere.
On 1/12/2012 10:01 AM, Yuri Shtil wrote:
> Well, I found as much myself, tried all I could and it did not work.
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Thursday, January 12, 2012 9:53 AM
> To: [email protected]
> Subject: Re: How to build parser with autostubbing
>
> Consult the section on '-s' at http://perldoc.perl.org/perlrun.html:
>
> -s
>
> enables rudimentary switch parsing for switches on the command line
> after the program name but before any filename arguments (or before
> an argument of --). Any switch found there is removed from @ARGV and
> sets the corresponding variable in the Perl program. The following
> program prints "1" if the program is invoked with a -xyz switch, and
> "abc" if it is invoked with -xyz=abc.
> #!/usr/bin/perl -s
> if ($xyz) { print "$xyz\n" }
>
> Do note that a switch like --help creates the variable ${-help} ,
> which is not compliant with use strict "refs" . Also, when using
> this option on a script with warnings enabled you may get a lot of
> spurious "used only once" warnings.
>
>
> So this is probably what you want:
>
> perl -MParse::RecDescent -s -RD_AUTOSTUB - grammar NewMakepp::Grammar
>
> Untested, you may need to move -s, '-RD_AUTOSTUB and the '- grammar ...' arguments around to make it work.
>
> On 1/12/2012 9:39 AM, Yuri Shtil wrote:
>> The documentation is a little unclear
>>
>> I use perl -MParse::RecDescent - grammar NewMakepp::Grammar to create a parser module.
>>
>> What do I do in order to generate stubs for undefined rules?
>> How do I pass RD_AUTOSTUB?
>>
>> ----------------------------------------------------------------------
>> ------------- This email message is for the sole use of the intended
>> recipient(s) and may contain confidential information. Any
>> unauthorized review, use, disclosure or distribution is prohibited.
>> If you are not the intended recipient, please contact the sender by
>> reply email and destroy all copies of the original message.
>> ----------------------------------------------------------------------
>> -------------
>>