~singpolyma/dhall-ruby

a7a8593ab08221d6e30afad5a0f9727a23fcf95f — Stephen Paul Weber 3 years ago c924b36
Allow arbitrary ruby objects to live in the AST

Only for when you're really sure you want that.
2 files changed, 31 insertions(+), 3 deletions(-)

M lib/dhall/ast.rb
M lib/dhall/normalize.rb
M lib/dhall/ast.rb => lib/dhall/ast.rb +30 -2
@@ 217,7 217,29 @@ module Dhall
		end
	end

	class FunctionProxy < Function
	class RubyObjectRaw < Expression
		def initialize(object)
			@object = object
		end

		def unwrap
			@object
		end

		def respond_to_missing?(m)
			super || @object.respond_to?(m)
		end

		def method_missing(m, *args, &block)
			if @object.respond_to?(m)
				@object.public_send(m, *args, &block)
			else
				super
			end
		end
	end

	class FunctionProxyRaw < Function
		def initialize(callable, curry: true)
			@callable = if !curry
				callable


@@ 231,7 253,7 @@ module Dhall
		end

		def call(*args, &block)
			@callable.call(*args.map { |arg| arg&.as_dhall }, &block).as_dhall
			RubyObjectRaw.new(@callable.call(*args.map { |arg| arg&.as_dhall }, &block))
		end

		def as_json


@@ 239,6 261,12 @@ module Dhall
		end
	end

	class FunctionProxy < FunctionProxyRaw
		def call(*args, &block)
			super.unwrap.as_dhall
		end
	end

	class Bool < Expression
		include(ValueSemantics.for_attributes do
			value Bool()

M lib/dhall/normalize.rb => lib/dhall/normalize.rb +1 -1
@@ 120,7 120,7 @@ module Dhall
		end
	end

	class FunctionProxy
	class FunctionProxyRaw
		def shift(*)
			self
		end