[antlr-interest] Lexer context problem
Gavin Lambert
antlr at mirality.co.nz
Sat Nov 24 02:44:30 PST 2007
At 21:56 24/11/2007, Keith Whittingham wrote:
>Could someone explain what I'm doing wrong here
[...]
>NAME
> : {!brackets}?
>('A'..'Z'|'a'..'z'|'.'|'_')('0'..'9'|'A'..'Z'|'a'..'z'|'.'|'_')+
> ;
[...]
>DOTDOT
> : {brackets}? '..'
> ;
[...]
>I always get an error "ine 1:6 rule NAME failed predicate:
>{!brackets}?"
You could try using a gated predicate (put => after the ?). I'm a
little fuzzy on the exact behaviour but I think this makes it a
decision-making predicate instead of just a verification predicate
-- so it's stronger.
If that doesn't work either then possibly ANTLR is discarding the
predicate because it can't see any alts within the rule
itself. If that's what's happening then you'll need to rewrite
your rules so that you either match the bracket sequence
completely in the parser or completely within the lexer. Either
way, losing the predicates.
More information about the antlr-interest
mailing list