class Yadriggy::Call

Method call following parentheses. @see Command @see VariableCall

Attributes

args[R]

@return [Array<ASTnode>] the method-call arguments.

block[R]

@return [ASTnode|nil] the block passed to the method.

block_arg[R]

@return [ASTnode|nil] the argument preceded by an ampersand.

name[R]

@return [Identifier] the method name.

op[R]

Returns either `:“.”`, `:“::”`, or `nil`. @return [Symbol] the symbol used as a separator between

the receiver and the method name.
It is either `:"."`, `:"::"`, or `nil`.
receiver[R]

@return [ASTnode|nil] the callee object.

Public Class Methods

make(receiver: nil, op: nil, name:, args: [], block_arg: nil, block: nil, parent:, link_from_children: false) click to toggle source

Makes an instance of {Call} with the given values for its instance variables. @param [ASTnode|nil] receiver the receiver object. @param [Symbol|nil] op the operator. @param [Identifeir] name the method name. @param [Array<ASTnode>] args the method-call arguments. @param [ASTnode|nil] block_arg the argument preceded by an ampersand. @param [ASTnode|nil] block the block passed to the method. @param [ASTnode] parent the parent node. @param [Boolean] link_from_children if true, links from children

to `self` are added.

@return [Call] the created object.

# File lib/yadriggy/ast.rb, line 829
def self.make(receiver: nil, op: nil, name:, args: [],
              block_arg: nil, block: nil,
              parent:, link_from_children: false)
  obj = self.allocate
  obj.initialize2(receiver, op, name, args, block_arg, block,
                  parent, link_from_children)
end
new(sexp) click to toggle source
# File lib/yadriggy/ast.rb, line 859
def initialize(sexp)
  @args = []
  @block_arg = nil
  @block = nil

  case sexp[0]
  when :call, :field
    initialize_call(sexp)
  when :method_add_block
    marg = sexp[1]
    if marg[0] == :method_add_arg
      initialize_method_arg(marg[1], marg[2])
    elsif marg[0] == :command
      initialize_call([:call, nil, nil, marg[1]])
      initialize_args(marg[2]) if marg.length > 2
    elsif marg[0] == :command_call
      initialize_call([:call, marg[1], marg[2], marg[3]])
      initialize_args(marg[4]) if marg.length > 4
    else
      initialize_method_arg(marg, [])
    end
    @block = to_node(sexp[2])
    add_child(@block)
  else
    initialize_method_arg(sexp[1], sexp[2])
  end
end
tags() click to toggle source
# File lib/yadriggy/ast.rb, line 857
def self.tags() [:method_add_arg, :call, :method_add_block, :field] 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 890
def accept(evaluator)
  evaluator.call(self)
end
initialize2(recv, op, name, args, barg, blk, parent, link_from_children) click to toggle source

@api private

# File lib/yadriggy/ast.rb, line 838
def initialize2(recv, op, name, args, barg, blk,
                parent, link_from_children)
  @receiver = recv
  @op = op
  @name = name
  @args = args
  @block_arg = barg
  @block = blk
  @parent = parent
  if link_from_children
    add_child(@receiver)
    add_child(@name)
    add_children(@args)
    add_child(@block_arg)
    add_child(@block)
  end
  self
end
value() click to toggle source

Gets the invoked method or Undef.

# File lib/yadriggy/ast_value.rb, line 397
def value()
  if @receiver.nil?
    lookup_method(get_receiver_object)
  else
    lookup_method(@receiver.value)
  end
end
value_in_class(klass) click to toggle source
# File lib/yadriggy/ast_value.rb, line 405
def value_in_class(klass)
  if @receiver.nil?
    lookup_method(get_receiver_object)
  else
    lookup_method(@receiver.value_in_class(klass))
  end
end

Private Instance Methods

initialize_args(args_block) click to toggle source
# File lib/yadriggy/ast.rb, line 935
def initialize_args(args_block)
  args = if args_block[0] == :args_add_block
           args_block[1]
         else
           args_block
         end
  args2 = initialize_star_arg(args)
  @args = to_nodes(args2)
  @block_arg = if args_block[2]
                 to_node(args_block[2])
               else
                 nil
               end
  add_children(@args)
  add_child(@block_arg)
end
initialize_call(sexp) click to toggle source
# File lib/yadriggy/ast.rb, line 913
def initialize_call(sexp)
  @receiver = to_node(sexp[1])
  @op = op_symbol(sexp[2])    # :"." or :"::" or nil.
  @name = if sexp[3] == :call
            nil
          else
            @name = to_node(has_tag?(sexp[3], :@ident))
          end
  add_child(@receiver)
  add_child(@name)
end
initialize_method_arg(msg, arg_paren) click to toggle source
# File lib/yadriggy/ast.rb, line 896
def initialize_method_arg(msg, arg_paren)
  if msg[0] == :fcall
    initialize_call([:call, nil, nil, msg[1]])
  elsif msg[0] == :call
    initialize_call(msg)
  else
    raise 'unknown pattern ' + msg.to_s
  end

  if arg_paren.length > 0
    args_block = has_tag?(arg_paren, :arg_paren)[1]
    unless args_block.nil?
      initialize_args(args_block)
    end
  end
end
initialize_star_arg(args) click to toggle source
# File lib/yadriggy/ast.rb, line 952
def initialize_star_arg(args)
  if args[0] == :args_add_star
    new_args = initialize_star_arg(args[1]) + [[:unary, :*, args[2]]]
    for i in 3...args.size
      new_args << args[i]
    end
    new_args
  else
    args
  end
end
lookup_method(obj) click to toggle source
# File lib/yadriggy/ast_value.rb, line 414
def lookup_method(obj)
  if obj.nil? || obj == Undef
    Undef
  else
    begin
      obj.method(@name.name)
    rescue NameError
      Undef
    end
  end
end
op_symbol(op) click to toggle source
# File lib/yadriggy/ast.rb, line 925
def op_symbol(op)
  if op.is_a?(Array)
    op = has_tag?(op, :@period)
    op[1].to_sym
  else
    # Ruby 2.5 or earlier
    op
  end
end