instance method
Prism::Translation::Ripper#visit_call_node
visit_call_node(node)
lib/prism/translation/ripper.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/prism/translation/ripper.rb, line 1003
def visit_call_node(node)
if node.call_operator_loc.nil?
case node.name
when :[]
receiver = visit(node.receiver)
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
bounds(node.location)
call = on_aref(receiver, arguments)
if block.nil?
call
else
bounds(node.location)
on_method_add_block(call, block)
end
when :[]=
receiver = visit(node.receiver)
*arguments, last_argument = node.arguments.arguments
arguments << node.block if !node.block.nil?
arguments =
if arguments.any?
args = visit_arguments(arguments)
if !node.block.nil?
args
else
bounds(arguments.first.location)
on_args_add_block(args, false)
end
end
bounds(node.location)
call = on_aref_field(receiver, arguments)
value = visit_write_value(last_argument)
bounds(last_argument.location)
on_assign(call, value)
when :-@, :+@, :~
receiver = visit(node.receiver)
bounds(node.location)
on_unary(node.name, receiver)
when :!
if node.message == "not"
receiver =
if !node.receiver.is_a?(ParenthesesNode) || !node.receiver.body.nil?
visit(node.receiver)
end
bounds(node.location)
on_unary(:not, receiver)
else
receiver = visit(node.receiver)
bounds(node.location)
on_unary(:!, receiver)
end
when *BINARY_OPERATORS
receiver = visit(node.receiver)
value = visit(node.arguments.arguments.first)
bounds(node.location)
on_binary(receiver, node.name, value)
else
bounds(node.message_loc)
message = visit_token(node.message, false)
if node.variable_call?
on_vcall(message)
else
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location))
call =
if node.opening_loc.nil? && arguments&.any?
bounds(node.location)
on_command(message, arguments)
elsif !node.opening_loc.nil?
bounds(node.location)
on_method_add_arg(on_fcall(message), on_arg_paren(arguments))
else
bounds(node.location)
on_method_add_arg(on_fcall(message), on_args_new)
end
if block.nil?
call
else
bounds(node.block.location)
on_method_add_block(call, block)
end
end
end
else
receiver = visit(node.receiver)
bounds(node.call_operator_loc)
call_operator = visit_token(node.call_operator)
message =
if node.message_loc.nil?
:call
else
bounds(node.message_loc)
visit_token(node.message, false)
end
if node.name.end_with?("=") && !node.message.end_with?("=") && !node.arguments.nil? && node.block.nil?
value = visit_write_value(node.arguments.arguments.first)
bounds(node.location)
on_assign(on_field(receiver, call_operator, message), value)
else
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location))
call =
if node.opening_loc.nil?
bounds(node.location)
if node.arguments.nil? && !node.block.is_a?(BlockArgumentNode)
on_call(receiver, call_operator, message)
else
on_command_call(receiver, call_operator, message, arguments)
end
else
bounds(node.opening_loc)
arguments = on_arg_paren(arguments)
bounds(node.location)
on_method_add_arg(on_call(receiver, call_operator, message), arguments)
end
if block.nil?
call
else
bounds(node.block.location)
on_method_add_block(call, block)
end
end
end
end
foo ^^^
foo.bar ^^^^^^^
foo.bar() {} ^^^^^^^^^^^^