Re: Perhaps a FAQ: How to shortcut an alternation if one already commited subrule fails

[email protected] ("Sean O'Rourke") Wed, 31 Mar 2004 08:54:08 -0800
Newsgroups perl.recdescent
Message-ID <[email protected]>
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