1 // antlr4 -Dlanguage=Python3 ./dateparse_utils.g4
3 // Hi, self. In ANTLR grammars, there are two separate types of symbols: those
4 // for the lexer and those for the parser. The former begin with a CAPITAL
5 // whereas the latter begin with lowercase. The order of the lexer symbols
6 // is the order that the lexer will recognize them in. There's a good tutorial
9 // https://tomassetti.me/antlr-mega-tutorial/
11 // There are also a zillion premade grammars at:
13 // https://github.com/antlr/grammars-v4
15 grammar dateparse_utils;
21 | baseAndOffsetDateExpr
25 : monthDayMaybeYearExpr
26 | dayMonthMaybeYearExpr
28 | specialDateMaybeYearExpr
29 | nthWeekdayInMonthMaybeYearExpr
30 | firstLastWeekdayInMonthMaybeYearExpr
34 : monthExpr DIV* dayOfMonth (DIV* year)?
38 : dayOfMonth DIV* monthName (DIV* year)?
42 : year DIV* monthName DIV* dayOfMonth
45 nthWeekdayInMonthMaybeYearExpr
46 : nth dayName ('in'|'of') monthName (DIV* year)?
49 firstLastWeekdayInMonthMaybeYearExpr
50 : firstOrLast dayName ('in'|'of'|DIV)? monthName (DIV* year)?
53 specialDateMaybeYearExpr
54 : specialDate (DIV* year)?
58 : baseDate deltaPlusMinusExpr
59 | deltaPlusMinusExpr baseDate
62 baseDate: singleDateExpr ;
64 deltaPlusMinusExpr: deltaInt deltaUnit deltaBeforeAfter? ;
66 deltaUnit: (WEEK|DAY|SUN|WEEKDAY) ;
68 deltaBeforeAfter: (BEFORE|AFTER) ;
75 year: DIGIT DIGIT DIGIT DIGIT ;
77 specialDate: SPECIAL_DATE ;
79 dayOfMonth: DIGIT? DIGIT ('st'|'nd'|'rd'|'th')? ;
81 firstOrLast: (FIRST|LAST) ;
83 nth: DIGIT ('st'|'nd'|'rd'|'th')? ;
85 deltaInt: ('+'|'-')? DIGIT+ ;
91 monthNumber: DIGIT? DIGIT ;
93 // ----------------------------------
95 COMMENT: '#' ~[\r\n]* -> skip ;
97 SPACE: [ \t\r\n] -> skip ;
103 MONTH: (JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC) ;
153 WEEKDAY: (SUN|MON|TUE|WED|THU|FRI|SAT) ;
212 | MARTIN_LUTHER_KING_DAY
266 MARTIN_LUTHER_KING_DAY
267 : 'martin luther king day'
303 | 'indiginous peoples day'
304 | 'indiginous peoples\' day'
326 AFTER: ('after'|'from') ;