[antlr-interest] rule, that consider token, follow the match token
    Andrei Plet 
    andrei.plet at empolis.com
       
    Thu Jun 28 07:16:55 PDT 2012
    
    
  
Bart;
Thanks for fast response.
Your solution works fine.
Thanks and kind regards
Andrei
Von: Bart Kiers [mailto:bkiers at gmail.com]
Gesendet: Donnerstag, 28. Juni 2012 13:47
An: Andrei Plet
Cc: antlr-interest at antlr.org
Betreff: Re: [antlr-interest] rule, that consider token, follow the match token
On Thu, Jun 28, 2012 at 1:20 PM, Andrei Plet <andrei.plet at empolis.com<mailto: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