Module: Rigor::Source::NodeWalker
- Defined in:
- lib/rigor/source/node_walker.rb
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.
- .walk(node) {|node| ... } ⇒ Object
Class Method Details
.each(root) {|node| ... } ⇒ Enumerator
Returns when no block is given.
22 23 24 25 26 27 |
# File 'lib/rigor/source/node_walker.rb', line 22 def each(root, &) return to_enum(__method__, root) unless block_given? walk(root, &) nil end |
.walk(node) {|node| ... } ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rigor/source/node_walker.rb', line 29 def walk(node, &) return unless node.is_a?(Prism::Node) yield node node.compact_child_nodes.each { |child| walk(child, &) } end |