-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoml-schema.abnf
217 lines (157 loc) · 6.83 KB
/
toml-schema.abnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
;; TOML Schema Document Grammar and Structure
;; Author: Bruno Borges
;; Overall Structure
;; Test with http://instaparse.mojombo.com/
toml-schema = ws-comment-newline 1toml-schema-table ws-comment-newline 0*1types-table ws-comment-newline 1elements-table
toml-schema-table = table-open "toml-schema" table-close ws-comment-newline version
types-table = table-open "types" table-close ws-comment-newline 0*elementdef
elements-table = table-open "elements" table-close ws-comment-newline 0*elementdef
;; Built-in properties
version = ws "version" keyval-sep integer ws-comment-newline
type = ws "type" keyval-sep built-in-type ws-comment-newline
typeref = ws "typeref" keyval-sep basic-string ws-comment-newline
arraytype = ws "arraytype" keyval-sep built-in-type ws-comment-newline
optional = ws "optional" keyval-sep boolean ws-comment-newline
default = ws "default" keyval-sep val ws-comment-newline
minlength = ws "minlength" keyval-sep integer ws-comment-newline
maxlength = ws "maxlength" keyval-sep integer ws-comment-newline
minoccurs = ws "minoccurs" keyval-sep integer ws-comment-newline
maxoccurs = ws "maxoccurs" keyval-sep integer ws-comment-newline
pattern = ws "pattern" keyval-sep basic-string ws-comment-newline
allowedvalues = ws "allowedvalues" keyval-sep array ws-comment-newline
elementdef = table ws-comment-newline
[ type ws-comment-newline ]
[ typeref ws-comment-newline ]
[ arraytype ws-comment-newline ]
[ optional ws-comment-newline ]
[ default ws-comment-newline ]
[ minlength ws-comment-newline ]
[ maxlength ws-comment-newline ]
[ minoccurs ws-comment-newline ]
[ maxoccurs ws-comment-newline ]
[ pattern ws-comment-newline ]
[ allowedvalues ws-comment-newline ]
[ ws-comment-newline ]
;; Whitespace
ws = *wschar
wschar = %x20 ; Space
wschar =/ %x09 ; Horizontal tab
;; Newline
newline = %x0A ; LF
newline =/ %x0D.0A ; CRLF
;; Comment
comment-start-symbol = %x23 ; #
non-ascii = %x80-D7FF / %xE000-10FFFF
non-eol = %x09 / %x20-7F / non-ascii
comment = comment-start-symbol *non-eol
comments = *( newline ws [ comment ] )
;; Key-Value pairs
keyval = key keyval-sep val
key = simple-key / dotted-key
simple-key = quoted-key / unquoted-key
unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
quoted-key = basic-string / literal-string
dotted-key = simple-key 1*( dot-sep simple-key )
dot-sep = ws %x2E ws ; . Period
keyval-sep = ws %x3D ws ; =
val = string / boolean / array / integer / float
;; String
string = basic-string / ml-literal-string / literal-string
;; Basic String
basic-string = quotation-mark *basic-char quotation-mark
quotation-mark = %x22 ; "
basic-char = basic-unescaped / escaped
basic-unescaped = wschar / %x21 / %x23-5B / %x5D-7E / non-ascii
escaped = escape escape-seq-char
escape = %x5C ; \
escape-seq-char = %x22 ; " quotation mark U+0022
escape-seq-char =/ %x5C ; \ reverse solidus U+005C
escape-seq-char =/ %x62 ; b backspace U+0008
escape-seq-char =/ %x66 ; f form feed U+000C
escape-seq-char =/ %x6E ; n line feed U+000A
escape-seq-char =/ %x72 ; r carriage return U+000D
escape-seq-char =/ %x74 ; t tab U+0009
escape-seq-char =/ %x75 4HEXDIG ; uXXXX U+XXXX
escape-seq-char =/ %x55 8HEXDIG ; UXXXXXXXX U+XXXXXXXX
;; Literal String
literal-string = apostrophe *literal-char apostrophe
apostrophe = %x27 ; ' apostrophe
literal-char = %x09 / %x20-26 / %x28-7E / non-ascii
;; Integer
integer = dec-int
minus = %x2D ; -
plus = %x2B ; +
underscore = %x5F ; _
digit1-9 = %x31-39 ; 1-9
digit0-7 = %x30-37 ; 0-7
digit0-1 = %x30-31 ; 0-1
dec-int = [ minus ] unsigned-dec-int
unsigned-dec-int = DIGIT / digit1-9 1*( DIGIT / underscore DIGIT )
;; Float
float = float-int-part ( exp / frac [ exp ] )
float =/ special-float
float-int-part = dec-int
frac = decimal-point zero-prefixable-int
decimal-point = %x2E ; .
zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT )
exp = "e" float-exp-part
float-exp-part = [ minus / plus ] zero-prefixable-int
special-float = [ minus / plus ] ( inf / nan )
inf = %x69.6e.66 ; inf
nan = %x6e.61.6e ; nan
;; Built-in Types
built-in-type = anytype
built-in-type =/ stringtype
built-in-type =/ integertype
built-in-type =/ floattype
built-in-type =/ booleantype
built-in-type =/ localdatetype
built-in-type =/ localtimetype
built-in-type =/ localdatetimetype
built-in-type =/ offsetdatetimetype
built-in-type =/ arraytype
built-in-type =/ tabletype
;; built-in-type =/ inlinetabletype
built-in-type =/ tablecollectiontype
;; Simple Types
anytype = %x61.6e.79 ; any
stringtype = %x73.74.72.69.6e.67 ; string
integertype = %x69.6e.74.65.67.65.72 ; integer
floattype = %x66.6c.6f.61.74 ; float
booleantype = %x62.6f.6f.6c.65.61.6e ; boolean
localdatetype = %x6c.6f.63.61.6c.2d.64.61.74.65 ; local-date
localtimetype = %x6c.6f.63.61.6c.2d.74.69.6d.65 ; local-time
localdatetimetype = %x6c.6f.63.61.6c.2d.64.61.74.65.2d.74.69.6d.65 ; local-date-time
offsetdatetimetype = %x6f.66.66.73.65.74.2d.64.61.74.65.2d.74.69.6d.65 ; offset-date-time
;; Block Types
arraytype = %x61.72.72.61.79 ; array
tabletype = %x74.61.62.6c.65 ; table
;; inlinetabletype = %x69.6e.6c.69.6e.65.2d.74.61.62.6c.65 ; inline-table
tablecollectiontype = %x74.61.62.6c.65.2d.63.6f.6c.6c.65.63.74.69.6f.6e ; table-collection
;; Boolean
boolean = true / false
true = %x74.72.75.65 ; true
false = %x66.61.6C.73.65 ; false
;; Array
array = array-open [ array-values ] ws-comment-newline array-close
array-open = %x5B ; [
array-close = %x5D ; ]
array-values = ws-comment-newline val ws-comment-newline array-sep array-values
array-values =/ ws-comment-newline val ws-comment-newline [ array-sep ]
array-sep = %x2C ; , Comma
ws-comment-newline = *( wschar / [ comment ] newline )
;; Table
table = table-open key table-close
table-open = %x5B ws ; [ Left square bracket
table-close = ws %x5D ; ] Right square bracket
;; Multiline Literal String
ml-literal-string = ml-literal-string-delim ml-literal-body ml-literal-string-delim
ml-literal-string-delim = 3apostrophe
ml-literal-body = *mll-content *( mll-quotes 1*mll-content ) [ mll-quotes ]
mll-content = mll-char / newline
mll-char = %x09 / %x20-26 / %x28-7E / non-ascii
mll-quotes = 1*2apostrophe
;; Built-in ABNF terms, reproduced here for clarity
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"