Sean O'Rourke schrieb:
Barring Perl 6, one thing you can do is lift the unique prefixes up into the rule you want to fail, e.g.:
ENTITY : ( '#' <commit> COMMENT | IDENT '=' <commit> OPTION | TYPE NAME '{' <commit> DECLARATION | 'scope' <commit> SCOPE )(s)
COMMENT : m/.*/
OPTION : VALUE { store($item{IDENT}, $item{VALUE}) }
DECL : DECL_BODY '}' { store($item{TYPE}, $ITEM{NAME}, $ITEM{DECL_BODY}) }
SCOPE : '{' ENTITY(s) '}'
On the other hand, this _does_ highlight exactly what prefixes you're using to distinguish between rules. And it suggests you might want to put SCOPE right after comment, since it is accepted or rejected based on a single, simple token.
sure this is one possibility with a lot of drawbacks.
In my example I need the prefixes for processing it in the subrule actions and the parent rule consumed it already. OK, I could send it downstream as arguments but this makes the grammar very uply and hard to maintain.
The biggest drawback is the error message: With commiting the different productions already in the ENTITY rule, I get just an error message, stating that a ENTITY failed, not if it was already a commited OPTION or DECLARATION etc.
I was thinking about unique prefix lookahead, but this failed due to the multi token prefixes like TYPE VALUE in the declaration. OK, again you could collapse this to one more indirection, but this makes the grammar again more unreadable and hard to mainatin (the example is just a shrink down extract in a huge grammar).
Hmm, any solutions with this - now more detailed - problem in mind?
Best Regards Charly
-- Karl Gaissmaier KIZ/Infrastructure, University of Ulm, Germany Email:[EMAIL PROTECTED] Service Group Network Tel.: ++49 731 50-22499