Class: Dhallish::Ast::RecordProjection

Inherits:
Object
  • Object
show all
Defined in:
lib/ast.rb

Overview

keys: ruby-list of keys to access (strings)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rec, keys) ⇒ RecordProjection

Returns a new instance of RecordProjection.



466
467
468
469
# File 'lib/ast.rb', line 466

def initialize(rec, keys)
	@rec = rec
	@keys = keys
end

Instance Attribute Details

#keysObject

Returns the value of attribute keys.



465
466
467
# File 'lib/ast.rb', line 465

def keys
  @keys
end

#recObject

Returns the value of attribute rec.



464
465
466
# File 'lib/ast.rb', line 464

def rec
  @rec
end

Instance Method Details

#compute_type(ctx) ⇒ Object



471
472
473
474
475
476
477
478
479
480
# File 'lib/ast.rb', line 471

def compute_type(ctx)
	rectype = @rec.compute_type ctx
	assert("`.` can only be used on records") { rectype.is_a? Types::Record }
	newrectype = {}
	@keys.each { |key|
		assert("missing key in projection: `#{key}`") { !rectype.types[key].nil? }
		newrectype[key] = rectype.types[key]
	}
	Types::Record.new(newrectype)
end

#evaluate(ctx) ⇒ Object



482
483
484
485
486
487
488
489
# File 'lib/ast.rb', line 482

def evaluate(ctx)
	rec = @rec.evaluate ctx
	newrecvals = {}
	@keys.each { |key|
		newrecvals[key] = rec[key]
	}
	newrecvals
end