I have following grammar for parsing time expressions like '1 day 2 hour'.
time : timeLiteral
| FLOAT
| INTEGER
;
timeLiteral : dayExpr hourExpr? minuteExpr? ;
dayExpr : timeVal ('days' | 'day') ;
hourExpr : timeVal ('hour'|'hours') ;
minuteExpr : timeVal ('minutes' | 'minute') ;
timeVal : INTEGER | FLOAT ;
INTEGER : '0' 'x' (HEXDIGIT)+
| (DIGIT)+
;
FLOAT : '.' (DIGIT)+ (EXPONENT)?
| ((DIGIT)+ '.') => (DIGIT)+ '.' (DIGIT)* (EXPONENT)?
| (DIGIT)+ ('.' (DIGIT)*)? EXPONENT
;
fragment DIGIT : '0'..'9';
fragment HEXDIGIT : 'a'..'f' | 'A'..'F' | DIGIT;
fragment EXPONENT : ('e' | 'E') ('+' | '-')? (DIGIT)+;
This works fine for expressions like '1day 2hour' but fails when hexadecimal values are used with day without space. Like '0x23day 0x56hour'. In this case lexer creates an INTEGER token with value '0x23da'. So instead of getting INTEGER, 'day' parser is getting INTEGER, 'y'. What can I do to make lexer give me 0x23 as INTGER and 'day'.?