I have the following ANTLR grammar
relation
: IDENTIFIER EQUAL relative_date
;
relative_date
: K_NOW (PLUS | MINUS) NUMERIC_LITERAL TIME_UNIT
;
IDENTIFIER
: //'"' (~'"' | '""')* '"'
'`' (~'`' | '``')* '`'
| '[' ~']'* ']'
| [a-zA-Z_] [a-zA-Z_.0-9]*
;
TIME_UNIT
: ('h'|'m'|'s'|'d'|'w'|'M'|'y'|'q')
;
PLUS : '+';
MINUS : '-';
EQUAL: '=';
K_NOW : N O W;
NUMERIC_LITERAL
: [0-9]+ ;
If I put TIME_UNIT before IDENTIFIER parser
something = now - 5dworksd = now - 5dDOES NOT work and fails at firstdand saysIDENTIFIERrequired
If I put TIME_UNIT after IDENTIFIER parser
something = now - 5dfails at the seconddand says TIME_UNIT requiredd = now - 5dfails at the seconddand says TIME_UNIT required
Can someone help me how can I change the grammar to work in both cases? Like when it is a relative date use TIME_UNIT lexer otherwise IDENTIFIER lexer