[antlr-interest] rule, that consider token, follow the match token
Bart Kiers
bkiers at gmail.com
Thu Jun 28 04:46:49 PDT 2012
On Thu, Jun 28, 2012 at 1:20 PM, Andrei Plet <andrei.plet at empolis.com>wrote:
> ...
> OP_AND : ('A'|'a') ('N'|'n') ('D'|'d');
> TEXT : ('a'..'z'|'A'..'Z')+;
> PLUS : '+';
>
> The rule OP_AND should match only, if after the input 'and' isn't a '+', so
>
> 'and' --> should match rule OP_AND
> 'and+' --> should match 2 rules: the rule TEXT 'and' and rule PLUS '+'
>
>
I wouldn't do that in the lexer, but something like this instead:
OP_AND : ('A'|'a') ('N'|'n') ('D'|'d');
TEXT : ('a'..'z'|'A'..'Z')+;
PLUS : '+';
any_text : OP_AND | TEXT;
add_expr : any_text PLUS any_text;
Regards,
Bart.
More information about the antlr-interest
mailing list