What is the simplest (shortest, smallest rule and no warning) way to analyze both real dates and numbers in one grammar? My problem is that the lexer rule to match a valid month (1-12) will match any occurrence of 1-12. Therefore, if I just want to match the number, I need a parsing rule, for example:
number: (MONTH|INT);
It only gets complicated when I add lexer rules for day and year. I want a date syntax rule:
date: month '/' day ( '/' year )? -> ^('DATE' year month day);
I don’t care if the month, day and year are the rules of parsing or lexer, only as long as I get the same tree structure. I should also be able to recognize numbers elsewhere, for example:
foo: STRING OP number -> ^(OP STRING number);
STRING: ('a'..'z')+;
OP: ('<'|'>');