~singpolyma/dhall-ruby

c96020032566959f30bb9fa4c3af56dbe9849ef8 — Stephen Paul Weber 4 years ago 9a23028
Update to latest dhall-lang
M dhall-lang => dhall-lang +1 -1
@@ 1,1 1,1 @@
Subproject commit f0509b403ace4b8a72ebb5fa9c473b9aeabeaf33
Subproject commit 2ae7c0c74265226ecbed018c5f83e0c574a5bc39

M lib/dhall/ast.rb => lib/dhall/ast.rb +18 -27
@@ 1085,12 1085,12 @@ module Dhall
			Builtins[:Text]
		end

		def empty?
			value.empty?
		end

		def <<(other)
			if other.is_a?(Text)
				with(value: value + other.value)
			else
				super
			end
			with(value: value + other.value)
		end

		def to_s


@@ 1123,6 1123,14 @@ module Dhall
			fixed.length == 1 ? fixed.first : new(chunks: fixed)
		end

		def start_empty?
			chunks.first.empty?
		end

		def end_empty?
			chunks.last.empty?
		end

		def as_json
			[18, *chunks.map { |chunk| chunk.is_a?(Text) ? chunk.value : chunk.as_json }]
		end


@@ 1370,24 1378,6 @@ module Dhall
		end

		class EnvironmentVariable
			ESCAPES = {
				"\"" => "\"",
				"\\" => "\\",
				"a"  => "\a",
				"b"  => "\b",
				"f"  => "\f",
				"n"  => "\n",
				"r"  => "\r",
				"t"  => "\t",
				"v"  => "\v"
			}.freeze

			def self.decode(var)
				var.gsub(/\\[\"\\abfnrtv]/) do |escape|
					ESCAPES.fetch(escape[1])
				end
			end

			attr_reader :var

			def initialize(var)


@@ 1427,7 1417,10 @@ module Dhall
			end

			def to_s
				"env:#{as_json}"
				escapes = Parser::PosixEnvironmentVariableCharacter::ESCAPES
				"env:#{@var.gsub(/[\"\\\a\b\f\n\r\t\v]/) do |c|
					"\\" + escapes.find { |(_, v)| v == c }.first
				end}"
			end

			def hash


@@ 1440,9 1433,7 @@ module Dhall
			alias eql? ==

			def as_json
				@var.gsub(/[\"\\\a\b\f\n\r\t\v]/) do |c|
					"\\" + ESCAPES.find { |(_, v)| v == c }.first
				end
				@var
			end
		end


M lib/dhall/binary.rb => lib/dhall/binary.rb +0 -1
@@ 192,7 192,6 @@ module Dhall
	class Import
		def self.decode(integrity_check, import_type, path_type, *parts)
			parts[0] = Dhall.decode(parts[0]) if path_type < 2 && !parts[0].nil?
			parts[0] = EnvironmentVariable.decode(parts[0]) if path_type == 6

			new(
				IntegrityCheck.new(*integrity_check),

M lib/dhall/normalize.rb => lib/dhall/normalize.rb +8 -1
@@ 363,7 363,14 @@ module Dhall

	class TextLiteral
		def normalize
			TextLiteral.for(*super.flatten.chunks)
			lit = TextLiteral.for(*super.flatten.chunks)

			if lit.is_a?(TextLiteral) && lit.chunks.length == 3 &&
			   lit.start_empty? && lit.end_empty?
				lit.chunks[1]
			else
				lit
			end
		end

		def flatten

M lib/dhall/parser.rb => lib/dhall/parser.rb +14 -4
@@ 559,9 559,9 @@ module Dhall
			def value
				Dhall::Import::EnvironmentVariable.new(
					if captures.key?(:bash_environment_variable)
						capture(:bash_environment_variable).string
						capture(:bash_environment_variable).value
					else
						capture(:posix_environment_variable).value.encode("utf-8")
						capture(:posix_environment_variable).value
					end
				)
			end


@@ 569,12 569,22 @@ module Dhall

		module PosixEnvironmentVariable
			def value
				matches.map(&:value).join
				matches.map(&:value).join.encode(Encoding::UTF_8)
			end
		end

		module PosixEnvironmentVariableCharacter
			ESCAPES = Dhall::Import::EnvironmentVariable::ESCAPES
			ESCAPES = {
				"\"" => "\"",
				"\\" => "\\",
				"a"  => "\a",
				"b"  => "\b",
				"f"  => "\f",
				"n"  => "\n",
				"r"  => "\r",
				"t"  => "\t",
				"v"  => "\v"
			}.freeze

			def value
				if first&.string == "\\"

M test/test_as_json.rb => test/test_as_json.rb +1 -0
@@ 16,6 16,7 @@ class TestAsJson < Minitest::Test
		define_method("test_#{test}") do
			skip "double as_json" if test =~ /doubleB/
			skip "deprecated syntax" if test =~ /collectionImportTypeB|annotationsB/
			skip "deprecated syntax" if test =~ /pathTerminationUnion/
			assert_equal(
				CBOR.decode(path.read),
				Dhall.from_binary(path.read).as_json

M test/test_parser.rb => test/test_parser.rb +1 -0
@@ 14,6 14,7 @@ class TestParser < Minitest::Test
		test = path.relative_path_from(TESTS).to_s.sub(/A\.dhall$/, "")
		define_method("test_#{test}") do
			skip "deprecated syntax" if test =~ /collectionImportType|annotations/
			skip "deprecated syntax" if test =~ /pathTerminationUnion/
			skip "very slow" if !ENV.key?("CI") && test =~ /largeExpression/
			match = Dhall::Parser.parse_file(path)
			assert(match)