Module: Docscribe::Infer::ASTWalk
- Defined in:
- lib/docscribe/infer/ast_walk.rb
Overview
AST traversal helpers for parser AST nodes.
Class Method Summary collapse
-
.walk(node, &block) {|node| ... } ⇒ void
Depth-first walk over a parser AST.
Class Method Details
.walk(node, &block) {|node| ... } ⇒ void
Note:
module_function: when included, also defines #walk (instance visibility: private)
This method returns an undefined value.
Depth-first walk over a parser AST.
Yields each node exactly once, descending recursively through child nodes. Non-AST values are ignored.
18 19 20 21 22 23 24 25 |
# File 'lib/docscribe/infer/ast_walk.rb', line 18 def walk(node, &block) return unless node.is_a?(Parser::AST::Node) yield node node.children.each do |ch| walk(ch, &block) if ch.is_a?(Parser::AST::Node) end end |