M .rubocop.yml => .rubocop.yml +3 -0
@@ 70,6 70,9 @@ Style/StringLiteralsInInterpolation:
Style/SymbolArray:
EnforcedStyle: brackets
+Style/NumericLiterals:
+ Enabled: false
+
Style/WordArray:
EnforcedStyle: brackets
M lib/dhall/binary.rb => lib/dhall/binary.rb +11 -6
@@ 219,12 219,12 @@ module Dhall
end
BINARY = {
- ::TrueClass => ->(e) { Bool.new(value: e) },
- ::FalseClass => ->(e) { Bool.new(value: e) },
- ::Float => ->(e) { Double.new(value: e) },
- ::String => ->(e) { Builtins::ALL[e]&.new || Variable.new(name: e) },
- ::Integer => ->(e) { Variable.new(index: e) },
- ::Array => lambda { |e|
+ ::TrueClass => ->(e) { Bool.new(value: e) },
+ ::FalseClass => ->(e) { Bool.new(value: e) },
+ ::Float => ->(e) { Double.new(value: e) },
+ ::String => ->(e) { Builtins::ALL[e]&.new || Variable.new(name: e) },
+ ::Integer => ->(e) { Variable.new(index: e) },
+ ::Array => lambda { |e|
if e.length == 2 && e.first.is_a?(::String)
Variable.new(name: e[0], index: e[1])
else
@@ 232,6 232,11 @@ module Dhall
BINARY_TAGS[tag]&.decode(*body) ||
(raise "Unknown expression: #{e.inspect}")
end
+ },
+ ::CBOR::Tagged => lambda { |e|
+ return Dhall.decode(e.value) if e.tag == 55799
+
+ raise "Unknown tag: #{e.inspect}"
}
}.freeze
M test/test_binary.rb => test/test_binary.rb +8 -0
@@ 1,5 1,6 @@
# frozen_string_literal: true
+require "base64"
require "minitest/autorun"
require "pathname"
@@ 19,4 20,11 @@ class TestBinary < Minitest::Test
)
end
end
+
+ def test_self_describing_cbor
+ assert_equal(
+ Dhall::Variable["x"],
+ Dhall.from_binary(Base64.decode64("2dn3YXg"))
+ )
+ end
end