[antlr-interest] PEG-style "and" predicates

David Piepgrass qwertie256 at gmail.com
Mon Jul 2 16:38:13 PDT 2007


> I tried making a rule like this:
>
>    FOO : ('bar' ' '* ('\n' | '\r' | EOF))=> 'bar' ;
>
> But it doesn't work.
...
> My understanding of predicates (notes at <http://wincent.com/
> knowledge-base/ANTLR_predicates>) leads me to believe that this is
> failing because in ANTLR, syntactic predicates are used to order a
> rule's alternatives. They are not like gated semantic predicates
> which can be used to turn an entire rule off depending on context. It

Hmm, I realize I am very puzzled about something. If these predicates
aren't used for prediction, then what are they good for? A means to
reorder alternatives is not really needed--if the user wants to
reorder alternatives, he can simply do so. They get rid of warnings,
but this would be better accomplished with a special option (as was
available in v2).

IMO, this line really ought to work as you expected:

FOO : ('bar' ' '* ('\n' | '\r' | EOF))=> 'bar' ;


More information about the antlr-interest mailing list