class SyntaxTree::BasicVisitor
attempt to visit a node that you don’t handle.
should extend this class if you want your visitor to raise an error if you
ability to walk down the tree. It does not define any handlers, so you
BasicVisitor is the parent class of the Visitor class that provides the
def valid_visit_methods
def valid_visit_methods @valid_visit_methods ||= Visitor.instance_methods.grep(/^visit_(?!child_nodes)/) end
def visit(node)
def visit(node) node&.accept(self) end
def visit_all(nodes)
def visit_all(nodes) nodes.map { |node| visit(node) } end
def visit_child_nodes(node)
def visit_child_nodes(node) visit_all(node.child_nodes) end
def visit_method(method_name)
name. It will raise an error if the visit method you're defining isn't
If you use this method, you can ensure you're writing the correct method
override these parent methods.
the visitor since it's perfectly valid to define methods that don't
It's not always easy to ensure you're writing the correct method name in
This method is here to help folks write visitors.
def visit_method(method_name) return if valid_visit_methods.include?(method_name) raise VisitMethodError, method_name end
def visit_methods
ensure it's a valid visit method using the BasicVisitor::visit_method
Within the given block, every method that is defined will be checked to
This method is here to help folks write visitors.
def visit_methods checker = VisitMethodsChecker.new extend(checker) yield checker.disable! end