dhall 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,420 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dhall/builtins"
4
+ require "dhall/visitor"
5
+ require "dhall/util"
6
+
7
+ module Dhall
8
+ module ExpressionVisitor
9
+ ExpressionHash = Util::HashOf.new(
10
+ ValueSemantics::Anything,
11
+ ValueSemantics::Either.new([Expression, nil])
12
+ )
13
+
14
+ def self.new(&block)
15
+ Visitor.new(
16
+ Expression => block,
17
+ Util::ArrayOf.new(Expression) => lambda do |x|
18
+ x.map(&block)
19
+ end,
20
+ ExpressionHash => lambda do |x|
21
+ Hash[x.map { |k, v| [k, v.nil? ? v : block[v]] }.sort]
22
+ end
23
+ )
24
+ end
25
+ end
26
+
27
+ class Expression
28
+ def normalize
29
+ with(ExpressionVisitor.new(&:normalize).visit(self))
30
+ end
31
+
32
+ def shift(amount, name, min_index)
33
+ with(ExpressionVisitor.new { |expr|
34
+ expr.shift(amount, name, min_index)
35
+ }.visit(self))
36
+ end
37
+
38
+ def substitute(var, with_expr)
39
+ with(ExpressionVisitor.new { |expr|
40
+ expr.substitute(var, with_expr)
41
+ }.visit(self))
42
+ end
43
+
44
+ def fusion(*); end
45
+ end
46
+
47
+ class Application
48
+ def normalize
49
+ return fuse.normalize if fuse
50
+
51
+ normalized = super
52
+ return normalized.fuse if normalized.fuse
53
+
54
+ if normalized.function.is_a?(Builtin) ||
55
+ normalized.function.is_a?(Function) ||
56
+ normalized.function.is_a?(RecordSelection)
57
+ return normalized.function.call(normalized.argument)
58
+ end
59
+
60
+ normalized
61
+ end
62
+
63
+ def fuse
64
+ if function.is_a?(Application)
65
+ @fuse ||= function.function.fusion(function.argument, argument)
66
+ return @fuse if @fuse
67
+ end
68
+
69
+ @fuse ||= function.fusion(argument)
70
+ end
71
+ end
72
+
73
+ class Function
74
+ @@alpha_normalization = true
75
+
76
+ def self.disable_alpha_normalization!
77
+ @@alpha_normalization = false
78
+ end
79
+
80
+ def self.enable_alpha_normalization!
81
+ @@alpha_normalization = true
82
+ end
83
+
84
+ def shift(amount, name, min_index)
85
+ return super unless var == name
86
+
87
+ with(
88
+ type: type.shift(amount, name, min_index),
89
+ body: body.shift(amount, name, min_index + 1)
90
+ )
91
+ end
92
+
93
+ def substitute(svar, with_expr)
94
+ with(
95
+ type: type&.substitute(svar, with_expr),
96
+ body: body.substitute(
97
+ var == svar.name ? svar.with(index: svar.index + 1) : svar,
98
+ with_expr.shift(1, var, 0)
99
+ )
100
+ )
101
+ end
102
+
103
+ def normalize
104
+ return super unless alpha_normalize?
105
+ with(
106
+ var: "_",
107
+ type: type&.normalize,
108
+ body: body
109
+ .shift(1, "_", 0)
110
+ .substitute(Variable[var], Variable["_"])
111
+ .shift(-1, var, 0)
112
+ .normalize
113
+ )
114
+ end
115
+
116
+ protected
117
+
118
+ def alpha_normalize?
119
+ var != "_" && @@alpha_normalization
120
+ end
121
+ end
122
+
123
+ class Forall; end
124
+
125
+ class Bool
126
+ end
127
+
128
+ class Variable
129
+ def shift(amount, name, min_index)
130
+ return self if self.name != name || min_index > index
131
+
132
+ with(index: index + amount)
133
+ end
134
+
135
+ def substitute(var, with_expr)
136
+ self == var ? with_expr : self
137
+ end
138
+ end
139
+
140
+ class Operator
141
+ class Or
142
+ def normalize
143
+ lhs.normalize | rhs.normalize
144
+ end
145
+ end
146
+
147
+ class And
148
+ def normalize
149
+ lhs.normalize & rhs.normalize
150
+ end
151
+ end
152
+
153
+ class Equal
154
+ def normalize
155
+ lhs.normalize.dhall_eq(rhs.normalize)
156
+ end
157
+ end
158
+
159
+ class NotEqual
160
+ def normalize
161
+ normalized = super
162
+ if normalized.lhs == Bool.new(value: false)
163
+ normalized.rhs
164
+ elsif normalized.rhs == Bool.new(value: false)
165
+ normalized.lhs
166
+ elsif normalized.lhs == normalized.rhs
167
+ Bool.new(value: false)
168
+ else
169
+ normalized
170
+ end
171
+ end
172
+ end
173
+
174
+ class Plus
175
+ def normalize
176
+ normalized = super
177
+ if normalized.lhs == Natural.new(value: 0)
178
+ normalized.rhs
179
+ elsif normalized.rhs == Natural.new(value: 0)
180
+ normalized.lhs
181
+ else
182
+ normalized.lhs + normalized.rhs
183
+ end
184
+ end
185
+ end
186
+
187
+ class Times
188
+ def normalize
189
+ normalized = super
190
+ if normalized.lhs == Natural.new(value: 1)
191
+ normalized.rhs
192
+ elsif normalized.rhs == Natural.new(value: 1)
193
+ normalized.lhs
194
+ else
195
+ normalized.lhs * normalized.rhs
196
+ end
197
+ end
198
+ end
199
+
200
+ class TextConcatenate
201
+ def normalize
202
+ normalized = super
203
+ if normalized.lhs == Text.new(value: "")
204
+ normalized.rhs
205
+ elsif normalized.rhs == Text.new(value: "")
206
+ normalized.lhs
207
+ else
208
+ normalized.lhs << normalized.rhs
209
+ end
210
+ end
211
+ end
212
+
213
+ class ListConcatenate
214
+ def normalize
215
+ normalized = super
216
+ case normalized.rhs
217
+ when EmptyList
218
+ normalized.lhs
219
+ else
220
+ normalized.lhs.concat(normalized.rhs)
221
+ end
222
+ end
223
+ end
224
+
225
+ class RecursiveRecordMerge
226
+ def normalize
227
+ lhs.normalize.deep_merge(rhs.normalize)
228
+ end
229
+ end
230
+
231
+ class RightBiasedRecordMerge
232
+ def normalize
233
+ lhs.normalize.merge(rhs.normalize)
234
+ end
235
+ end
236
+
237
+ class RecursiveRecordTypeMerge
238
+ def normalize
239
+ lhs.normalize.deep_merge_type(rhs.normalize)
240
+ end
241
+ end
242
+ end
243
+
244
+ class EmptyList
245
+ def normalize
246
+ super.with(element_type: element_type.normalize)
247
+ end
248
+ end
249
+
250
+ class Optional
251
+ def normalize
252
+ with(
253
+ value: value.normalize,
254
+ value_type: value_type&.normalize,
255
+ normalized: true
256
+ )
257
+ end
258
+ end
259
+
260
+ class OptionalNone
261
+ def normalize
262
+ with(value_type: value_type.normalize)
263
+ end
264
+ end
265
+
266
+ class Merge
267
+ def normalize
268
+ normalized = super
269
+ if normalized.record.is_a?(Record) && normalized.input.is_a?(Union)
270
+ fetched = normalized.record.fetch(normalized.input.tag)
271
+ value = normalized.input.value
272
+ value.nil? ? fetched : fetched.call(value)
273
+ else
274
+ normalized
275
+ end
276
+ end
277
+ end
278
+
279
+ class Record
280
+ def normalize
281
+ with(record: Hash[
282
+ record.map { |k, v| [k, v.nil? ? v : v.normalize] }.sort
283
+ ])
284
+ end
285
+
286
+ def shift(amount, name, min_index)
287
+ with(record: Hash[
288
+ record.map { |k, v|
289
+ [k, v.nil? ? v : v.shift(amount, name, min_index)]
290
+ }.sort
291
+ ])
292
+ end
293
+
294
+ def substitute(var, with_expr)
295
+ with(record: Hash[
296
+ record.map { |k, v|
297
+ [k, v.nil? ? v : v.substitute(var, with_expr)]
298
+ }.sort
299
+ ])
300
+ end
301
+ end
302
+
303
+ class EmptyRecord
304
+ def normalize
305
+ self
306
+ end
307
+ end
308
+
309
+ class RecordSelection
310
+ def normalize
311
+ record.normalize.fetch(selector)
312
+ end
313
+ end
314
+
315
+ class RecordProjection
316
+ def normalize
317
+ record.normalize.slice(*selectors)
318
+ end
319
+ end
320
+
321
+ class EmptyRecordProjection
322
+ def normalize
323
+ EmptyRecord.new
324
+ end
325
+ end
326
+
327
+ class UnionType
328
+ def normalize
329
+ with(alternatives: Hash[super.alternatives.sort])
330
+ end
331
+ end
332
+
333
+ class Union
334
+ def normalize
335
+ val = if value.is_a?(TypeAnnotation)
336
+ value.with(ExpressionVisitor.new(&:normalize).visit(value))
337
+ else
338
+ value&.normalize
339
+ end
340
+
341
+ with(value: val, alternatives: alternatives.normalize)
342
+ end
343
+ end
344
+
345
+ class If
346
+ def normalize
347
+ normalized = super
348
+ if normalized.predicate.is_a?(Bool)
349
+ normalized.predicate.reduce(normalized.then, normalized.else)
350
+ elsif normalized.trivial?
351
+ normalized.predicate
352
+ elsif normalized.then == normalized.else
353
+ normalized.then
354
+ else
355
+ normalized
356
+ end
357
+ end
358
+
359
+ def trivial?
360
+ self.then == Bool.new(value: true) &&
361
+ self.else == Bool.new(value: false)
362
+ end
363
+ end
364
+
365
+ class Number
366
+ end
367
+
368
+ class Natural; end
369
+ class Integer; end
370
+ class Double; end
371
+
372
+ class Text
373
+ end
374
+
375
+ class TextLiteral
376
+ def normalize
377
+ TextLiteral.for(*super.flatten.chunks)
378
+ end
379
+
380
+ def flatten
381
+ with(chunks: chunks.flat_map do |chunk|
382
+ chunk.is_a?(TextLiteral) ? chunk.chunks : chunk
383
+ end)
384
+ end
385
+ end
386
+
387
+ class Import
388
+ end
389
+
390
+ class LetIn
391
+ def normalize
392
+ desugar.normalize
393
+ end
394
+
395
+ def shift(amount, name, min_index)
396
+ return super unless let.var == name
397
+
398
+ with(
399
+ let: let.shift(amount, name, min_index),
400
+ body: body.shift(amount, name, min_index + 1)
401
+ )
402
+ end
403
+ end
404
+
405
+ class LetBlock
406
+ def normalize
407
+ desugar.normalize
408
+ end
409
+
410
+ def shift(amount, name, min_index)
411
+ unflatten.shift(amount, name, min_index)
412
+ end
413
+ end
414
+
415
+ class TypeAnnotation
416
+ def normalize
417
+ value.normalize
418
+ end
419
+ end
420
+ end
@@ -0,0 +1,500 @@
1
+ grammar Dhall::Parser::CitrusParser
2
+ root complete_expression
3
+ rule end_of_line
4
+ (/\n/i | (/(?:\r)(?:\n)/i))
5
+ end
6
+ rule tab
7
+ (/\t/i)
8
+ end
9
+ rule block_comment
10
+ (/(?:\u{7b})(?:\u{2d})/i (block_comment_continue))
11
+ end
12
+ rule block_comment_chunk
13
+ ((block_comment) | /[\u{20}-@\u{5b}-\u{10ffff}]/i | (tab) | (end_of_line))
14
+ end
15
+ rule block_comment_continue
16
+ ((/(?:\u{2d})(?:\u{7d})/i) | ((block_comment_chunk) (block_comment_continue)))
17
+ end
18
+ rule not_end_of_line
19
+ (/[\u{20}-@\u{5b}-\u{10ffff}]/i | (tab))
20
+ end
21
+ rule line_comment
22
+ (/(?:\u{2d})(?:\u{2d})/i ((not_end_of_line)*) (end_of_line))
23
+ end
24
+ rule whitespace_chunk
25
+ (/\u{20}/i | (tab) | (end_of_line) | (line_comment) | (block_comment))
26
+ end
27
+ rule whsp
28
+ ((whitespace_chunk)*)
29
+ end
30
+ rule whsp1
31
+ ((whitespace_chunk)+)
32
+ end
33
+ rule alpha
34
+ (/[a-z]/i)
35
+ end
36
+ rule digit
37
+ (/\d/i)
38
+ end
39
+ rule hexdig
40
+ ((digit) | /[a-f]/i | (digit) | /[a-f]/i)
41
+ end
42
+ rule simple_label_first_char
43
+ ((alpha) | `_`)
44
+ end
45
+ rule simple_label_next_char
46
+ ((alpha) | (digit) | /[\u{2d}\/_]/i)
47
+ end
48
+ rule simple_label
49
+ (keyword simple_label_next_char+ | !keyword (simple_label_first_char simple_label_next_char*))
50
+ end
51
+ rule quoted_label_char
52
+ (/[\u{20}-@\u{5b}-_a-~]/i)
53
+ end
54
+ rule quoted_label
55
+ ((quoted_label_char)+)
56
+ end
57
+ rule label
58
+ ((/`/i (quoted_label) /`/i) | (simple_label)) <Dhall::Parser::Label>
59
+ end
60
+ rule nonreserved_label
61
+ (reserved_identifier simple_label_next_char+ | !reserved_identifier label) <Dhall::Parser::NonreservedLabel>
62
+ end
63
+ rule any_label
64
+ (label)
65
+ end
66
+ rule double_quote_chunk
67
+ ((interpolation) | (/\u{5c}/i (double_quote_escaped)) | (double_quote_char)) <Dhall::Parser::DoubleQuoteChunk>
68
+ end
69
+ rule double_quote_escaped
70
+ (/["\u{24}\/\u{5c}bfnrt]/ | ("u" ((hexdig) 4*4))) <Dhall::Parser::DoubleQuoteEscaped>
71
+ end
72
+ rule double_quote_char
73
+ (/[\u{20}!\u{23}-@\u{5b}\u{5d}-\u{10ffff}]/i)
74
+ end
75
+ rule double_quote_literal
76
+ (/"/i ((double_quote_chunk)*) /"/i) <Dhall::Parser::DoubleQuoteLiteral>
77
+ end
78
+ rule single_quote_continue
79
+ (((interpolation) (single_quote_continue)) | ((escaped_quote_pair) (single_quote_continue)) | ((escaped_interpolation) (single_quote_continue)) | ((single_quote_char) (single_quote_continue)) | (`''`)) <Dhall::Parser::SingleQuoteContinue>
80
+ end
81
+ rule escaped_quote_pair
82
+ (`'''`) <Dhall::Parser::EscapedQuotePair>
83
+ end
84
+ rule escaped_interpolation
85
+ (/(?:''(?:\u{24}))(?:\u{7b})/i) <Dhall::Parser::EscapedInterpolation>
86
+ end
87
+ rule single_quote_char
88
+ (/[\u{20}-@\u{5b}-\u{10ffff}]/i | (tab) | (end_of_line))
89
+ end
90
+ rule single_quote_literal
91
+ (`''` (end_of_line) (single_quote_continue)) <Dhall::Parser::SingleQuoteLiteral>
92
+ end
93
+ rule interpolation
94
+ (/(?:\u{24})(?:\u{7b})/i (complete_expression) /\u{7d}/i) <Dhall::Parser::Interpolation>
95
+ end
96
+ rule text_literal
97
+ ((double_quote_literal) | (single_quote_literal))
98
+ end
99
+ rule if
100
+ ("if")
101
+ end
102
+ rule then
103
+ ("then")
104
+ end
105
+ rule else
106
+ ("else")
107
+ end
108
+ rule let
109
+ ("let")
110
+ end
111
+ rule in
112
+ ("in")
113
+ end
114
+ rule as
115
+ ("as")
116
+ end
117
+ rule using
118
+ ("using")
119
+ end
120
+ rule merge
121
+ ("merge")
122
+ end
123
+ rule missing
124
+ ("missing") <Dhall::Parser::Missing>
125
+ end
126
+ rule infinity
127
+ ("Infinity")
128
+ end
129
+ rule nan
130
+ ("NaN") <Dhall::Parser::Nan>
131
+ end
132
+ rule some
133
+ ("Some")
134
+ end
135
+ rule keyword
136
+ ((if) | (then) | (else) | (let) | (in) | (using) | (missing) | (as) | (infinity) | (nan) | (merge) | (some))
137
+ end
138
+ rule optional
139
+ ("Optional")
140
+ end
141
+ rule text
142
+ ("Text")
143
+ end
144
+ rule list
145
+ ("List")
146
+ end
147
+ rule combine
148
+ (/\u{2227}/i | (/(?:\/)(?:\u{5c})/i))
149
+ end
150
+ rule combine_types
151
+ (/\u{2a53}/i | (/(?:(?:(?:\/)(?:\/))(?:\u{5c}))(?:\u{5c})/i))
152
+ end
153
+ rule prefer
154
+ (/\u{2afd}/i | (/(?:\/)(?:\/)/i))
155
+ end
156
+ rule lambda
157
+ (/[\u{5c}\u{3bb}]/i)
158
+ end
159
+ rule forall
160
+ (/\u{2200}/i | ("forall"))
161
+ end
162
+ rule arrow
163
+ (/\u{2192}/i | (/(?:\u{2d})(?:>)/i))
164
+ end
165
+ rule exponent
166
+ (`e` (/[\u{2b}\u{2d}]/i?) ((digit)+))
167
+ end
168
+ rule numeric_double_literal
169
+ ((/[\u{2b}\u{2d}]/i?) ((digit)+) ((/\u{2e}/i ((digit)+) ((exponent)?)) | (exponent))) <Dhall::Parser::NumericDoubleLiteral>
170
+ end
171
+ rule minus_infinity_literal
172
+ (/\u{2d}/i (infinity)) <Dhall::Parser::MinusInfinityLiteral>
173
+ end
174
+ rule plus_infinity_literal
175
+ (infinity) <Dhall::Parser::PlusInfinityLiteral>
176
+ end
177
+ rule double_literal
178
+ ((numeric_double_literal) | (minus_infinity_literal) | (plus_infinity_literal) | (nan))
179
+ end
180
+ rule natural_literal
181
+ ((digit)+) <Dhall::Parser::NaturalLiteral>
182
+ end
183
+ rule integer_literal
184
+ (/[\u{2b}\u{2d}]/i (natural_literal)) <Dhall::Parser::IntegerLiteral>
185
+ end
186
+ rule identifier
187
+ ((any_label) (((whsp) /@/i (whsp) (natural_literal))?)) <Dhall::Parser::Identifier>
188
+ end
189
+ rule path_character
190
+ (/[!\u{24}-'\u{2a}\u{2b}\u{2d}\u{2e}0-;=@\u{5e}-z\u{7c}~]/i)
191
+ end
192
+ rule quoted_path_character
193
+ (/[\u{20}!\u{23}-\u{2e}0-@\u{5b}-\u{10ffff}]/i)
194
+ end
195
+ rule unquoted_path_component
196
+ ((path_character)+)
197
+ end
198
+ rule quoted_path_component
199
+ ((quoted_path_character)+)
200
+ end
201
+ rule path_component
202
+ (/\//i ((unquoted_path_component) | (/"/i (quoted_path_component) /"/i))) <Dhall::Parser::PathComponent>
203
+ end
204
+ rule path
205
+ ((path_component)+) <Dhall::Parser::Path>
206
+ end
207
+ rule local
208
+ ((parent_path) | (here_path) | (home_path) | (absolute_path))
209
+ end
210
+ rule parent_path
211
+ (/(?:\u{2e})(?:\u{2e})/i (path)) <Dhall::Parser::ParentPath>
212
+ end
213
+ rule here_path
214
+ (/\u{2e}/i (path)) <Dhall::Parser::HerePath>
215
+ end
216
+ rule home_path
217
+ (/~/i (path)) <Dhall::Parser::HomePath>
218
+ end
219
+ rule absolute_path
220
+ (path) <Dhall::Parser::AbsolutePath>
221
+ end
222
+ rule scheme
223
+ ("http" ("s"?))
224
+ end
225
+ rule http_raw
226
+ ((scheme) /(?::(?:\/))(?:\/)/i (authority) (path) ((/\u{3f}/i (query))?))
227
+ end
228
+ rule authority
229
+ ((((userinfo) /@/i)?) (host) ((`:` (port))?))
230
+ end
231
+ rule userinfo
232
+ (((unreserved) | (pct_encoded) | (sub_delims) | `:`)*)
233
+ end
234
+ rule host
235
+ ((ip_literal) | (ipv4address) | (reg_name))
236
+ end
237
+ rule port
238
+ ((digit)*)
239
+ end
240
+ rule ip_literal
241
+ (/\u{5b}/i ((ipv6address) | (ipvfuture)) /\u{5d}/i)
242
+ end
243
+ rule ipvfuture
244
+ (`v` ((hexdig)+) /\u{2e}/i (((unreserved) | (sub_delims) | `:`)+))
245
+ end
246
+ rule ipv6address
247
+ (((((h16) `:`) 6*6) (ls32)) | (`::` (((h16) `:`) 5*5) (ls32)) | (((h16)?) `::` (((h16) `:`) 4*4) (ls32)) | ((((((h16) `:`)?) (h16))?) `::` (((h16) `:`) 3*3) (ls32)) | ((((((h16) `:`) 0*2) (h16))?) `::` (((h16) `:`) 2*2) (ls32)) | ((((((h16) `:`) 0*3) (h16))?) `::` (h16) `:` (ls32)) | ((((((h16) `:`) 0*4) (h16))?) `::` (ls32)) | ((((((h16) `:`) 0*5) (h16))?) `::` (h16)) | ((((((h16) `:`) 0*6) (h16))?) `::`))
248
+ end
249
+ rule h16
250
+ ((hexdig) 1*4)
251
+ end
252
+ rule ls32
253
+ (((h16) `:` (h16)) | (ipv4address))
254
+ end
255
+ rule ipv4address
256
+ ((dec_octet) /\u{2e}/i (dec_octet) /\u{2e}/i (dec_octet) /\u{2e}/i (dec_octet))
257
+ end
258
+ rule dec_octet
259
+ ((digit) | (/[1-9]/i (digit)) | (`1` ((digit) 2*2)) | (/2(?:[0-4])/i (digit)) | (/25(?:[0-5])/i))
260
+ end
261
+ rule reg_name
262
+ (((unreserved) | (pct_encoded) | (sub_delims))*)
263
+ end
264
+ rule pchar
265
+ ((unreserved) | (pct_encoded) | (sub_delims) | /[:@]/i)
266
+ end
267
+ rule query
268
+ (((pchar) | /[\/\u{3f}]/i)*)
269
+ end
270
+ rule pct_encoded
271
+ (/%/i (hexdig) (hexdig))
272
+ end
273
+ rule unreserved
274
+ ((alpha) | (digit) | /[\u{2d}\u{2e}_~]/i)
275
+ end
276
+ rule sub_delims
277
+ (/[!\u{24}&-,;=]/i)
278
+ end
279
+ rule http
280
+ ((http_raw) (((whsp) (using) (whsp1) ((import_hashed) | (/\u{28}/i (whsp) (import_hashed) (whsp) /\u{29}/i)))?)) <Dhall::Parser::Http>
281
+ end
282
+ rule env
283
+ (`env:` ((bash_environment_variable) | (/"/i (posix_environment_variable) /"/i))) <Dhall::Parser::Env>
284
+ end
285
+ rule bash_environment_variable
286
+ (((alpha) | `_`) (((alpha) | (digit) | `_`)*))
287
+ end
288
+ rule posix_environment_variable
289
+ ((posix_environment_variable_character)+) <Dhall::Parser::PosixEnvironmentVariable>
290
+ end
291
+ rule posix_environment_variable_character
292
+ ((/\u{5c}/i /["\u{5c}abfnrtv]/) | /[\u{20}!\u{23}-<>-@\u{5b}\u{5d}-~]/i) <Dhall::Parser::PosixEnvironmentVariableCharacter>
293
+ end
294
+ rule import_type
295
+ ((missing) | (local) | (http) | (env))
296
+ end
297
+ rule hash
298
+ ("sha" `2` `5` `6` `:` ((hexdig) 64*64)) <Dhall::Parser::Hash>
299
+ end
300
+ rule import_hashed
301
+ ((import_type) (((whsp1) (hash))?)) <Dhall::Parser::ImportHashed>
302
+ end
303
+ rule import
304
+ ((import_hashed) (((whsp) (as) (whsp1) (text))?)) <Dhall::Parser::Import>
305
+ end
306
+ rule expression
307
+ (((lambda) (whsp) /\u{28}/i (whsp) (nonreserved_label) (whsp) `:` (whsp1) (expression) (whsp) /\u{29}/i (whsp) (arrow) (whsp) (expression)) | ((if) (whsp1) (expression) (whsp) (then) (whsp1) (expression) (whsp) (else) (whsp1) (expression)) | (((let_binding)+) (in) (whsp1) (expression)) | ((forall) (whsp) /\u{28}/i (whsp) (nonreserved_label) (whsp) `:` (whsp1) (expression) (whsp) /\u{29}/i (whsp) (arrow) (whsp) (expression)) | ((operator_expression) (whsp) (arrow) (whsp) (expression)) | ((merge) (whsp1) (import_expression) (whsp) (import_expression) (((whsp) `:` (whsp1) (application_expression))?)) | (/\u{5b}/i (whsp) ((empty_collection) | (non_empty_optional))) | (annotated_expression)) <Dhall::Parser::Expression>
308
+ end
309
+ rule annotated_expression
310
+ ((operator_expression) (((whsp) `:` (whsp1) (expression))?)) <Dhall::Parser::AnnotatedExpression>
311
+ end
312
+ rule let_binding
313
+ ((let) (whsp1) (nonreserved_label) (whsp) ((`:` (whsp1) (expression) (whsp))?) /=/i (whsp) (expression) (whsp)) <Dhall::Parser::LetBinding>
314
+ end
315
+ rule empty_collection
316
+ (/\u{5d}/i (whsp) `:` (whsp1) ((list) | (optional)) (whsp) (import_expression)) <Dhall::Parser::EmptyCollection>
317
+ end
318
+ rule non_empty_optional
319
+ ((expression) (whsp) /\u{5d}/i (whsp) `:` (whsp1) (optional) (whsp) (import_expression)) <Dhall::Parser::NonEmptyOptional>
320
+ end
321
+ rule operator_expression
322
+ (import_alt_expression)
323
+ end
324
+ rule import_alt_expression
325
+ ((or_expression) (((whsp) /\u{3f}/i (whsp1) (or_expression))*)) <Dhall::Parser::ImportAltExpression>
326
+ end
327
+ rule or_expression
328
+ ((plus_expression) (((whsp) /(?:\u{7c})(?:\u{7c})/i (whsp) (plus_expression))*)) <Dhall::Parser::OrExpression>
329
+ end
330
+ rule plus_expression
331
+ ((text_append_expression) (((whsp) /\u{2b}/i (whsp1) (text_append_expression))*)) <Dhall::Parser::PlusExpression>
332
+ end
333
+ rule text_append_expression
334
+ ((list_append_expression) (((whsp) /(?:\u{2b})(?:\u{2b})/i (whsp) (list_append_expression))*)) <Dhall::Parser::TextAppendExpression>
335
+ end
336
+ rule list_append_expression
337
+ ((and_expression) (((whsp) /\u{23}/i (whsp) (and_expression))*)) <Dhall::Parser::ListAppendExpression>
338
+ end
339
+ rule and_expression
340
+ ((combine_expression) (((whsp) /(?:&)(?:&)/i (whsp) (combine_expression))*)) <Dhall::Parser::AndExpression>
341
+ end
342
+ rule combine_expression
343
+ ((prefer_expression) (((whsp) (combine) (whsp) (prefer_expression))*)) <Dhall::Parser::CombineExpression>
344
+ end
345
+ rule prefer_expression
346
+ ((combine_types_expression) (((whsp) (prefer) (whsp) (combine_types_expression))*)) <Dhall::Parser::PreferExpression>
347
+ end
348
+ rule combine_types_expression
349
+ ((times_expression) (((whsp) (combine_types) (whsp) (times_expression))*)) <Dhall::Parser::CombineTypesExpression>
350
+ end
351
+ rule times_expression
352
+ ((equal_expression) (((whsp) /\u{2a}/i (whsp) (equal_expression))*)) <Dhall::Parser::TimesExpression>
353
+ end
354
+ rule equal_expression
355
+ ((not_equal_expression) (((whsp) /(?:=)(?:=)/i (whsp) (not_equal_expression))*)) <Dhall::Parser::EqualExpression>
356
+ end
357
+ rule not_equal_expression
358
+ ((application_expression) (((whsp) /(?:!)(?:=)/i (whsp) (application_expression))*)) <Dhall::Parser::NotEqualExpression>
359
+ end
360
+ rule application_expression
361
+ ((((some) (whsp1))?) (import_expression) (((whsp1) (import_expression))*)) <Dhall::Parser::ApplicationExpression>
362
+ end
363
+ rule import_expression
364
+ ((import) | (selector_expression))
365
+ end
366
+ rule selector_expression
367
+ ((primitive_expression) (((whsp) /\u{2e}/i (whsp) (selector))*)) <Dhall::Parser::SelectorExpression>
368
+ end
369
+ rule selector
370
+ ((any_label) | (labels))
371
+ end
372
+ rule labels
373
+ (/\u{7b}/i (whsp) (((any_label) (whsp) ((/,/i (whsp) (any_label) (whsp))*))?) /\u{7d}/i) <Dhall::Parser::Labels>
374
+ end
375
+ rule primitive_expression
376
+ ((double_literal) | (natural_literal) | (integer_literal) | (text_literal) | (/\u{7b}/i (whsp) (record_type_or_literal) (whsp) /\u{7d}/i) | (/</i (whsp) (union_type_or_literal) (whsp) />/i) | (non_empty_list_literal) | (identifier) | (/\u{28}/i (complete_expression) /\u{29}/i)) <Dhall::Parser::PrimitiveExpression>
377
+ end
378
+ rule record_type_or_literal
379
+ ((empty_record_literal) | (non_empty_record_type_or_literal) | (empty_record_type))
380
+ end
381
+ rule empty_record_literal
382
+ (/=/i) <Dhall::Parser::EmptyRecordLiteral>
383
+ end
384
+ rule empty_record_type
385
+ ("") <Dhall::Parser::EmptyRecordType>
386
+ end
387
+ rule non_empty_record_type_or_literal
388
+ ((any_label) (whsp) ((non_empty_record_literal) | (non_empty_record_type))) <Dhall::Parser::NonEmptyRecordTypeOrLiteral>
389
+ end
390
+ rule non_empty_record_type
391
+ (`:` (whsp1) (expression) (((whsp) /,/i (whsp) (record_type_entry))*)) <Dhall::Parser::NonEmptyRecordType>
392
+ end
393
+ rule record_type_entry
394
+ ((any_label) (whsp) `:` (whsp1) (expression)) <Dhall::Parser::RecordTypeEntry>
395
+ end
396
+ rule non_empty_record_literal
397
+ (/=/i (whsp) (expression) (((whsp) /,/i (whsp) (record_literal_entry))*)) <Dhall::Parser::NonEmptyRecordLiteral>
398
+ end
399
+ rule record_literal_entry
400
+ ((any_label) (whsp) /=/i (whsp) (expression)) <Dhall::Parser::RecordLiteralEntry>
401
+ end
402
+ rule union_type_or_literal
403
+ ((non_empty_union_type_or_literal) | (empty_union_type))
404
+ end
405
+ rule empty_union_type
406
+ ("") <Dhall::Parser::EmptyUnionType>
407
+ end
408
+ rule non_empty_union_type_or_literal
409
+ ((any_label) (((whsp) ((union_literal_variant_value) | (union_type_or_literal_variant_type)))?)) <Dhall::Parser::NonEmptyUnionTypeOrLiteral>
410
+ end
411
+ rule union_literal_variant_value
412
+ (/=/i (whsp) (expression) (((whsp) /\u{7c}/i (whsp) (union_type_entry))*)) <Dhall::Parser::UnionLiteralVariantValue>
413
+ end
414
+ rule union_type_entry
415
+ ((any_label) (((whsp) `:` (whsp1) (expression))?)) <Dhall::Parser::UnionTypeEntry>
416
+ end
417
+ rule union_type_or_literal_variant_type
418
+ (((`:` (whsp1) (expression))?) (((whsp) /\u{7c}/i (whsp) (non_empty_union_type_or_literal))?)) <Dhall::Parser::UnionTypeOrLiteralVariantType>
419
+ end
420
+ rule non_empty_list_literal
421
+ (/\u{5b}/i (whsp) (expression) (whsp) ((/,/i (whsp) (expression) (whsp))*) /\u{5d}/i) <Dhall::Parser::NonEmptyListLiteral>
422
+ end
423
+ rule complete_expression
424
+ ((whsp) (expression) (whsp)) <Dhall::Parser::CompleteExpression>
425
+ end
426
+ rule bit
427
+ (/[01]/i)
428
+ end
429
+ rule char
430
+ (/[\u{01}-@\u{5b}-\u{7f}]/i)
431
+ end
432
+ rule cr
433
+ (/\r/i)
434
+ end
435
+ rule crlf
436
+ ((cr) (lf))
437
+ end
438
+ rule ctl
439
+ (/[\u{00}-\u{1f}\u{7f}]/i)
440
+ end
441
+ rule dquote
442
+ (/"/i)
443
+ end
444
+ rule htab
445
+ (/\t/i)
446
+ end
447
+ rule lf
448
+ (/\n/i)
449
+ end
450
+ rule lwsp
451
+ (((wsp) | ((crlf) (wsp)))*)
452
+ end
453
+ rule octet
454
+ (/[\u{00}-@\u{5b}-\u{ff}]/i)
455
+ end
456
+ rule sp
457
+ (/\u{20}/i)
458
+ end
459
+ rule vchar
460
+ (/[!-@\u{5b}-~]/i)
461
+ end
462
+ rule wsp
463
+ ((sp) | (htab))
464
+ end
465
+ rule reserved_identifier
466
+ "Natural/build" |
467
+ "Natural/fold" |
468
+ "Natural/isZero" |
469
+ "Natural/even" |
470
+ "Natural/odd" |
471
+ "Natural/toInteger" |
472
+ "Natural/show" |
473
+ "Integer/toDouble" |
474
+ "Integer/show" |
475
+ "Double/show" |
476
+ "List/build" |
477
+ "List/fold" |
478
+ "List/length" |
479
+ "List/head" |
480
+ "List/last" |
481
+ "List/indexed" |
482
+ "List/reverse" |
483
+ "Optional/fold" |
484
+ "Optional/build" |
485
+ "Text/show" |
486
+ "Bool" |
487
+ "Optional" |
488
+ "Natural" |
489
+ "Integer" |
490
+ "Double" |
491
+ "Text" |
492
+ "List" |
493
+ "True" |
494
+ "False" |
495
+ "None" |
496
+ "Type" |
497
+ "Kind" |
498
+ "Sort"
499
+ end
500
+ end