Class: Yadriggy::Loop

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

Overview

while, until, and modifier while/until.

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) ⇒ Loop

Returns a new instance of Loop.



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/yadriggy/ast.rb', line 1136

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

#bodyASTnode (readonly)

Returns the loop body.

Returns:



1132
1133
1134
# File 'lib/yadriggy/ast.rb', line 1132

def body
  @body
end

#condASTnode (readonly)

Returns the condition expression.

Returns:

  • (ASTnode)

    the condition expression.



1129
1130
1131
# File 'lib/yadriggy/ast.rb', line 1129

def cond
  @cond
end

#opSymbol (readonly)

Returns :while, :until, :while_mod, or :until_mod.

Returns:

  • (Symbol)

    :while, :until, :while_mod, or :until_mod.



1126
1127
1128
# File 'lib/yadriggy/ast.rb', line 1126

def op
  @op
end

Class Method Details

.tagsObject



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

def self.tags() [:while, :until, :while_mod, :until_mod] end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



1152
1153
1154
# File 'lib/yadriggy/ast.rb', line 1152

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

#real_operatorSymbol

Returns the real operator name.

Returns:

  • (Symbol)

    the real operator name, while or until.



1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/yadriggy/ast.rb', line 1158

def real_operator
  case @op
  when :while_mod
    :while
  when :until_mod
    :until
  else
    @op
  end
end