Class: Yadriggy::Loop
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb
Overview
while, until, and modifier while/until.
Instance Attribute Summary collapse
-
#body ⇒ ASTnode
readonly
The loop body.
-
#cond ⇒ ASTnode
readonly
The condition expression.
-
#op ⇒ Symbol
readonly
:while
,:until
,:while_mod
, or:until_mod
.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#initialize(sexp) ⇒ Loop
constructor
A new instance of Loop.
-
#real_operator ⇒ Symbol
Returns the real operator name.
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) ⇒ Loop
Returns a new instance of Loop.
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 |
# File 'lib/yadriggy/ast.rb', line 1140 def initialize(sexp) @op = sexp[0] @cond = to_node(sexp[1]) case @op when :while_mod, :until_mod @body = to_node(sexp[2]) else @body = Exprs.make(sexp[2]) end add_child(@cond) add_child(@body) end |
Instance Attribute Details
#body ⇒ ASTnode (readonly)
Returns the loop body.
1136 1137 1138 |
# File 'lib/yadriggy/ast.rb', line 1136 def body @body end |
#cond ⇒ ASTnode (readonly)
Returns the condition expression.
1133 1134 1135 |
# File 'lib/yadriggy/ast.rb', line 1133 def cond @cond end |
#op ⇒ Symbol (readonly)
Returns :while
, :until
, :while_mod
, or :until_mod
.
1130 1131 1132 |
# File 'lib/yadriggy/ast.rb', line 1130 def op @op end |
Class Method Details
.tags ⇒ Object
1138 |
# File 'lib/yadriggy/ast.rb', line 1138 def self.() [:while, :until, :while_mod, :until_mod] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1156 1157 1158 |
# File 'lib/yadriggy/ast.rb', line 1156 def accept(evaluator) evaluator.loop(self) end |
#real_operator ⇒ Symbol
Returns the real operator name.
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
# File 'lib/yadriggy/ast.rb', line 1162 def real_operator case @op when :while_mod :while when :until_mod :until else @op end end |