rnix-parser icon indicating copy to clipboard operation
rnix-parser copied to clipboard

Example of modifying an AST

Open abhillman opened this issue 1 year ago • 2 comments

Description

Some basic code that demonstrates modifying an AST.

Considered alternatives

Poking around, playing with various things, reading tests -- currently doing that.

Additional context

An example could look something like this:

fn main() {
    let parse: rnix::Parse<rnix::Root> = rnix::Root::parse("\"hello world!\"");
    if !parse.errors().is_empty() { panic!(); }
    let syntax_node: rnix::SyntaxNode = parse.syntax();
    // modify the ast and call `println!("Modified: {}", syntax_node_modified);`
    println!("Original: {}", syntax_node);
}

abhillman avatar May 07 '24 22:05 abhillman