-
Notifications
You must be signed in to change notification settings - Fork 3
/
dhall.abnf.patch
331 lines (292 loc) · 13.3 KB
/
dhall.abnf.patch
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
--- dhall-lang/standard/dhall.abnf 2018-11-24 12:47:42.310502783 +0100
+++ dhall.abnf 2018-11-24 12:56:23.450535111 +0100
@@ -110,7 +110,9 @@
block-comment-chunk =
block-comment
- / %x20-10FFFF
+ / %x20-7a
+ ; %x7b = "{"
+ / %x7c-10FFFF
/ tab
/ end-of-line
@@ -129,9 +131,9 @@
/ line-comment
/ block-comment
-whitespace = *whitespace-chunk
+whitespace = "" / whitespace whitespace-chunk
-nonempty-whitespace = 1*whitespace-chunk
+nonempty-whitespace = whitespace whitespace-chunk
; Uppercase or lowercase ASCII letter
ALPHA = %x41-5A / %x61-7A
@@ -139,9 +141,11 @@
; ASCII digit
DIGIT = %x30-39 ; 0-9
-HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
+HEXDIG = DIGIT / %x41-46 / %x61-66
-simple-label = (ALPHA / "_") *(ALPHA / DIGIT / "-" / "/" / "_")
+; simple label matches like described, but after that keywords are rejected
+; simple-label = (ALPHA / "_") *(ALPHA / DIGIT / "-" / "/" / "_")
+simple-label = "" ; placeholder
quoted-label = 1*(ALPHA / DIGIT / "-" / "/" / "_" / ":" / "." / "$")
@@ -200,7 +204,9 @@
; Printable characters except double quote and backslash
/ %x20-21
; %x22 = '"'
- / %x23-5B
+ / %x23
+ ; %x24 = "$"
+ / %x25-5B
; %x5C = "\"
/ %x5D-10FFFF
@@ -217,19 +223,14 @@
;
; If you try to end the string literal with a single quote then you get "'''",
; which is interpreted as an escaped pair of single quotes
-single-quote-continue =
- ; Escape two single quotes (i.e. replace this sequence with "''")
- "'''" single-quote-continue
- ; Interpolation
- / "${" complete-expression "}" single-quote-continue
- ; Escape interpolation (i.e. replace this sequence with "${")
- / "''${" single-quote-continue
- / "''" ; End of text literal
- / %x20-10FFFF single-quote-continue
- / tab single-quote-continue
- / end-of-line single-quote-continue
+single-quote-regular-chunk = "" ; placeholder
+single-quote-nonempty =
+ single-quote-nonempty single-quote-regular-chunk
+ / single-quote-regular-chunk
+ / single-quote-nonempty "${" complete-expression "}"
+ / "${" complete-expression "}"
-single-quote-literal = "''" single-quote-continue
+single-quote-literal = "''" single-quote-nonempty "''" / "''''"
text-literal = (double-quote-literal / single-quote-literal) whitespace
@@ -250,81 +251,10 @@
missing-raw = %x6d.69.73.73.69.6e.67
Some-raw = %x53.6f.6d.65
constructors-raw = %x63.6f.6e.73.74.72.75.63.74.6f.72.73
-Natural-fold-raw = %x4e.61.74.75.72.61.6c.2f.66.6f.6c.64
-Natural-build-raw = %x4e.61.74.75.72.61.6c.2f.62.75.69.6c.64
-Natural-isZero-raw = %x4e.61.74.75.72.61.6c.2f.69.73.5a.65.72.6f
-Natural-even-raw = %x4e.61.74.75.72.61.6c.2f.65.76.65.6e
-Natural-odd-raw = %x4e.61.74.75.72.61.6c.2f.6f.64.64
-Natural-toInteger-raw = %x4e.61.74.75.72.61.6c.2f.74.6f.49.6e.74.65.67.65.72
-Natural-show-raw = %x4e.61.74.75.72.61.6c.2f.73.68.6f.77
-Integer-toDouble-raw = %x49.6e.74.65.67.65.72.2f.74.6f.44.6f.75.62.6c.65
-Integer-show-raw = %x49.6e.74.65.67.65.72.2f.73.68.6f.77
-Double-show-raw = %x44.6f.75.62.6c.65.2f.73.68.6f.77
-List-build-raw = %x4c.69.73.74.2f.62.75.69.6c.64
-List-fold-raw = %x4c.69.73.74.2f.66.6f.6c.64
-List-length-raw = %x4c.69.73.74.2f.6c.65.6e.67.74.68
-List-head-raw = %x4c.69.73.74.2f.68.65.61.64
-List-last-raw = %x4c.69.73.74.2f.6c.61.73.74
-List-indexed-raw = %x4c.69.73.74.2f.69.6e.64.65.78.65.64
-List-reverse-raw = %x4c.69.73.74.2f.72.65.76.65.72.73.65
-Optional-fold-raw = %x4f.70.74.69.6f.6e.61.6c.2f.66.6f.6c.64
-Optional-build-raw = %x4f.70.74.69.6f.6e.61.6c.2f.62.75.69.6c.64
-Bool-raw = %x42.6f.6f.6c
Optional-raw = %x4f.70.74.69.6f.6e.61.6c
-None-raw = %x4e.6f.6e.65
-Natural-raw = %x4e.61.74.75.72.61.6c
-Integer-raw = %x49.6e.74.65.67.65.72
-Double-raw = %x44.6f.75.62.6c.65
Text-raw = %x54.65.78.74
List-raw = %x4c.69.73.74
-True-raw = %x54.72.75.65
-False-raw = %x46.61.6c.73.65
-NaN-raw = %x4e.61.4e
Infinity-raw = %x49.6e.66.69.6e.69.74.79
-Type-raw = %x54.79.70.65
-Kind-raw = %x4b.69.6e.64
-Sort-raw = %x53.6f.72.74
-
-reserved-raw =
- Bool-raw
- / Optional-raw
- / None-raw
- / Natural-raw
- / Integer-raw
- / Double-raw
- / Text-raw
- / List-raw
- / True-raw
- / False-raw
- / NaN-raw
- / Infinity-raw
- / Type-raw
- / Kind-raw
- / Sort-raw
-
-reserved-namespaced-raw =
- Natural-fold-raw
- / Natural-build-raw
- / Natural-isZero-raw
- / Natural-even-raw
- / Natural-odd-raw
- / Natural-toInteger-raw
- / Natural-show-raw
- / Integer-toDouble-raw
- / Integer-show-raw
- / Double-show-raw
- / List-build-raw
- / List-fold-raw
- / List-length-raw
- / List-head-raw
- / List-last-raw
- / List-indexed-raw
- / List-reverse-raw
- / Optional-fold-raw
- / Optional-build-raw
-
-reserved = reserved-raw whitespace
-reserved-namespaced = reserved-namespaced-raw whitespace
; Whitespaced rules for reserved words, to be used when matching expressions
if = if-raw nonempty-whitespace
@@ -383,13 +313,7 @@
natural-literal = natural-raw whitespace
-identifier = label [ at natural-raw whitespace ]
-
-identifier-reserved-prefix =
- reserved-raw 1*(ALPHA / DIGIT / "-" / "/" / "_") whitespace [ at natural-raw whitespace ]
-
-identifier-reserved-namespaced-prefix =
- reserved-namespaced-raw 1*(ALPHA / DIGIT / "-" / "/" / "_") whitespace [ at natural-raw whitespace ]
+builtin-or-identifier = label / label at natural-raw whitespace
missing = missing-raw whitespace
@@ -461,11 +385,12 @@
http-raw = scheme "://" authority directory file [ "?" query ] [ "#" fragment ]
; NOTE: Backtrack if parsing the optional user info prefix fails
-authority = [ userinfo "@" ] host [ ":" port ]
-
-userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
+authority = [ userinfo "@" ] IP-literal [ ":" port ]
+ / userinfo "@" userinfo userinfo-char
+ / userinfo userinfo-char
-host = IP-literal / IPv4address / reg-name
+userinfo-char = unreserved / pct-encoded / sub-delims / ":"
+userinfo = userinfo userinfo-char / ""
port = *DIGIT
@@ -497,8 +422,6 @@
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
-reg-name = *( unreserved / pct-encoded / sub-delims )
-
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
query = *( pchar / "/" / "?" )
@@ -620,7 +543,8 @@
annotated-expression =
; "merge e1 e2 : t"
; "merge e1 e2"
- merge import-expression import-expression [ colon application-expression ]
+ merge import-expression import-expression
+ / merge import-expression import-expression colon application-expression
; "[] : List t"
; "[] : Optional t"
@@ -629,35 +553,34 @@
; NOTE: Backtrack if parsing this alternative fails since we can't tell
; from the opening bracket whether or not this will be an empty list or
; non-empty list
- / open-bracket (empty-collection / non-empty-optional)
+ / open-bracket close-bracket colon List import-expression
+ / open-bracket close-bracket colon Optional import-expression
+ / open-bracket expression close-bracket colon Optional import-expression
; "x : t"
- / operator-expression (colon expression / "")
-
-empty-collection = close-bracket colon (List / Optional) import-expression
-
-non-empty-optional = expression close-bracket colon Optional import-expression
+ / operator-expression colon expression
+ / operator-expression
operator-expression = import-alt-expression
-import-alt-expression = or-expression *(import-alt or-expression)
-or-expression = plus-expression *(or plus-expression )
-plus-expression = text-append-expression *(plus text-append-expression )
-text-append-expression = list-append-expression *(text-append list-append-expression )
-list-append-expression = and-expression *(list-append and-expression )
-and-expression = combine-expression *(and combine-expression )
-combine-expression = prefer-expression *(combine prefer-expression )
-prefer-expression = combine-types-expression *(prefer combine-types-expression)
-combine-types-expression = times-expression *(combine-types times-expression )
-times-expression = equal-expression *(times equal-expression )
-equal-expression = not-equal-expression *(double-equal not-equal-expression )
-not-equal-expression = application-expression *(not-equal application-expression )
+import-alt-expression = or-expression / import-alt-expression import-alt or-expression
+or-expression = plus-expression / or-expression or plus-expression
+plus-expression = text-append-expression / plus-expression plus text-append-expression
+text-append-expression = list-append-expression / text-append-expression text-append list-append-expression
+list-append-expression = and-expression / list-append-expression list-append and-expression
+and-expression = combine-expression / and-expression and combine-expression
+combine-expression = prefer-expression / combine-expression combine prefer-expression
+prefer-expression = combine-types-expression / prefer-expression prefer combine-types-expression
+combine-types-expression = times-expression / combine-types-expression combine-types times-expression
+times-expression = equal-expression / times-expression times equal-expression
+equal-expression = not-equal-expression / equal-expression double-equal not-equal-expression
+not-equal-expression = constructors-or-some-expression / not-equal-expression not-equal constructors-or-some-expression
; Import expressions need to be separated by some whitespace, otherwise there
; would be ambiguity: `./ab` could be interpreted as "import the file `./ab`",
; or "apply the import `./a` to label `b`"
-application-expression =
- [ constructors / Some ] import-expression *(whitespace-chunk import-expression)
+constructors-or-some-expression = [ constructors / Some ] application-expression
+application-expression = import-expression / application-expression whitespace-chunk import-expression
import-expression = import / selector-expression
@@ -669,7 +592,10 @@
; can't tell from parsing just the period whether "foo." will become "foo.bar"
; (i.e. accessing field `bar` of the record `foo`) or `foo./bar` (i.e. applying
; the function `foo` to the relative path `./bar`)
-selector-expression = primitive-expression *(dot ( label / labels ))
+selector-expression = primitive-expression
+ / selector-expression dot label
+ / selector-expression dot open-brace close-brace
+ / selector-expression dot open-brace label *(comma label) close-brace
; NOTE: Backtrack when parsing the first three alternatives (i.e. the numeric
; literals). This is because they share leading characters in common
@@ -709,48 +635,26 @@
; "[1, 2, 3]"
/ non-empty-list-literal ; `annotated-expression` handles empty lists
- ; "List/foldWith"
- / identifier-reserved-namespaced-prefix
-
- ; "List/head"
- / reserved-namespaced
-
- ; "List/map"
- ; "TypeDefinition"
- / identifier-reserved-prefix
-
- ; "List"
- / reserved
-
; "x"
; "x@2"
- / identifier
+ / builtin-or-identifier
; "( e )"
/ open-parens expression close-parens
-labels = open-brace ( label *(comma label) / "" ) close-brace
-
record-type-or-literal =
equal ; Empty record literal
- / non-empty-record-type-or-literal
/ "" ; Empty record type
-
-non-empty-record-type-or-literal =
- label (non-empty-record-literal / non-empty-record-type)
-
-non-empty-record-type = colon expression *(comma label colon expression)
-non-empty-record-literal = equal expression *(comma label equal expression)
+ / label colon expression *(comma label colon expression) ; nonempty record type
+ / label equal expression *(comma label equal expression) ; nonempty record literal
union-type-or-literal =
non-empty-union-type-or-literal
/ "" ; Empty union type
non-empty-union-type-or-literal =
- label
- ( equal expression *(bar label colon expression)
- / colon expression (bar non-empty-union-type-or-literal / "")
- )
+ label equal expression *(bar label colon expression)
+ / label colon expression (bar non-empty-union-type-or-literal / "")
non-empty-list-literal = open-bracket expression *(comma expression) close-bracket