From 42276b7eda8f5368ba339d9afb824f62526518d2 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 10 Jul 2019 22:03:04 -0500 Subject: [PATCH] Update parser --- lib/dhall/parser.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/dhall/parser.rb b/lib/dhall/parser.rb index 73ed7b7..5d5c37c 100644 --- a/lib/dhall/parser.rb +++ b/lib/dhall/parser.rb @@ -22,15 +22,10 @@ module Dhall module Expression def value key = - [:let_binding, :lambda, :forall, :arrow, :if, :merge] + [:let_binding, :lambda, :forall, :arrow, :if, :merge, :list] .find { |k| captures.key?(k) } - return public_send(key) if key - - key = - [:empty_collection, :non_empty_optional] - .find { |k| captures.key?(k) } - key ? capture(key).value : super + key ? public_send(key) : super end def let_binding @@ -78,6 +73,10 @@ module Dhall type: capture(:application_expression)&.value ) end + + def list + EmptyList.new(element_type: capture(:import_expression).value) + end end OPERATORS = { @@ -142,8 +141,7 @@ module Dhall module SelectorExpression def value record = capture(:primitive_expression).value - selectors = captures(:selector).map(&:value) - selectors.reduce(record) do |rec, sels| + captures(:selector).map(&:value).reduce(record) do |rec, sels| if sels.is_a?(Array) RecordProjection.for(rec, sels) elsif sels.is_a?(Dhall::Expression) @@ -155,9 +153,15 @@ module Dhall end end - module Labels + module Selector def value - captures(:any_label).map(&:value) + if captures.key?(:type_selector) + capture(:expression).value + elsif captures.key?(:labels) + captures(:any_label).map(&:value) + else + string + end end end -- 2.45.2