Class: Dhall::LetBlock
- Inherits:
-
Expression
show all
- Defined in:
- lib/dhall/ast.rb,
lib/dhall/binary.rb,
lib/dhall/normalize.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #<<, #as_dhall, #cache_key, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #resolve, #slice, #substitute, #to_cbor, #to_proc, #|
Class Method Details
.decode(*parts) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/dhall/binary.rb', line 206
def self.decode(*parts)
body = Dhall.decode(parts.pop)
lets = parts.each_slice(3).map do |(var, type, assign)|
Let.new(
var: var,
assign: Dhall.decode(assign),
type: type.nil? ? nil : Dhall.decode(type)
)
end
self.for(lets: lets, body: body)
end
|
.for(lets:, body:) ⇒ Object
1525
1526
1527
1528
1529
1530
1531
|
# File 'lib/dhall/ast.rb', line 1525
def self.for(lets:, body:)
if lets.length == 1
LetIn.new(let: lets.first, body: body)
else
new(lets: lets, body: body)
end
end
|
Instance Method Details
#as_json ⇒ Object
1544
1545
1546
|
# File 'lib/dhall/ast.rb', line 1544
def as_json
[25, *lets.flat_map(&:as_json), body.as_json]
end
|
#desugar ⇒ Object
1540
1541
1542
|
# File 'lib/dhall/ast.rb', line 1540
def desugar
unflatten(&:desugar)
end
|
#normalize ⇒ Object
406
407
408
|
# File 'lib/dhall/normalize.rb', line 406
def normalize
desugar.normalize
end
|
#shift(amount, name, min_index) ⇒ Object
410
411
412
|
# File 'lib/dhall/normalize.rb', line 410
def shift(amount, name, min_index)
unflatten.shift(amount, name, min_index)
end
|
#unflatten ⇒ Object
1533
1534
1535
1536
1537
1538
|
# File 'lib/dhall/ast.rb', line 1533
def unflatten
lets.reverse.reduce(body) do |inside, let|
letin = LetIn.new(let: let, body: inside)
block_given? ? (yield letin) : letin
end
end
|