Class: Yadriggy::Conditional

Inherits:
ASTnode
  • Object
show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb

Overview

if, unless, modifier if/unless, and ternary if (?:).

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ Conditional



1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/yadriggy/ast.rb', line 1077

def initialize(sexp)
  @op = sexp[0]
  @cond = to_node(sexp[1])
  @all_elsif = []
  case @op
  when :ifop                   # ternary if
    @then = to_node(sexp[2])
    @else = to_node(sexp[3])
  when :if_mod, :unless_mod    # modifier if/unless
    @then = to_node(sexp[2])
    @else = nil
  else                         # if/unless
    @then = Exprs.make(sexp[2])
    initialize_else(sexp[3])
  end
  add_child(@cond)
  add_child(@then)
  add_child(@else)
  @all_elsif.each do |pair|
    pair.each { |e| add_child(e) }
  end
end

Instance Attribute Details

#all_elsifArray<ASTnode> (readonly)

Returns the elsif-expressions.



1070
1071
1072
# File 'lib/yadriggy/ast.rb', line 1070

def all_elsif
  @all_elsif
end

#condASTnode (readonly)



1062
1063
1064
# File 'lib/yadriggy/ast.rb', line 1062

def cond
  @cond
end

#elseASTnode|nil (readonly)



1073
1074
1075
# File 'lib/yadriggy/ast.rb', line 1073

def else
  @else
end

#opSymbol (readonly)



1059
1060
1061
# File 'lib/yadriggy/ast.rb', line 1059

def op
  @op
end

#thenASTnode (readonly)



1065
1066
1067
# File 'lib/yadriggy/ast.rb', line 1065

def then
  @then
end

Class Method Details

.tagsObject



1075
# File 'lib/yadriggy/ast.rb', line 1075

def self.tags() [:if, :unless, :ifop, :if_mod, :unless_mod] end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.



1103
1104
1105
# File 'lib/yadriggy/ast.rb', line 1103

def accept(evaluator)
  evaluator.conditional(self)
end