Module: Solargraph::Parser::NodeProcessor

Defined in:
lib/solargraph/parser/node_processor.rb,
lib/solargraph/parser/node_processor/base.rb,
lib/solargraph/parser/parser_gem/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

.deregister(type, cls) ⇒ void

This method returns an undefined value.

Parameters:



30
31
32
# File 'lib/solargraph/parser/node_processor.rb', line 30

def deregister type, cls
  @@processors[type].delete(cls)
end

.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: [])
  • locals (Array<Pin::BaseVariable>) (defaults to: [])

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/solargraph/parser/node_processor.rb', line 40

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

  node_processor_classes.each do |klass|
    processor = klass.new(node, region, pins, locals)
    process_next = processor.process

    break unless process_next
  end

  [pins, locals]
end

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

Register a processor for a node type. You can register multiple processors for the same type. If a node processor returns true, it will skip the next processor of the same node type.

Parameters:

Returns:



21
22
23
24
# File 'lib/solargraph/parser/node_processor.rb', line 21

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