I want to parse ISO 8601 dates in my ANTLR grammar.
2001-05-03
I have the following entries in my grammar file:
date : FOUR_DIGIT ('-')? TWO_DIGIT ('-')? TWO_DIGIT ;
FOUR_DIGIT
: TWO_DIGIT TWO_DIGIT ;
TWO_DIGIT
: DIGIT DIGIT ;
DIGIT : ('0'..'9') ;
I know I can match one or more with DIGIT+
and zero or more with DIGIT*
While this works, is there a simpler syntax to specify I want to match exactly 2 DIGIT
?
DIGIT
patterns. – Mirador