~singpolyma/dhall-ruby

ef67435f5e2b0937c1da262d59c6a10394203743 — Stephen Paul Weber 5 years ago 62d267c
RecordProjection.for
3 files changed, 10 insertions(+), 7 deletions(-)

M lib/dhall/ast.rb
M lib/dhall/binary.rb
M lib/dhall/parser.rb
M lib/dhall/ast.rb => lib/dhall/ast.rb +8 -0
@@ 798,6 798,14 @@ module Dhall
			selectors Util::ArrayOf.new(::String, min: 1)
		end)

		def self.for(record, selectors)
			if selectors.empty?
				EmptyRecordProjection.new(record: record)
			else
				new(record: record, selectors: selectors)
			end
		end

		def as_json
			[10, record.as_json, *selectors]
		end

M lib/dhall/binary.rb => lib/dhall/binary.rb +1 -5
@@ 141,11 141,7 @@ module Dhall

	class RecordProjection
		def self.decode(record, *selectors)
			if selectors.empty?
				EmptyRecordProjection.new(record: Dhall.decode(record))
			else
				new(record: Dhall.decode(record), selectors: selectors)
			end
			self.for(Dhall.decode(record), selectors)
		end
	end


M lib/dhall/parser.rb => lib/dhall/parser.rb +1 -2
@@ 145,8 145,7 @@ module Dhall
				selectors = captures(:selector).map(&:value)
				selectors.reduce(record) do |rec, sels|
					if sels.is_a?(Array)
						return EmptyRecordProjection.new(record: rec) if sels.empty?
						RecordProjection.new(record: rec, selectors: sels)
						RecordProjection.for(rec, sels)
					else
						RecordSelection.new(record: rec, selector: sels)
					end