class Dhallish::Ast::ListNode
Attributes
list[RW]
type_node[RW]
Public Class Methods
new(list, type_node)
click to toggle source
# File lib/ast.rb, line 286 def initialize(list, type_node) @list = list @type_node = type_node end
Public Instance Methods
compute_type(ctx)
click to toggle source
# File lib/ast.rb, line 291 def compute_type(ctx) elem_type = nil if !@type_node.nil? annot_type = @type_node.compute_type ctx assert ("Annotated Type not a type") { annot_type.is_a? Types::Type } elem_type = annot_type.metadata end if @list.length > 0 if !elem_type.nil? assert ("First list element's type mismatches annotated type") { list[0].compute_type(ctx) == elem_type } else elem_type = list[0].compute_type(ctx) end @list.each_with_index { |e, idx| t = e.compute_type(ctx) assert ("Type mismatch: element at index #{idx} has type #{t}, expected #{elem_type}") { t == elem_type } } end Types::List.new elem_type end
evaluate(ctx)
click to toggle source
# File lib/ast.rb, line 315 def evaluate(ctx) res = [] list.each { |node| res.append node.evaluate(ctx) } res end