~singpolyma/dhall-ruby

9a230286a1eec33bda93aee493272d35c45aeda0 — Stephen Paul Weber 5 years ago 1d780e3
Handle self-describe tag anywhere
1 files changed, 9 insertions(+), 5 deletions(-)

M lib/dhall/binary.rb
M lib/dhall/binary.rb => lib/dhall/binary.rb +9 -5
@@ 223,6 223,13 @@ module Dhall
		end
	end

	def self.handle_tag(e)
		return e unless e.is_a?(::CBOR::Tagged)
		return e.value if e.tag == 55799

		raise "Unknown tag: #{e.inspect}"
	end

	BINARY = {
		::TrueClass    => ->(e) { Bool.new(value: e) },
		::FalseClass   => ->(e) { Bool.new(value: e) },


@@ 230,6 237,7 @@ module Dhall
		::String       => ->(e) { Builtins[e.to_sym] || (raise "Unknown builtin") },
		::Integer      => ->(e) { Variable.new(index: e) },
		::Array        => lambda { |e|
			e = e.map(&method(:handle_tag))
			if e.length == 2 && e.first.is_a?(::String)
				Variable.new(name: e[0], index: e[1])
			else


@@ 238,11 246,7 @@ module Dhall
					(raise "Unknown expression: #{e.inspect}")
			end
		},
		::CBOR::Tagged => lambda { |e|
			return Dhall.decode(e.value) if e.tag == 55799

			raise "Unknown tag: #{e.inspect}"
		}
		::CBOR::Tagged => ->(e) { Dhall.decode(handle_tag(e)) }
	}.freeze

	BINARY_TAGS = [