sigil-stitch 0.5.2

Type-safe, import-aware, width-aware code generation for multiple languages
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::code_node::CodeNode;

/// Recursively apply a rewrite function to all node vectors in the tree.
///
/// Visits the given `nodes` first, then recurses into any `Nested(CodeBlock)`
/// or `Sequence(Vec<CodeNode>)` children.
pub fn walk_nodes_mut(nodes: &mut Vec<CodeNode>, f: &dyn Fn(&mut Vec<CodeNode>)) {
    f(nodes);
    for node in nodes.iter_mut() {
        match node {
            CodeNode::Nested(block) => walk_nodes_mut(block.nodes_mut(), f),
            CodeNode::Sequence(children) => walk_nodes_mut(children, f),
            _ => {}
        }
    }
}