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_binary, #to_cbor, #to_proc, #to_s, #|
Class Method Details
.decode(*parts) ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/dhall/binary.rb', line 272
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
1777
1778
1779
1780
1781
1782
1783
|
# File 'lib/dhall/ast.rb', line 1777
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
1800
1801
1802
|
# File 'lib/dhall/ast.rb', line 1800
def as_json
[25, *lets.flat_map(&:as_json), body.as_json]
end
|
#desugar ⇒ Object
1796
1797
1798
|
# File 'lib/dhall/ast.rb', line 1796
def desugar
unflatten(&:desugar)
end
|
#flatten ⇒ Object
1785
1786
1787
|
# File 'lib/dhall/ast.rb', line 1785
def flatten
unflatten.flatten
end
|
#normalize ⇒ Object
445
446
447
|
# File 'lib/dhall/normalize.rb', line 445
def normalize
desugar.normalize
end
|
#shift(amount, name, min_index) ⇒ Object
449
450
451
|
# File 'lib/dhall/normalize.rb', line 449
def shift(amount, name, min_index)
unflatten.shift(amount, name, min_index)
end
|
#substitute(svar, with_expr) ⇒ Object
453
454
455
|
# File 'lib/dhall/normalize.rb', line 453
def substitute(svar, with_expr)
unflatten.substitute(svar, with_expr)
end
|
#unflatten ⇒ Object
1789
1790
1791
1792
1793
1794
|
# File 'lib/dhall/ast.rb', line 1789
def unflatten
lets.reverse.reduce(body) do |inside, let|
letin = LetIn.new(let: let, body: inside)
block_given? ? (yield letin) : letin
end
end
|