Skip to content

Instantly share code, notes, and snippets.

@chrisalbright
Forked from robjens/date.abnf
Created July 7, 2016 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisalbright/89fe583abd06556a2244070cb60ff429 to your computer and use it in GitHub Desktop.
Save chrisalbright/89fe583abd06556a2244070cb60ff429 to your computer and use it in GitHub Desktop.
A few BNF files I co(rr|ll)ected for Instaparse
; http://www.ietf.org/rfc/rfc3339.txt
; and http://www.odata.org/documentation/odata-version-3-0/abnf/
oneToNine = "01" / "02" / "03" / "04" / "05" / "06" / "07" / "08" / "09"
zeroToNine = "00" / oneToNine
oneToTwelve = oneToNine / "1" ( "0" / "1" / "2" )
oneToThirteen = oneToTwelve / "13"
zeroToFiftyNine = zeroToNine / ( "1" / "2" / "3" / "4" / "5" ) DIGIT
zeroToSixty = zeroToNine / ( "1" / "2" / "3" / "4" / "5" ) DIGIT / "60"
oneToThirtyOne = oneToNine / ( "1" / "2" ) DIGIT / "30" / "31"
zeroToTwentyFour = zeroToNine / "1" DIGIT / "2" ( "0" / "1" / "2" / "3" / "4" )
date-century = 2DIGIT ; 00-99
date-decade = DIGIT ; 0-9
date-subdecade = DIGIT ; 0-9
date-year = date-decade date-subdecade
date-fullyear = date-century date-year
date-month = oneToTwelve ; 01-12
date-wday = DIGIT ; 1-7 ; 1 is Monday, 7 is Sunday
date-mday = oneToThirtyOne ; 01-28, 01-29, 01-30, 01-31 based on
; month/year
date-yday = 3DIGIT ; 001-365, 001-366 based on year
date-week = 2DIGIT ; 01-52, 01-53 based on year
datepart-fullyear = [date-century] date-year ["-"]
datepart-ptyear = "-" [date-subdecade ["-"]]
datepart-wkyear = datepart-ptyear / datepart-fullyear
dateopt-century = "-" / date-century
dateopt-fullyear = "-" / datepart-fullyear
dateopt-year = "-" / (date-year ["-"])
dateopt-month = "-" / (date-month ["-"])
dateopt-week = "-" / (date-week ["-"])
datespec-full = datepart-fullyear date-month ["-"] date-mday
datespec-year = date-century / dateopt-century date-year
datespec-month = "-" dateopt-year date-month [["-"] date-mday]
datespec-mday = "--" dateopt-month date-mday
datespec-week = datepart-wkyear "W"
(date-week / dateopt-week date-wday)
datespec-wday = "---" date-wday
datespec-yday = dateopt-fullyear date-yday
date = datespec-full / datespec-year
/ datespec-month /
datespec-mday / datespec-week / datespec-wday / datespec-yday
time-hour = zeroToTwentyFour ; 00-24
time-minute = zeroToFiftyNine ; 00-59
time-second = zeroToSixty ; 00-58, 00-59, 00-60 based on
; leap-second rules
time-fraction = ("," / ".") 1*DIGIT
time-numoffset = 0*1SP ("+" / "-") time-hour [[":"] time-minute]
time-zone = "Z" / time-numoffset
timeopt-hour = "-" / (time-hour [":"])
timeopt-minute = "-" / (time-minute [":"])
timespec-hour = time-hour [[":"] time-minute [[":"] time-second]]
timespec-minute = timeopt-hour time-minute [[":"] time-second]
timespec-second = "-" timeopt-minute time-second
timespec-base = timespec-hour / timespec-minute / timespec-second
time = timespec-base [time-fraction] [time-zone]
date-time-sep = "T" / SP
iso-date-time = date date-time-sep time
dur-second = 1*DIGIT "S"
dur-minute = 1*DIGIT "M" [dur-second]
dur-hour = 1*DIGIT "H" [dur-minute]
dur-time = "T" (dur-hour / dur-minute / dur-second)
dur-day = 1*DIGIT "D"
dur-week = 1*DIGIT "W"
dur-month = 1*DIGIT "M" [dur-day]
dur-year = 1*DIGIT "Y" [dur-month]
dur-date = (dur-day / dur-month / dur-year) [dur-time]
duration = "P" (dur-date / dur-time / dur-week)
; http://tools.ietf.org/html/rfc5322#section-3.4.1
addr-spec = local-part "@" domain
local-part = dot-atom / quoted-string / obs-local-part
domain = dot-atom / domain-literal / obs-domain
domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
dtext = %d33-90 / ; Printable US-ASCII
%d94-126 / ; characters not including
obs-dtext ; "[", "]", or "\"
; http://tools.ietf.org/html/rfc5322#section-3.2.3
atext = ALPHA / DIGIT / ; Printable US-ASCII
"!" / "#" / ; characters not including
"$" / "%" / ; specials. Used for atoms.
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
atom = [CFWS] 1*atext [CFWS]
dot-atom-text = 1*atext *("." 1*atext)
dot-atom = [CFWS] dot-atom-text [CFWS]
specials = "(" / ")" / ; Special characters that do
"<" / ">" / ; not appear in atext
"[" / "]" /
":" / ";" /
"@" / "\" /
"," / "." /
DQUOTE
; http://tools.ietf.org/html/rfc5322#section-3.2.4
qtext = %d33 / ; Printable US-ASCII
%d35-91 / ; characters not including
%d93-126 / ; "\" or the quote character
obs-qtext
qcontent = qtext / quoted-pair
quoted-string = [CFWS]
DQUOTE *([FWS] qcontent) [FWS] DQUOTE
[CFWS]
; http://tools.ietf.org/html/rfc5322#section-3.2.2
FWS = ([*WSP CRLF] 1*WSP) / obs-FWS
; Folding white space
ctext = %d33-39 / ; Printable US-ASCII
%d42-91 / ; characters not including
%d93-126 / ; "(", ")", or "\"
obs-ctext
ccontent = ctext / quoted-pair / comment
comment = "(" *([FWS] ccontent) [FWS] ")"
CFWS = (1*([FWS] comment) [FWS]) / FWS
; http://tools.ietf.org/html/rfc5322#section-4.4
obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS]
obs-route = obs-domain-list ":"
obs-domain-list = *(CFWS / ",") "@" domain
*("," [CFWS] ["@" domain])
obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS])
obs-addr-list = *([CFWS] ",") address *("," [address / CFWS])
obs-group-list = 1*([CFWS] ",") [CFWS]
obs-local-part = word *("." word)
obs-domain = atom *("." atom)
obs-dtext = obs-NO-WS-CTL / quoted-pair
; http://tools.ietf.org/html/rfc5322#section-3.4
address = mailbox / group
mailbox = name-addr / addr-spec
name-addr = [display-name] angle-addr
angle-addr = [CFWS] "<" addr-spec ">" [CFWS] /
obs-angle-addr
group = display-name ":" [group-list] ";" [CFWS]
display-name = phrase
mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list
address-list = (address *("," address)) / obs-addr-list
group-list = mailbox-list / CFWS / obs-group-list
; http://tools.ietf.org/html/rfc5322#section-4.1
obs-NO-WS-CTL = %d1-8 / ; US-ASCII control
%d11 / ; characters that do not
%d12 / ; include the carriage
%d14-31 / ; return, line feed, and
%d127 ; white space characters
obs-ctext = obs-NO-WS-CTL
obs-qtext = obs-NO-WS-CTL
obs-utext = %d0 / obs-NO-WS-CTL / VCHAR
obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR)
obs-body = *((*LF *CR *((%d0 / text) *LF *CR)) / CRLF)
obs-unstruct = *((*LF *CR *(obs-utext *LF *CR)) / FWS)
obs-phrase = word *(word / "." / CFWS)
obs-phrase-list = [phrase / CFWS] *("," [phrase / CFWS])
; http://tools.ietf.org/html/rfc5322#section-3.2.5
word = atom / quoted-string
phrase = 1*word / obs-phrase
unstructured = (*([FWS] VCHAR) *WSP) / obs-unstruct
; http://tools.ietf.org/html/rfc5322#section-3.2.1
quoted-pair = ("\" (VCHAR / WSP)) / obs-qp
; http://tools.ietf.org/html/rfc5322#section-4.2
obs-FWS = 1*WSP *(CRLF 1*WSP)
; http://tools.ietf.org/html/rfc5322#section-3.5
message = (fields / obs-fields)
[CRLF body]
body = (*(*998text CRLF) *998text) / obs-body
text = %d1-9 / ; Characters excluding CR
%d11 / ; and LF
%d12 /
%d14-127
; http://tools.ietf.org/html/rfc5322#section-3.6
fields = *(trace
*optional-field /
*(resent-date /
resent-from /
resent-sender /
resent-to /
resent-cc /
resent-bcc /
resent-msg-id))
*(orig-date /
from /
sender /
reply-to /
to /
cc /
bcc /
message-id /
in-reply-to /
references /
subject /
comments /
keywords /
optional-field)
; http://tools.ietf.org/html/rfc5322#section-4.5
obs-fields = *(obs-return /
obs-received /
obs-orig-date /
obs-from /
obs-sender /
obs-reply-to /
obs-to /
obs-cc /
obs-bcc /
obs-message-id /
obs-in-reply-to /
obs-references /
obs-subject /
obs-comments /
obs-keywords /
obs-resent-date /
obs-resent-from /
obs-resent-send /
obs-resent-rply /
obs-resent-to /
obs-resent-cc /
obs-resent-bcc /
obs-resent-mid /
obs-optional)
; http://tools.ietf.org/html/rfc5322#section-3.6.7
trace = [return]
1*received
return = "Return-Path:" path CRLF
path = angle-addr / ([CFWS] "<" [CFWS] ">" [CFWS])
received = "Received:" *received-token ";" date-time CRLF
received-token = word / angle-addr / addr-spec / domain
; http://tools.ietf.org/html/rfc5322#section-3.3
date-time = [ day-of-week "," ] date time [CFWS]
day-of-week = ([FWS] day-name) / obs-day-of-week
day-name = "Mon" / "Tue" / "Wed" / "Thu" /
"Fri" / "Sat" / "Sun"
date = day month year
day = ([FWS] 1*2DIGIT FWS) / obs-day
month = "Jan" / "Feb" / "Mar" / "Apr" /
"May" / "Jun" / "Jul" / "Aug" /
"Sep" / "Oct" / "Nov" / "Dec"
year = (FWS 4*DIGIT FWS) / obs-year
time = time-of-day zone
time-of-day = hour ":" minute [ ":" second ]
hour = 2DIGIT / obs-hour
minute = 2DIGIT / obs-minute
second = 2DIGIT / obs-second
zone = (FWS ( "+" / "-" ) 4DIGIT) / obs-zone
; http://tools.ietf.org/html/rfc5322#section-4.3
obs-day-of-week = [CFWS] day-name [CFWS]
obs-day = [CFWS] 1*2DIGIT [CFWS]
obs-year = [CFWS] 2*DIGIT [CFWS]
obs-hour = [CFWS] 2DIGIT [CFWS]
obs-minute = [CFWS] 2DIGIT [CFWS]
obs-second = [CFWS] 2DIGIT [CFWS]
obs-zone = "UT" / "GMT" / ; Universal Time
; North American UT
; offsets
"EST" / "EDT" / ; Eastern: - 5/ - 4
"CST" / "CDT" / ; Central: - 6/ - 5
"MST" / "MDT" / ; Mountain: - 7/ - 6
"PST" / "PDT" / ; Pacific: - 8/ - 7
%d65-73 / ; Military zones - "A"
%d75-90 / ; through "I" and "K"
%d97-105 / ; through "Z", both
%d107-122 ; upper and lower case
; http://tools.ietf.org/html/rfc5322#section-3.6.8
optional-field = field-name ":" unstructured CRLF
field-name = 1*ftext
ftext = %d33-57 / ; Printable US-ASCII
%d59-126 ; characters not including
; ":".
; http://tools.ietf.org/html/rfc5322#section-3.6.6
; https://tools.ietf.org/html/rfc6854#section-2.2
resent-date = "Resent-Date:" date-time CRLF
resent-from = "Resent-From:" (mailbox-list / address-list) CRLF
resent-sender = "Resent-Sender:" (mailbox / address) CRLF
resent-to = "Resent-To:" address-list CRLF
resent-cc = "Resent-Cc:" address-list CRLF
resent-bcc = "Resent-Bcc:" [address-list / CFWS] CRLF
resent-msg-id = "Resent-Message-ID:" msg-id CRLF
; http://tools.ietf.org/html/rfc5322#section-3.6.4
message-id = "Message-ID:" msg-id CRLF
in-reply-to = "In-Reply-To:" 1*msg-id CRLF
references = "References:" 1*msg-id CRLF
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
id-left = dot-atom-text / obs-id-left
id-right = dot-atom-text / no-fold-literal / obs-id-right
no-fold-literal = "[" *dtext "]"
; http://tools.ietf.org/html/rfc5322#section-3.6.4
obs-message-id = "Message-ID" *WSP ":" msg-id CRLF
obs-in-reply-to = "In-Reply-To" *WSP ":" *(phrase / msg-id) CRLF
obs-references = "References" *WSP ":" *(phrase / msg-id) CRLF
obs-id-left = local-part
obs-id-right = domain
; http://tools.ietf.org/html/rfc5322#section-3.6.1
orig-date = "Date:" date-time CRLF
; https://tools.ietf.org/html/rfc6854#section-2.1
from = "From:" (mailbox-list / address-list) CRLF
sender = "Sender:" (mailbox / address) CRLF
reply-to = "Reply-To:" address-list CRLF
; http://tools.ietf.org/html/rfc5322#section-3.6.3
to = "To:" address-list CRLF
cc = "Cc:" address-list CRLF
bcc = "Bcc:" [address-list / CFWS] CRLF
; http://tools.ietf.org/html/rfc5322#section-3.6.5
subject = "Subject:" unstructured CRLF
comments = "Comments:" unstructured CRLF
keywords = "Keywords:" phrase *("," phrase) CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.7
obs-return = "Return-Path" *WSP ":" path CRLF
obs-received = "Received" *WSP ":" *received-token CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.1
obs-orig-date = "Date" *WSP ":" date-time CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.2
obs-from = "From" *WSP ":" mailbox-list CRLF
obs-sender = "Sender" *WSP ":" mailbox CRLF
obs-reply-to = "Reply-To" *WSP ":" address-list CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.3
obs-to = "To" *WSP ":" address-list CRLF
obs-cc = "Cc" *WSP ":" address-list CRLF
obs-bcc = "Bcc" *WSP ":"
(address-list / (*([CFWS] ",") [CFWS])) CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.5
obs-subject = "Subject" *WSP ":" unstructured CRLF
obs-comments = "Comments" *WSP ":" unstructured CRLF
obs-keywords = "Keywords" *WSP ":" obs-phrase-list CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.6
obs-resent-from = "Resent-From" *WSP ":" mailbox-list CRLF
obs-resent-send = "Resent-Sender" *WSP ":" mailbox CRLF
obs-resent-date = "Resent-Date" *WSP ":" date-time CRLF
obs-resent-to = "Resent-To" *WSP ":" address-list CRLF
obs-resent-cc = "Resent-Cc" *WSP ":" address-list CRLF
obs-resent-bcc = "Resent-Bcc" *WSP ":"
(address-list / (*([CFWS] ",") [CFWS])) CRLF
obs-resent-mid = "Resent-Message-ID" *WSP ":" msg-id CRLF
obs-resent-rply = "Resent-Reply-To" *WSP ":" address-list CRLF
; http://tools.ietf.org/html/rfc5322#section-4.5.8
obs-optional = field-name *WSP ":" unstructured CRLF
; http://tools.ietf.org/html/rfc6531#section-3.3
; http://www.utf8-chartable.de/unicode-utf8-table.pl
UTF8-non-ascii = %x80-FF / ; Latin-1 Supplement
%x100-17F / ; Latin Extended-A
%x370-3FF / ; Greek and Coptic
%x400-4FF / ; Cyrillic
%x500-52F / ; Cyrillic Supplement
%x4E00-9FFF ; CJK Unified Ideographs
atext =/ UTF8-non-ascii
Module = ( <_> | DefinitionAll | Use | Import )*
DefinitionAll = (Definition | Function)
Definition = Identifier <_*> <'='> <_*> Expression [<_+> Where]
Signature = Identifier <'('> <_*> Args <_*> <')'>
Function = Signature <_*> <'='> <_*> Expression [<_+> Where]
Keyword = 'nil' | 'true' | 'false' | 'when' | 'case' | 'do' | 'if' | 'end' | 'use' | 'import' | 'only' | 'hide' | 'type'
Component = !Keyword #'[A-Za-z_]\w*'
Expressions = (Expression <_+>)* Expression
Expression = Token | Range | Integer | String | Nil | Boolean | Result | Lamda | List | Map | Set | When | Case | Identifier | Float | Do | ListComprehension | SetComprehension | MapComprehension | Type | Protocol
KeyValues = (KeyValue <_+>)* KeyValue
KeyValue = Expression <_*> <':'> <_*> Expression
Result = ( Identifier | Result | Lamda ) <'('> <_*> [Expressions <_*>] <')'>
Lamda = <'('> <_*> Args <':'> <_*> Expression <_*> <')'>
Where = <'where'> <_+> (DefinitionAll <_*>)* <'end'>
When = <'when'> <_+> (KeyValue <_*>)* <'end'>
Case = <'case'> <_+> Identifier <_+> (Branch <_+>)* <'end'>
Identifier = Component (<'.'> Component)*
Guard = <'if'> <_+> Expression
Do = <'do'> <_+> (DefinitionAll <_*>)* <'end'>
Branch = Expression [<_+> Guard] <_*> <':'> <_*> Expression
Namespace = (Identifier <'.'>)* Identifier
Use = <'use'> <_+> Namespace [<_+> ('only'|'hide') (<_+> Identifier)+ ]
Import = <'import'> <_+> Namespace [<_+> 'as' <_+> Identifier ]
ListComprehension = <'['> <_*> Expression <_+> <'for'> <_+> KeyValue [<_+> Guard] <_*> <']'>
MapComprehension = <'{'> <_*> KeyValue <_+> <'for'> <_+> KeyValue [<_+> Guard] <_*> <'}'>
SetComprehension = <'('> <_*> Expression <_+> <'for'> <_+> KeyValue [<_+> Guard] <_*> <')'>
Args = (Identifier <_*>)*
Float = #'-?\d+\.\d+'
Range = ( Expression | Epsilon ) '..' ( Expression | Epsilon )
Integer = #'-?\d+'
String = <'\"'> #'[^"]*' <'\"'>
Token = <'#'> #'\w+'
Nil = <'nil'>
Boolean = 'true' | 'false'
List = <'['> [<_*> Expressions] <_*> <']'>
Map = <'{'> [<_*> KeyValues] <_*> <'}'>
Set = <'('> [<_*> Expressions] <_*> <')'>
Type = <'type'> <_*> (Identifier <_*>)+ <'end'>
Protocol = <'protocol'> <_*> (Signature <_*>)+ <'end'>
_ = #'\s'
; http://tools.ietf.org/html/rfc3986#appendix-A
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
URI-reference = URI / relative-ref
absolute-URI = scheme ":" hier-part [ "?" query ]
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
authority = [ userinfo "@" ] host [ ":" port ]
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
host = IP-literal / IPv4address / reg-name
port = *DIGIT
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
h16 = 1*4HEXDIG
ls32 = ( h16 ":" h16 ) / IPv4address
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
reg-name = *( unreserved / pct-encoded / sub-delims )
path = path-abempty ; begins with "/" or is empty
/ path-absolute ; begins with "/" but not "//"
/ path-noscheme ; begins with a non-colon segment
/ path-rootless ; begins with a segment
/ path-empty ; zero characters
path-abempty = *( "/" segment )
path-absolute = "/" [ segment-nz *( "/" segment ) ]
path-noscheme = segment-nz-nc *( "/" segment )
path-rootless = segment-nz *( "/" segment )
path-empty = 0<pchar>
segment = *pchar
segment-nz = 1*pchar
segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
; non-zero-length segment without any colon ":"
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
query = *( pchar / "/" / "?" )
fragment = *( pchar / "/" / "?" )
pct-encoded = "%" HEXDIG HEXDIG
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment