From c96020032566959f30bb9fa4c3af56dbe9849ef8 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 5 May 2019 20:12:07 -0500 Subject: [PATCH] Update to latest dhall-lang --- dhall-lang | 2 +- lib/dhall/ast.rb | 45 +++++++++++++++++------------------------- lib/dhall/binary.rb | 1 - lib/dhall/normalize.rb | 9 ++++++++- lib/dhall/parser.rb | 18 +++++++++++++---- test/test_as_json.rb | 1 + test/test_parser.rb | 1 + 7 files changed, 43 insertions(+), 34 deletions(-) diff --git a/dhall-lang b/dhall-lang index f0509b4..2ae7c0c 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit f0509b403ace4b8a72ebb5fa9c473b9aeabeaf33 +Subproject commit 2ae7c0c74265226ecbed018c5f83e0c574a5bc39 diff --git a/lib/dhall/ast.rb b/lib/dhall/ast.rb index c96659a..741a7ec 100644 --- a/lib/dhall/ast.rb +++ b/lib/dhall/ast.rb @@ -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 diff --git a/lib/dhall/binary.rb b/lib/dhall/binary.rb index d21770b..c8fdfcb 100644 --- a/lib/dhall/binary.rb +++ b/lib/dhall/binary.rb @@ -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), diff --git a/lib/dhall/normalize.rb b/lib/dhall/normalize.rb index 0b1d1c3..ec4df46 100644 --- a/lib/dhall/normalize.rb +++ b/lib/dhall/normalize.rb @@ -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 diff --git a/lib/dhall/parser.rb b/lib/dhall/parser.rb index 31a532d..9b3706b 100644 --- a/lib/dhall/parser.rb +++ b/lib/dhall/parser.rb @@ -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 == "\\" diff --git a/test/test_as_json.rb b/test/test_as_json.rb index 36a26e2..8685bde 100644 --- a/test/test_as_json.rb +++ b/test/test_as_json.rb @@ -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 diff --git a/test/test_parser.rb b/test/test_parser.rb index c45f8e9..62b0291 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -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) -- 2.45.2