Class: Solargraph::Parser::ParserGem::NodeProcessors::OpasgnNode

Inherits:
NodeProcessor::Base show all
Defined in:
lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb

Instance Attribute Summary

Attributes inherited from NodeProcessor::Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods inherited from NodeProcessor::Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Parser::NodeProcessor::Base

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb', line 10

def process
  # Parser::CurrentRuby.parse("a += 2")
  # => s(:op_asgn,
  #      s(:lvasgn, :a), :+,
  #      s(:int, 2))
  asgn = node.children[0]
  variable_name = asgn.children[0]
  operator = node.children[1]
  argument = node.children[2]
  # for lvasgn, gvasgn, cvasgn, convert to lvar, gvar, cvar
  # [6] pry(main)> Parser::CurrentRuby.parse("a = a + 1")
  # => s(:lvasgn, :a,
  #   s(:send,
  #     s(:lvar, :a), :+,
  #     s(:int, 1)))
  # [7] pry(main)>
  variable_reference_type = asgn.type.to_s.sub(/vasgn$/, 'var').to_sym
  variable_reference = node.updated(variable_reference_type, asgn.children)
  send_children = [
    variable_reference,
    operator,
    argument
  ]
  send_node = node.updated(:send, send_children)
  new_asgn = node.updated(asgn.type, [variable_name,  send_node])
  NodeProcessor.process(new_asgn, region, pins, locals)
end