Expand description
Generic AST visitor used by the linter, formatter, and any other
crate that needs to walk every SNode in a parsed program.
Centralizing this here keeps a single source of truth for which
children each Node variant has — adding a new variant requires
one edit (in walk_children) and every consumer benefits.
§Usage
ⓘ
use harn_parser::visit::walk_program;
let mut count = 0;
walk_program(&program, &mut |node| {
if matches!(&node.node, harn_parser::Node::FunctionCall { .. }) {
count += 1;
}
});The visitor invokes the closure on each node before recursing
into its children (pre-order). To stop recursion at a particular
node, prefer using walk_children directly.
Functions§
- walk_
children - Recurse into
node’s children without re-visitingnodeitself. Useful when a caller wants to handle the parent specially and then continue the default traversal. - walk_
node - Visit
node, then recurse into its children. - walk_
program - Walk every node in
programin pre-order, invokingvisitoron each.