I would say this is a bug, but I can't really be sure :)

According to my reading of http://search.cpan.org/~jtbraun/Parse-RecDescent-1.967009/lib/Parse/RecDescent.pm#Rejecting_a_production, if you replace reject:$failed with the equivalent

<reject: defined $failed> { print "WHAT!\n"; exit }

The program will print "WHAT!" and exit

So it could be that its a bug, or it could be the gotcha http://search.cpan.org/~jtbraun/Parse-RecDescent-1.967009/lib/Parse/RecDescent.pm#1._Expecting_an_error_to_always_invalidate_a_parse

update: It probably is a bug, because the actual equivalent would return UNDEF on failure and not EXIT, and when I do that, the error propagates, so it is probably a bug in reject autohandler or something ... Hooray, I can't fix it :)

#!/usr/bin/perl -- use Parse::RecDescent; my $grammar = q( myrule : <rulevar: local $failed> myrule : 'stuff' mysubrule(?) <reject: defined $failed> { print "WHAT +($failed)!\n"; undef } | <error> mysubrule: 'ID' <commit> '[' ']' | <error?> { $failed++ } ); my $parser = Parse::RecDescent->new($grammar) or die "hi"; for my $text ( "stuff ID something", "stuff something", ){ print "text => $text\n"; my $tree = eval { $parser->myrule($text) }; warn $@ if $@; use Data::Dump qw/ dd /; dd $tree; } __END__ text => stuff ID something WHAT ()! ERROR (line 1): Invalid mysubrule: Was expecting '[' but found "something" instead ERROR (line 1): Invalid myrule: Was expecting 'stuff' undef text => stuff something ERROR (line 1): Invalid myrule: Was expecting 'stuff' undef

update: It think this might be related issue, Bug #62892 for Parse-RecDescent: failed subrules eat text


In reply to Re: Parse::Recdescent optional subrule commit by Anonymous Monk
in thread Parse::Recdescent optional subrule commit by campugnatus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.