class YARP::DesugarVisitor
Public Instance Methods
visit_class_variable_and_write_node(node)
click to toggle source
@@foo &&= bar
becomes
@@foo && @@foo = bar
# File yarp/desugar_visitor.rb, line 10 def visit_class_variable_and_write_node(node) desugar_and_write_node(node, ClassVariableReadNode, ClassVariableWriteNode, node.name) end
visit_class_variable_operator_write_node(node)
click to toggle source
@@foo += bar
becomes
@@foo = @@foo + bar
# File yarp/desugar_visitor.rb, line 28 def visit_class_variable_operator_write_node(node) desugar_operator_write_node(node, ClassVariableReadNode, ClassVariableWriteNode, node.name) end
visit_class_variable_or_write_node(node)
click to toggle source
@@foo ||= bar
becomes
defined?(@@foo) ? @@foo : @@foo = bar
# File yarp/desugar_visitor.rb, line 19 def visit_class_variable_or_write_node(node) desugar_or_write_defined_node(node, ClassVariableReadNode, ClassVariableWriteNode, node.name) end
visit_constant_and_write_node(node)
click to toggle source
Foo &&= bar
becomes
Foo && Foo = bar
# File yarp/desugar_visitor.rb, line 37 def visit_constant_and_write_node(node) desugar_and_write_node(node, ConstantReadNode, ConstantWriteNode, node.name) end
visit_constant_operator_write_node(node)
click to toggle source
Foo += bar
becomes
Foo = Foo + bar
# File yarp/desugar_visitor.rb, line 55 def visit_constant_operator_write_node(node) desugar_operator_write_node(node, ConstantReadNode, ConstantWriteNode, node.name) end
visit_constant_or_write_node(node)
click to toggle source
Foo ||= bar
becomes
defined?(Foo) ? Foo : Foo = bar
# File yarp/desugar_visitor.rb, line 46 def visit_constant_or_write_node(node) desugar_or_write_defined_node(node, ConstantReadNode, ConstantWriteNode, node.name) end
visit_global_variable_and_write_node(node)
click to toggle source
$foo &&= bar
becomes
$foo && $foo = bar
# File yarp/desugar_visitor.rb, line 64 def visit_global_variable_and_write_node(node) desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, node.name) end
visit_global_variable_operator_write_node(node)
click to toggle source
$foo += bar
becomes
$foo = $foo + bar
# File yarp/desugar_visitor.rb, line 82 def visit_global_variable_operator_write_node(node) desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, node.name) end
visit_global_variable_or_write_node(node)
click to toggle source
$foo ||= bar
becomes
defined?($foo) ? $foo : $foo = bar
# File yarp/desugar_visitor.rb, line 73 def visit_global_variable_or_write_node(node) desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, node.name) end
visit_instance_variable_and_write_node(node)
click to toggle source
@foo &&= bar
becomes
@foo && @foo = bar
# File yarp/desugar_visitor.rb, line 91 def visit_instance_variable_and_write_node(node) desugar_and_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, node.name) end
visit_instance_variable_operator_write_node(node)
click to toggle source
@foo += bar
becomes
@foo = @foo + bar
# File yarp/desugar_visitor.rb, line 109 def visit_instance_variable_operator_write_node(node) desugar_operator_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, node.name) end
visit_instance_variable_or_write_node(node)
click to toggle source
@foo ||= bar
becomes
@foo || @foo = bar
# File yarp/desugar_visitor.rb, line 100 def visit_instance_variable_or_write_node(node) desugar_or_write_node(node, InstanceVariableReadNode, InstanceVariableWriteNode, node.name) end
visit_local_variable_and_write_node(node)
click to toggle source
foo &&= bar
becomes
foo && foo = bar
# File yarp/desugar_visitor.rb, line 118 def visit_local_variable_and_write_node(node) desugar_and_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, node.name, node.depth) end
visit_local_variable_operator_write_node(node)
click to toggle source
foo += bar
becomes
foo = foo + bar
# File yarp/desugar_visitor.rb, line 136 def visit_local_variable_operator_write_node(node) desugar_operator_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, node.name, node.depth) end
visit_local_variable_or_write_node(node)
click to toggle source
foo ||= bar
becomes
foo || foo = bar
# File yarp/desugar_visitor.rb, line 127 def visit_local_variable_or_write_node(node) desugar_or_write_node(node, LocalVariableReadNode, LocalVariableWriteNode, node.name, node.depth) end
Private Instance Methods
desugar_and_write_node(node, read_class, write_class, *arguments)
click to toggle source
Desugar ‘x &&= y` to `x && x = y`
# File yarp/desugar_visitor.rb, line 143 def desugar_and_write_node(node, read_class, write_class, *arguments) AndNode.new( read_class.new(*arguments, node.name_loc), write_class.new(*arguments, node.name_loc, node.value, node.operator_loc, node.location), node.operator_loc, node.location ) end
desugar_operator_write_node(node, read_class, write_class, *arguments)
click to toggle source
Desugar ‘x += y` to `x = x + y`
# File yarp/desugar_visitor.rb, line 153 def desugar_operator_write_node(node, read_class, write_class, *arguments) write_class.new( *arguments, node.name_loc, CallNode.new( read_class.new(*arguments, node.name_loc), nil, node.operator_loc.copy(length: node.operator_loc.length - 1), nil, ArgumentsNode.new([node.value], node.value.location), nil, nil, 0, node.operator_loc.slice.chomp("="), node.location ), node.operator_loc.copy(start_offset: node.operator_loc.end_offset - 1, length: 1), node.location ) end
desugar_or_write_defined_node(node, read_class, write_class, *arguments)
click to toggle source
Desugar ‘x ||= y` to `defined?(x) ? x : x = y`
# File yarp/desugar_visitor.rb, line 185 def desugar_or_write_defined_node(node, read_class, write_class, *arguments) IfNode.new( node.operator_loc, DefinedNode.new(nil, read_class.new(*arguments, node.name_loc), nil, node.operator_loc, node.name_loc), StatementsNode.new([read_class.new(*arguments, node.name_loc)], node.location), ElseNode.new( node.operator_loc, StatementsNode.new( [write_class.new(*arguments, node.name_loc, node.value, node.operator_loc, node.location)], node.location ), node.operator_loc, node.location ), node.operator_loc, node.location ) end
desugar_or_write_node(node, read_class, write_class, *arguments)
click to toggle source
Desugar ‘x ||= y` to `x || x = y`
# File yarp/desugar_visitor.rb, line 175 def desugar_or_write_node(node, read_class, write_class, *arguments) OrNode.new( read_class.new(*arguments, node.name_loc), write_class.new(*arguments, node.name_loc, node.value, node.operator_loc, node.location), node.operator_loc, node.location ) end