Module: Solargraph::Parser::NodeProcessor

Defined in:
lib/solargraph/parser/node_processor.rb,
lib/solargraph/parser/node_processor/base.rb,
lib/solargraph/parser/legacy/node_processors.rb,
lib/solargraph/parser/rubyvm/node_processors.rb

Overview

The processor classes used by SourceMap::Mapper to generate pins from parser nodes.

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Class Method Details

.process(node, region = Region.new, pins = [], locals = []) ⇒ Array(Array<Pin::Base>, Array<Pin::Base>)

Parameters:

  • node (Parser::AST::Node)
  • region (Region) (defaults to: Region.new)
  • pins (Array<Pin::Base>) (defaults to: [])

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solargraph/parser/node_processor.rb', line 28

def self.process node, region = Region.new, pins = [], locals = []
  if pins.empty?
    pins.push Pin::Namespace.new(
      location: region.source.location,
      name: ''
    )
  end
  return [pins, locals] unless Parser.is_ast_node?(node)
  klass = @@processors[node.type] || NodeProcessor::Base
  processor = klass.new(node, region, pins, locals)
  processor.process
  [processor.pins, processor.locals]
end

.register(type, cls) ⇒ Class<NodeProcessor::Base>

Register a processor for a node type.

Parameters:

Returns:



19
20
21
# File 'lib/solargraph/parser/node_processor.rb', line 19

def register type, cls
  @@processors[type] = cls
end