Skip to main content

Module visit

Module visit 

Source
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 collect_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§

contains_identifier_enum_pattern
Return whether a program contains an enum-shaped match pattern whose receiver is a bare identifier (Status.Ready or Status.Error(value)).
contains_identifier_receiver_access
Return whether a program contains a member access or method call whose receiver is a bare identifier (Name.Member). This is the only syntax whose lowering needs to distinguish an imported enum namespace from an ordinary runtime object; callers can use the predicate to avoid resolving the full import graph for files that cannot contain that ambiguity.
immediate_children
Collect node’s immediate children without recursing. Lets callers walk selectively (e.g. stop descending at nested loops) while still relying on this module’s single source of truth for each variant’s children.
walk_children
Recurse into node’s children without re-visiting node itself. 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 program in pre-order, invoking visitor on each.