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.

/s

Karl Gaissmaier <[EMAIL PROTECTED]> writes:

> Hi P::RD lovers,
>
> is there a general advice to shortcut an alternation in a rule
> if one already commited subrule fails:
>
> Example:
>
> ENTITY : ( COMMENT | OPTION | DECLARATION | SCOPE )(s)
>
> COMMENT : '#' <commit> m/.*/
>            | <error?> <reject>
>
> OPTION  : IDENT '=' <commit> VALUE
>            { store($item{IDENT}, $item{VALUE}) }
>            | <error?> <reject>
>
> DECL    : TYPE NAME '{' <commit> DECL_BODY '}'
>            { store($item{TYPE}, $ITEM{NAME}, $ITEM{DECL_BODY}) }
>            | <error?> <reject>
>
> SCOPE   : 'scope' <commit> '{' ENTITY(s) '}'
>            | <error?> <reject>
>
>
> I would like to see the immediately failure of ENTITY, if
> e.g. the DECL subrule fails after already commited.
>
> Is there a general usage pattern to shortcut the ENTITY rule
> if an already commited subrule fails?
>
>
> Best Regards
>       Charly
> -- 
> Karl Gaissmaier       KIZ/Infrastructure, University of Ulm, Germany
> Email:[EMAIL PROTECTED]           Service Group Network
> Tel.: ++49 731 50-22499

Reply via email to