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

I spent several hours chasing down a simple bug in my Parse::RecDescent (P::RD) grammar. It turned out that in one of my subrules, I wrote:
equals: '>=' | '<=' | '=' | '>' | '>'
Note the duplication of the '>' symbol. This works fine in Perl (`perl -e 'print 0 || "hi" || "hi"'`), but apparently P::RD didn't really like it. Finally, jcwren showed me my stupid error. I changed the second '>' to '<' and everything magically worked.

But it left me wondering why this would cause the rule not to work correctly. After all, it works in Perl.

Is there anyone familiar with the inner workings of Parse::RecDescent who would care to shine a light on this seemingly mysterious behavior?


I realize that P::RD is only supposed to work on correct grammar, and this certainly wasn't correct (technically). But this should at least be considered a GOTCHA in the docs, and if possible, should be the target of some error-checking code in the next release.

Thanks!

Quinn Slack
perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'

Replies are listed 'Best First'.
Re: Parse::RecDescent gotcha? - duplicates in ORs
by hossman (Prior) on Mar 15, 2002 at 06:49 UTC
    I don't have any practicle experience with Parse::RecDescent, but i remember seeing this the other day when skimming the docs for another node...
    # Global flags (useful as command line arguments under -s):
    
          $::RD_ERRORS       # unless undefined, report fatal errors
          $::RD_WARN         # unless undefined, also report non-fatal problems
          $::RD_HINT         # if defined, also suggestion remedies
          $::RD_TRACE        # if defined, also trace parsers' behaviour
          $::RD_AUTOSTUB     # if defined, generates "stubs" for undefined rules
          $::RD_AUTOACTION   # if defined, appends specified action to productions
    
    did you try setting $::RD_HINT ?
      I already got it working before I posted. But $::RD_HINT didn't reveal any reasons as to why this quirk exists.

      Quinn Slack
      perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'