Class: Unparser::Preprocessor

Inherits:
Object
  • Object
show all
Includes:
AbstractType, Adamantium::Flat, NodeHelpers
Defined in:
lib/unparser/preprocessor.rb

Overview

Preprocessor to normalize AST generated by parser

Direct Known Subclasses

Begin, Infinity, Noop

Defined Under Namespace

Classes: Begin, Infinity, Noop

Constant Summary collapse

EMPTY =
Parser::AST::Node.new(:empty)
REGISTRY =
Hash.new { |hash, key| hash[key] = [] }

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NodeHelpers

#n, #s

Class Method Details

.run(node, parent_type = nil) ⇒ Parser::AST::Node?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run preprocessor for node

Parameters:

  • node (Parser::AST::Node, nil)

Returns:

  • (Parser::AST::Node, nil)


26
27
28
29
30
31
32
# File 'lib/unparser/preprocessor.rb', line 26

def self.run(node, parent_type = nil)
  return EMPTY if node.nil?

  REGISTRY.fetch(node.type, [Noop]).reduce(node) do |current, processor|
    processor.call(current, parent_type)
  end
end

Instance Method Details

#resultParser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return preprocessor result

Returns:

  • (Parser::AST::Node)


14
# File 'lib/unparser/preprocessor.rb', line 14

abstract_method :result