class Yadriggy::Assign

Assignment such as `=` and `+=`. `Assign#left` and `Assign#right` return an `ASTnode`, or an array of `ASTnode` if the node represents multiple assignment.

Public Class Methods

new(sexp) click to toggle source
# File lib/yadriggy/ast.rb, line 704
def initialize(sexp)
  case sexp[0]
  when :assign
    @left = to_node(sexp[1])
    add_child(@left)
    @op = :'='
    init_right(sexp[2])
  when :opassign
    @left = to_node(sexp[1])
    add_child(@left)
    @op = has_tag?(sexp[2], :@op)[1].to_sym
    init_right(sexp[3])
  when :massign
    @left = to_nodes(sexp[1])
    add_children(@left)
    @op = :'='
    init_right(sexp[2])
  else
    raise "unknown assignment " + sexp[0].to_s
  end
end
tags() click to toggle source
# File lib/yadriggy/ast.rb, line 702
def self.tags() [:assign, :opassign, :massign] end

Public Instance Methods

accept(evaluator) click to toggle source

A method for Visitor pattern. @param [Eval] evaluator the visitor of Visitor pattern. @return [void]

# File lib/yadriggy/ast.rb, line 729
def accept(evaluator)
  evaluator.assign(self)
end
const_value() click to toggle source
# File lib/yadriggy/ast_value.rb, line 389
def const_value() Undef end
const_value_in_class(klass) click to toggle source
# File lib/yadriggy/ast_value.rb, line 391
def const_value_in_class(klass) Undef end
value() click to toggle source
# File lib/yadriggy/ast_value.rb, line 385
def value() Undef end
value_in_class(klass) click to toggle source
# File lib/yadriggy/ast_value.rb, line 387
def value_in_class(klass) Undef end

Private Instance Methods

init_right(right_operand) click to toggle source

@api private

# File lib/yadriggy/ast.rb, line 736
def init_right(right_operand)
  if right_operand[0] == :mrhs_new_from_args
    @right = to_nodes(right_operand[1]) + [to_node(right_operand[2])]
    add_children(@right)
  else
    @right = to_node(right_operand)
    add_child(@right)
  end
end