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, #to_cbor, #to_proc, #to_s, #|
Class Method Details
.decode(*parts) ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/dhall/binary.rb', line 205
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
1648
1649
1650
1651
1652
1653
1654
|
# File 'lib/dhall/ast.rb', line 1648
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
1671
1672
1673
|
# File 'lib/dhall/ast.rb', line 1671
def as_json
[25, *lets.flat_map(&:as_json), body.as_json]
end
|
#desugar ⇒ Object
1667
1668
1669
|
# File 'lib/dhall/ast.rb', line 1667
def desugar
unflatten(&:desugar)
end
|
#flatten ⇒ Object
1656
1657
1658
|
# File 'lib/dhall/ast.rb', line 1656
def flatten
unflatten.flatten
end
|
#normalize ⇒ Object
419
420
421
|
# File 'lib/dhall/normalize.rb', line 419
def normalize
desugar.normalize
end
|
#shift(amount, name, min_index) ⇒ Object
423
424
425
|
# File 'lib/dhall/normalize.rb', line 423
def shift(amount, name, min_index)
unflatten.shift(amount, name, min_index)
end
|
#substitute(svar, with_expr) ⇒ Object
427
428
429
|
# File 'lib/dhall/normalize.rb', line 427
def substitute(svar, with_expr)
unflatten.substitute(svar, with_expr)
end
|
#unflatten ⇒ Object
1660
1661
1662
1663
1664
1665
|
# File 'lib/dhall/ast.rb', line 1660
def unflatten
lets.reverse.reduce(body) do |inside, let|
letin = LetIn.new(let: let, body: inside)
block_given? ? (yield letin) : letin
end
end
|