Class: Dhallish::Ast::OptionalNode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, expression) ⇒ OptionalNode

Returns a new instance of OptionalNode.



328
329
330
331
# File 'lib/ast.rb', line 328

def initialize(prefix, expression)
  @isSome = (prefix == "Some")
  @expression = expression
end

Instance Attribute Details

#expressionObject

expression should be a some value for prefix “Some” or a Type for prefix “None”



326
327
328
# File 'lib/ast.rb', line 326

def expression
  @expression
end

Instance Method Details

#compute_type(ctx) ⇒ Object



333
334
335
336
337
338
339
340
341
342
# File 'lib/ast.rb', line 333

def compute_type(ctx)
  if @isSome
    elem_type = @expression.compute_type ctx
  else
    type_type = @expression.compute_type ctx
    assert ("Expression after \"None\" not a type") { type_type.is_a? Types::Type }
    elem_type = type_type.
  end
  Types::Optional.new elem_type
end

#evaluate(ctx) ⇒ Object



344
345
346
347
348
349
350
# File 'lib/ast.rb', line 344

def evaluate(ctx)
  if @isSome
    @expression.evaluate(ctx)
  else
    nil
  end
end