Skip to content

Instantly share code, notes, and snippets.

@yaauie yaauie/Iso8601.g4
Created May 29, 2016

Embed
What would you like to do?
ISO-8601 Grammar
grammar Iso8601;
temporal : year (HYPHEN subyear)? offset? EOF
;
subyear : month (HYPHEN submonth)?
| W_LITERAL week (HYPHEN subweek)?
| Q_LITERAL quarter (HYPHEN subquarter)?
| oday (T_LITERAL subday)?
;
submonth : mday (T_LITERAL subday)?
;
subweek : wday (T_LITERAL subday)?
;
subquarter: qday (T_LITERAL subday)?
;
subday : hour (COLON subhour)?
;
subhour : minute (COLON subminute)?
;
subminute : second (DECIMAL subsecond)?
;
subsecond : dsec
| csec
| msec
;
offset : OFFSET ;
OFFSET : Z_LITERAL
| ('+' | '-') DIGIT2 ':' DIGIT2
;
HYPHEN : '-' ;
COLON : ':' ;
DECIMAL : '.' ;
T_LITERAL : 'T' ;
W_LITERAL : 'W' ;
Q_LITERAL : 'Q' ;
Z_LITERAL : 'Z' ;
year : DIGIT4 ;
month : DIGIT2 ;
week : DIGIT2 ;
quarter : DIGIT1 ;
qday: DIGIT2 ;
mday : DIGIT2 ;
wday : DIGIT1 ;
oday : DIGIT3 ;
hour : DIGIT2 ;
minute : DIGIT2 ;
second : DIGIT2 ;
dsec : DIGIT1 ;
csec : DIGIT2 ;
msec : DIGIT3 ;
DIGIT4 : [0-9] DIGIT3 ;
DIGIT3 : [0-9] DIGIT2 ;
DIGIT2 : [0-9] DIGIT1 ;
DIGIT1 : [0-9] ;

A work-in-progress grammar for ISO-8601.

This grammar will initially be used to parse temporal /resolutions/ without loss of specified precision (e.g., the string 2016-05 will be parsed to an object represeting the entire month of May 2016, while the string 2016-05-30T18Z will represent the zulu-hour starting a8 18:00 and running to 19:00 on May 30, 2016.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.