in reply to Parse::Recdescent optional subrule commit
My expectation is that the package definitely is maintained, and I believe that there is an error in your assumptions about the grammar. Not trying to delve too deeply into this (but having spent more than a year working magic with this package), if your grammar says that myrule consists of 'stuff' optionally followed by mysubrule, and the string begins with the token 'stuff' 'ID', then parsing has succeeded with just those tokens present: you said to <commit> after reading 'ID', and the rule did not fail until thereafter. You said also that the rule was optional, thereby saying that rule-failure was okay: the failure of an optional subrule means that it is not present, and your rule for myrule contains no subsequent condition that must be met. (This, BTW, is why programming-language statements are traditionally obliged to end with a semicolon. Generally speaking, when something is “optional,” you ought to stipulate that something that is not optional must follow it.
What you probably intend to do is to say that myrule : 'stuff' something_else, where something_else consists of several alternatives, one of which is the (now, non-optional) subrule, among others (the last of which might be an error-case). You are now saying, as I think you always intended to be saying, that the grammar must match one of the available alternatives, or declare that an error has occurred. I do not think that you actually mean for the rule to be “optional” at all.
Turning on the tracer is pretty much mandatory when using this module, and its tracer is quite generous. It will show you, in rather exhaustive detail, what it thought that your grammar meant. Undoubtedly, this will not be what you intended for that grammar to mean, but it will be a valid interpretation nonetheless.
A recursive-descent parser has its “certain peculiarities.” And grammars, in general, are always a challenge. Really, the only way to rigorously test them is to build up a rather extensive Test::Most testing suite that it must pass, and to build up and maintain that testing suite as you develop your grammar ... using git or some other version-control system as you go.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parse::Recdescent optional subrule commit
by Anonymous Monk on Apr 30, 2012 at 14:11 UTC | |
by locked_user sundialsvc4 (Abbot) on May 01, 2012 at 02:11 UTC | |
|
Re^2: Parse::Recdescent optional subrule commit
by campugnatus (Initiate) on May 01, 2012 at 10:27 UTC | |
by locked_user sundialsvc4 (Abbot) on May 01, 2012 at 14:27 UTC | |
by campugnatus (Initiate) on May 02, 2012 at 12:19 UTC |