Class: Dhall::LetIn
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #as_dhall, #cache_key, #call, #concat, decode, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #resolve, #slice, #to_binary, #to_cbor, #to_proc, #to_s, #|
Instance Method Details
#as_json ⇒ Object
1766
1767
1768
|
# File 'lib/dhall/ast.rb', line 1766
def as_json
[25, *let.as_json, body.as_json]
end
|
#desugar ⇒ Object
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
|
# File 'lib/dhall/ast.rb', line 1748
def desugar
Application.new(
function: Function.new(
var: let.var,
type: let.type,
body: body
),
argument: let.assign
)
end
|
#eliminate ⇒ Object
1759
1760
1761
1762
1763
1764
|
# File 'lib/dhall/ast.rb', line 1759
def eliminate
body.substitute(
Dhall::Variable[let.var],
let.assign.shift(1, let.var, 0)
).shift(-1, let.var, 0)
end
|
#flatten ⇒ Object
1739
1740
1741
1742
1743
1744
1745
1746
|
# File 'lib/dhall/ast.rb', line 1739
def flatten
flattened = body.is_a?(LetIn) ? body.flatten : body
if flattened.is_a?(LetIn) || flattened.is_a?(LetBlock)
LetBlock.for(lets: [let] + flattened.lets, body: flattened.body)
else
self
end
end
|
#lets ⇒ Object
1735
1736
1737
|
# File 'lib/dhall/ast.rb', line 1735
def lets
[let]
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
426
427
428
429
430
|
# File 'lib/dhall/normalize.rb', line 423
def shift(amount, name, min_index)
return super unless let.var == name
with(
let: let.shift(amount, name, min_index),
body: body.shift(amount, name, min_index + 1)
)
end
|
#substitute(svar, with_expr) ⇒ Object
432
433
434
435
436
437
438
439
440
441
|
# File 'lib/dhall/normalize.rb', line 432
def substitute(svar, with_expr)
var = let.var
with(
let: let.substitute(svar, with_expr),
body: body.substitute(
var == svar.name ? svar.with(index: svar.index + 1) : svar,
with_expr.shift(1, var, 0)
)
)
end
|