Re: question on directive <commit> and subrules
[email protected] (damian)
| Newsgroups | perl.recdescent |
|---|---|
| Organization | Perl Foundation |
| Message-ID | <[email protected]> |
> Ques: When a subrule in a rule that has a "zero or
> more" repetition specifier (ie. ? or s?) has a
> <commit> directive in its production followed by the
> conditional <error?> <reject> production, if that
> subrule's production becomes committed, does that
> error cause the rule containing the subrule to fail
> also? It should right, if we have committed? It does
> not seem to work.
>
> Here is what I mean:
>
> myrule: 'stuff' mysubrule(?)
>
> mysubrule: ID <commit> '[' ']'
> | <error?> <reject>
>
> If the 1st production of mysubrule has committed, then
> myrule should fail. It doesn't seem to.
The optional nature of the reference to mysubrule(?)
means that, when the subrule fails (whether committed or not)
the failure doesn't matter, since myrule can match if it
finds zero mysubrules, which it just did.
> If this is not a bug, how do I get this behavior?
Usually by "anchoring" the end of the match. That might be:
myrule: 'stuff' mysubrule(?) ...!ID
mysubrule: ID <commit> '[' ']'
| <error?> <reject>
or
myrule: 'stuff' mysubrule(?) /\s*\Z/
mysubrule: ID <commit> '[' ']'
| <error?> <reject>
or whatever addition confirms that there really wasn't anything else
after 'stuff'.
Damian