1
;; This document describes TOML's syntax, using the ABNF format (defined in
2
;; RFC 5234 -- https://www.ietf.org/rfc/rfc5234.txt).
4
;; All valid TOML documents will match this description, however certain
5
;; invalid documents would need to be rejected as per the semantics described
6
;; in the supporting text description.
8
;; It is possible to try this grammar interactively, using instaparse.
9
;; http://instaparse.mojombo.com/
11
;; To do so, in the lower right, click on Options and change `:input-format` to
12
;; ':abnf'. Then paste this entire ABNF document into the grammar entry box
13
;; (above the options). Then you can type or paste a sample TOML document into
14
;; the beige box on the left. Tada!
18
toml = expression *( newline expression )
20
expression = ws [ comment ]
21
expression =/ ws keyval ws [ comment ]
22
expression =/ ws table ws [ comment ]
28
wschar =/ %x09 ; Horizontal tab
33
newline =/ %x0D.0A ; CRLF
37
comment-start-symbol = %x23 ; #
38
non-ascii = %x80-D7FF / %xE000-10FFFF
39
non-eol = %x09 / %x20-7F / non-ascii
41
comment = comment-start-symbol *non-eol
45
keyval = key keyval-sep val
47
key = simple-key / dotted-key
48
simple-key = quoted-key / unquoted-key
50
unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
51
quoted-key = basic-string / literal-string
52
dotted-key = simple-key 1*( dot-sep simple-key )
54
dot-sep = ws %x2E ws ; . Period
55
keyval-sep = ws %x3D ws ; =
57
val = string / boolean / array / inline-table / date-time / float / integer
61
string = ml-basic-string / basic-string / ml-literal-string / literal-string
65
basic-string = quotation-mark *basic-char quotation-mark
67
quotation-mark = %x22 ; "
69
basic-char = basic-unescaped / escaped
70
basic-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
71
escaped = escape escape-seq-char
74
escape-seq-char = %x22 ; " quotation mark U+0022
75
escape-seq-char =/ %x5C ; \ reverse solidus U+005C
76
escape-seq-char =/ %x62 ; b backspace U+0008
77
escape-seq-char =/ %x66 ; f form feed U+000C
78
escape-seq-char =/ %x6E ; n line feed U+000A
79
escape-seq-char =/ %x72 ; r carriage return U+000D
80
escape-seq-char =/ %x74 ; t tab U+0009
81
escape-seq-char =/ %x75 4HEXDIG ; uXXXX U+XXXX
82
escape-seq-char =/ %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX
84
;; Multiline Basic String
86
ml-basic-string = ml-basic-string-delim [ newline ] ml-basic-body
88
ml-basic-string-delim = 3quotation-mark
89
ml-basic-body = *mlb-content *( mlb-quotes 1*mlb-content ) [ mlb-quotes ]
91
mlb-content = mlb-char / newline / mlb-escaped-nl
92
mlb-char = mlb-unescaped / escaped
93
mlb-quotes = 1*2quotation-mark
94
mlb-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
95
mlb-escaped-nl = escape ws newline *( wschar / newline )
99
literal-string = apostrophe *literal-char apostrophe
101
apostrophe = %x27 ; ' apostrophe
103
literal-char = %x09 / %x20-26 / %x28-7E / non-ascii
105
;; Multiline Literal String
107
ml-literal-string = ml-literal-string-delim [ newline ] ml-literal-body
108
ml-literal-string-delim
109
ml-literal-string-delim = 3apostrophe
110
ml-literal-body = *mll-content *( mll-quotes 1*mll-content ) [ mll-quotes ]
112
mll-content = mll-char / newline
113
mll-char = %x09 / %x20-26 / %x28-7E / non-ascii
114
mll-quotes = 1*2apostrophe
118
integer = dec-int / hex-int / oct-int / bin-int
123
digit1-9 = %x31-39 ; 1-9
124
digit0-7 = %x30-37 ; 0-7
125
digit0-1 = %x30-31 ; 0-1
127
hex-prefix = %x30.78 ; 0x
128
oct-prefix = %x30.6F ; 0o
129
bin-prefix = %x30.62 ; 0b
131
dec-int = [ minus / plus ] unsigned-dec-int
132
unsigned-dec-int = DIGIT / digit1-9 1*( DIGIT / underscore DIGIT )
134
hex-int = hex-prefix HEXDIG *( HEXDIG / underscore HEXDIG )
135
oct-int = oct-prefix digit0-7 *( digit0-7 / underscore digit0-7 )
136
bin-int = bin-prefix digit0-1 *( digit0-1 / underscore digit0-1 )
140
float = float-int-part ( exp / frac [ exp ] )
141
float =/ special-float
143
float-int-part = dec-int
144
frac = decimal-point zero-prefixable-int
145
decimal-point = %x2E ; .
146
zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT )
148
exp = "e" float-exp-part
149
float-exp-part = [ minus / plus ] zero-prefixable-int
151
special-float = [ minus / plus ] ( inf / nan )
152
inf = %x69.6e.66 ; inf
153
nan = %x6e.61.6e ; nan
157
boolean = true / false
159
true = %x74.72.75.65 ; true
160
false = %x66.61.6C.73.65 ; false
162
;; Date and Time (as defined in RFC 3339)
164
date-time = offset-date-time / local-date-time / local-date / local-time
166
date-fullyear = 4DIGIT
167
date-month = 2DIGIT ; 01-12
168
date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year
169
time-delim = "T" / %x20 ; T, t, or space
170
time-hour = 2DIGIT ; 00-23
171
time-minute = 2DIGIT ; 00-59
172
time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second rules
173
time-secfrac = "." 1*DIGIT
174
time-numoffset = ( "+" / "-" ) time-hour ":" time-minute
175
time-offset = "Z" / time-numoffset
177
partial-time = time-hour ":" time-minute ":" time-second [ time-secfrac ]
178
full-date = date-fullyear "-" date-month "-" date-mday
179
full-time = partial-time time-offset
183
offset-date-time = full-date time-delim full-time
187
local-date-time = full-date time-delim partial-time
191
local-date = full-date
195
local-time = partial-time
199
array = array-open [ array-values ] ws-comment-newline array-close
202
array-close = %x5D ; ]
204
array-values = ws-comment-newline val ws-comment-newline array-sep array-values
205
array-values =/ ws-comment-newline val ws-comment-newline [ array-sep ]
207
array-sep = %x2C ; , Comma
209
ws-comment-newline = *( wschar / [ comment ] newline )
213
table = std-table / array-table
217
std-table = std-table-open key std-table-close
219
std-table-open = %x5B ws ; [ Left square bracket
220
std-table-close = ws %x5D ; ] Right square bracket
224
inline-table = inline-table-open [ inline-table-keyvals ] inline-table-close
226
inline-table-open = %x7B ws ; {
227
inline-table-close = ws %x7D ; }
228
inline-table-sep = ws %x2C ws ; , Comma
230
inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
234
array-table = array-table-open key array-table-close
236
array-table-open = %x5B.5B ws ; [[ Double left square bracket
237
array-table-close = ws %x5D.5D ; ]] Double right square bracket
239
;; Built-in ABNF terms, reproduced here for clarity
241
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
243
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"