Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of modifying an AST #162

Open
abhillman opened this issue May 7, 2024 · 2 comments
Open

Example of modifying an AST #162

abhillman opened this issue May 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@abhillman
Copy link

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 abhillman added the enhancement New feature or request label May 7, 2024
@abhillman abhillman changed the title Example of _modifying_ an AST Example of modifying an AST May 7, 2024
@abhillman
Copy link
Author

Related #151 (comment)

@oberblastmeister
Copy link
Contributor

rust-analyzer has a good example for this https://github.com/rust-lang/rust-analyzer/blob/master/crates/syntax/src/ted.rs

I wonder if we should add an interface like that.

An example to modify the syntax tree would also be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants