Class: ASTTransform::AbstractProcessor

Inherits:
Parser::AST::Processor
  • Object
show all
Includes:
TransformationHelper
Defined in:
lib/ast_transform/abstract_processor.rb

Overview

Shared traversal core for tree passes. Parser::AST::Processor is a rewriting walker — every visit functionally rebuilds the tree — so transformation and analysis share one engine and differ only in what they keep: AbstractTransformation's run returns the rebuilt tree, AbstractAnalysis's run discards it and returns the harvested results. Subclass one of those leaves rather than this class.

Direct Known Subclasses

AbstractAnalysis, AbstractTransformation

Instance Method Summary collapse

Methods included from TransformationHelper

included

Instance Method Details

#on_ast_thunk(node) ⇒ Object

Thunks are framework-owned IR: descend into the body so passes that don't know about thunks still process the wrapped statements. Without this, Processor's handler_missing default would pass the node through opaquely, hiding the body from every later pass. The token (first child) is not a node and passes through untouched.



23
24
25
# File 'lib/ast_transform/abstract_processor.rb', line 23

def on_ast_thunk(node)
  node.updated(nil, [node.children[0], *process_all(node.children.drop(1))])
end

#process(node) ⇒ Object

Used internally by Parser::AST::Processor to process each node. DO NOT OVERRIDE.



14
15
16
17
18
# File 'lib/ast_transform/abstract_processor.rb', line 14

def process(node)
  return node unless node.is_a?(Parser::AST::Node)

  process_node(node)
end