Module: Rigor::Source::NodeWalker
- Defined in:
- lib/rigor/source/node_walker.rb,
sig/rigor/source.rbs
Overview
Yields every Prism::Node reachable from a root in DFS pre-order.
The walker is the source-positioning analogue to NodeLocator: where the locator answers "what node
is at this point?", the walker enumerates the full set of Prism nodes for tooling that needs to
operate on each one (coverage probes, lint passes, IDE outlines).
Non-Prism children (literals embedded in node attributes, virtual nodes, or nil slots) are silently
skipped so callers can rely on every yielded value responding to the Prism::Node API.
Class Method Summary collapse
-
.each(root) {|node| ... } ⇒ Enumerator
When no block is given.
-
.each_with_ancestors(root) {|node, ancestors| ... } ⇒ Enumerator
Like NodeWalker.each, but also yields the node's lexical ancestor chain (outermost first, EXCLUDING the node itself).
- .walk(node) {|node| ... } ⇒ Object
- .walk_with_ancestors(node, ancestors, &block) ⇒ Object
Instance Method Summary collapse
- #self?.each {|arg0| ... } ⇒ Object
- #self?.each_with_ancestors {|arg0, arg1| ... } ⇒ Object
- #self?.walk {|arg0| ... } ⇒ void
- #self?.walk_with_ancestors {|arg0, arg1| ... } ⇒ void
Class Method Details
.each(root) {|node| ... } ⇒ Enumerator
Returns when no block is given.
20 21 22 23 24 25 |
# File 'lib/rigor/source/node_walker.rb', line 20 def each(root, &) return to_enum(__method__, root) unless block_given? walk(root, &) nil end |
.each_with_ancestors(root) {|node, ancestors| ... } ⇒ Enumerator
Like each, but also yields the node's lexical ancestor chain (outermost first, EXCLUDING the node
itself). The yielded ancestors array is the live descent stack — callers that retain it past the
block invocation MUST copy it (Plugin::NodeContext does). Used by the plugin engine to give
node_rule blocks their enclosing class / method / block context (ADR-37 slice 1d).
42 43 44 45 46 47 |
# File 'lib/rigor/source/node_walker.rb', line 42 def each_with_ancestors(root, &) return to_enum(__method__, root) unless block_given? walk_with_ancestors(root, [], &) nil end |
.walk(node) {|node| ... } ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rigor/source/node_walker.rb', line 27 def walk(node, &) return unless node.is_a?(Prism::Node) yield node node.compact_child_nodes.each { |child| walk(child, &) } end |
.walk_with_ancestors(node, ancestors, &block) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rigor/source/node_walker.rb', line 49 def walk_with_ancestors(node, ancestors, &block) return unless node.is_a?(Prism::Node) block.call(node, ancestors) ancestors.push(node) node.compact_child_nodes.each { |child| walk_with_ancestors(child, ancestors, &block) } ancestors.pop end |
Instance Method Details
#self? ⇒ nil #self? ⇒ Enumerator[untyped, nil]
25 26 |
# File 'sig/rigor/source.rbs', line 25
def self?.each: (untyped root) { (untyped) -> void } -> nil
| (untyped root) -> Enumerator[untyped, nil]
|
#self? ⇒ nil #self? ⇒ Enumerator[untyped, nil]
28 29 |
# File 'sig/rigor/source.rbs', line 28
def self?.each_with_ancestors: (untyped root) { (untyped, Array[untyped]) -> void } -> nil
| (untyped root) -> Enumerator[untyped, nil]
|
#self?.walk {|arg0| ... } ⇒ void
This method returns an undefined value.
27 |
# File 'sig/rigor/source.rbs', line 27
def self?.walk: (untyped node) { (untyped) -> void } -> void
|
#self?.walk_with_ancestors {|arg0, arg1| ... } ⇒ void
This method returns an undefined value.
30 |
# File 'sig/rigor/source.rbs', line 30
def self?.walk_with_ancestors: (untyped node, Array[untyped] ancestors) { (untyped, Array[untyped]) -> void } -> void
|