~singpolyma/dhall-ruby

7a3a7bc998acbbeb6859580db2455297d81459c7 — Stephen Paul Weber 3 years ago 75e0382
Facility to flatten let blocks
1 files changed, 17 insertions(+), 0 deletions(-)

M lib/dhall/ast.rb
M lib/dhall/ast.rb => lib/dhall/ast.rb +17 -0
@@ 1599,6 1599,19 @@ module Dhall
			body Expression
		end)

		def lets
			[let]
		end

		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

		def desugar
			Application.new(
				function: Function.new(


@@ 1636,6 1649,10 @@ module Dhall
			end
		end

		def flatten
			unflatten.flatten
		end

		def unflatten
			lets.reverse.reduce(body) do |inside, let|
				letin = LetIn.new(let: let, body: inside)