1 ;; WARNING: This document is a work-in-progress and should not be considered
2 ;; authoritative until further notice.
4 ;; This is an attempt to define TOML in ABNF according to the grammar defined
5 ;; in RFC 5234 (http://www.ietf.org/rfc/rfc5234.txt).
7 ;; You can try out this grammar using http://instaparse.mojombo.com/
8 ;; To do so, in the lower right, click on Options and change `:input-format` to
9 ;; ':abnf'. Then paste this entire ABNF document into the grammar entry box
10 ;; (above the options). Then you can type or paste a sample TOML document into
11 ;; the beige box on the left. Tada!
15 toml = expression *( newline expression )
17 expression = ws [ comment ]
18 expression =/ ws keyval ws [ comment ]
19 expression =/ ws table ws [ comment ]
25 wschar =/ %x09 ; Horizontal tab
30 newline =/ %x0D.0A ; CRLF
34 comment-start-symbol = %x23 ; #
35 non-ascii = %x80-D7FF / %xE000-10FFFF
36 non-eol = %x09 / %x20-7F / non-ascii
38 comment = comment-start-symbol *non-eol
42 keyval = key keyval-sep val
44 key = simple-key / dotted-key
45 simple-key = quoted-key / unquoted-key
47 unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
48 quoted-key = basic-string / literal-string
49 dotted-key = simple-key 1*( dot-sep simple-key )
51 dot-sep = ws %x2E ws ; . Period
52 keyval-sep = ws %x3D ws ; =
54 val = string / boolean / array / inline-table / date-time / float / integer
58 string = ml-basic-string / basic-string / ml-literal-string / literal-string
62 basic-string = quotation-mark *basic-char quotation-mark
64 quotation-mark = %x22 ; "
66 basic-char = basic-unescaped / escaped
67 basic-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
68 escaped = escape escape-seq-char
71 escape-seq-char = %x22 ; " quotation mark U+0022
72 escape-seq-char =/ %x5C ; \ reverse solidus U+005C
73 escape-seq-char =/ %x62 ; b backspace U+0008
74 escape-seq-char =/ %x66 ; f form feed U+000C
75 escape-seq-char =/ %x6E ; n line feed U+000A
76 escape-seq-char =/ %x72 ; r carriage return U+000D
77 escape-seq-char =/ %x74 ; t tab U+0009
78 escape-seq-char =/ %x75 4HEXDIG ; uXXXX U+XXXX
79 escape-seq-char =/ %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX
81 ;; Multiline Basic String
83 ml-basic-string = ml-basic-string-delim ml-basic-body ml-basic-string-delim
84 ml-basic-string-delim = 3quotation-mark
85 ml-basic-body = *mlb-content *( mlb-quotes 1*mlb-content ) [ mlb-quotes ]
87 mlb-content = mlb-char / newline / mlb-escaped-nl
88 mlb-char = mlb-unescaped / escaped
89 mlb-quotes = 1*2quotation-mark
90 mlb-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
91 mlb-escaped-nl = escape ws newline *( wschar / newline )
95 literal-string = apostrophe *literal-char apostrophe
97 apostrophe = %x27 ; ' apostrophe
99 literal-char = %x09 / %x20-26 / %x28-7E / non-ascii
101 ;; Multiline Literal String
103 ml-literal-string = ml-literal-string-delim ml-literal-body ml-literal-string-delim
104 ml-literal-string-delim = 3apostrophe
105 ml-literal-body = *mll-content *( mll-quotes 1*mll-content ) [ mll-quotes ]
107 mll-content = mll-char / newline
108 mll-char = %x09 / %x20-26 / %x28-7E / non-ascii
109 mll-quotes = 1*2apostrophe
113 integer = dec-int / hex-int / oct-int / bin-int
117 underscore = %x5F ; _
118 digit1-9 = %x31-39 ; 1-9
119 digit0-7 = %x30-37 ; 0-7
120 digit0-1 = %x30-31 ; 0-1
122 hex-prefix = %x30.78 ; 0x
123 oct-prefix = %x30.6f ; 0o
124 bin-prefix = %x30.62 ; 0b
126 dec-int = [ minus / plus ] unsigned-dec-int
127 unsigned-dec-int = DIGIT / digit1-9 1*( DIGIT / underscore DIGIT )
129 hex-int = hex-prefix HEXDIG *( HEXDIG / underscore HEXDIG )
130 oct-int = oct-prefix digit0-7 *( digit0-7 / underscore digit0-7 )
131 bin-int = bin-prefix digit0-1 *( digit0-1 / underscore digit0-1 )
135 float = float-int-part ( exp / frac [ exp ] )
136 float =/ special-float
138 float-int-part = dec-int
139 frac = decimal-point zero-prefixable-int
140 decimal-point = %x2E ; .
141 zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT )
143 exp = "e" float-exp-part
144 float-exp-part = [ minus / plus ] zero-prefixable-int
146 special-float = [ minus / plus ] ( inf / nan )
147 inf = %x69.6e.66 ; inf
148 nan = %x6e.61.6e ; nan
152 boolean = true / false
154 true = %x74.72.75.65 ; true
155 false = %x66.61.6C.73.65 ; false
157 ;; Date and Time (as defined in RFC 3339)
159 date-time = offset-date-time / local-date-time / local-date / local-time
161 date-fullyear = 4DIGIT
162 date-month = 2DIGIT ; 01-12
163 date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year
164 time-delim = "T" / %x20 ; T, t, or space
165 time-hour = 2DIGIT ; 00-23
166 time-minute = 2DIGIT ; 00-59
167 time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second rules
168 time-secfrac = "." 1*DIGIT
169 time-numoffset = ( "+" / "-" ) time-hour ":" time-minute
170 time-offset = "Z" / time-numoffset
172 partial-time = time-hour ":" time-minute ":" time-second [ time-secfrac ]
173 full-date = date-fullyear "-" date-month "-" date-mday
174 full-time = partial-time time-offset
178 offset-date-time = full-date time-delim full-time
182 local-date-time = full-date time-delim partial-time
186 local-date = full-date
190 local-time = partial-time
194 array = array-open [ array-values ] ws-comment-newline array-close
196 array-open = %x5B ; [
197 array-close = %x5D ; ]
199 array-values = ws-comment-newline val ws array-sep array-values
200 array-values =/ ws-comment-newline val ws [ array-sep ]
202 array-sep = %x2C ; , Comma
204 ws-comment-newline = *( wschar / [ comment ] newline )
208 table = std-table / array-table
212 std-table = std-table-open key std-table-close
214 std-table-open = %x5B ws ; [ Left square bracket
215 std-table-close = ws %x5D ; ] Right square bracket
219 inline-table = inline-table-open [ inline-table-keyvals ] inline-table-close
221 inline-table-open = %x7B ws ; {
222 inline-table-close = ws %x7D ; }
223 inline-table-sep = ws %x2C ws ; , Comma
225 inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
229 array-table = array-table-open key array-table-close
231 array-table-open = %x5B.5B ws ; [[ Double left square bracket
232 array-table-close = ws %x5D.5D ; ]] Double right square bracket
234 ;; Built-in ABNF terms, reproduced here for clarity
236 ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
237 DIGIT = %x30-39 ; 0-9
238 HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"