Module: Propose::Visitor
- Included in:
- AtomFinder
- Defined in:
- lib/propose/visitor.rb
Overview
Provides basic functionality for traversing a parse tree.
Classes which include this module can define methods such as ‘visit_conjunction` to have the visitor visit all conjunctions in the parse tree.
Instance Method Summary collapse
Instance Method Details
#visit(node) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/propose/visitor.rb', line 8 def visit(node) # Keep track of whether this block was consumed by the visitor. This # allows us to visit all nodes by default, but can override the behavior # by specifying `yield false` in a visit method, indicating that no # further visiting should occur for the current node's children. block_called = false block = ->(descend = :children) do block_called = true visit_children(node) if descend == :children end method = "visit_#{node_name(node)}" send(method, node, &block) if respond_to?(method, true) visit_children(node) unless block_called end |