Code generation via AST

I want to generate Rust code from another language. I would like to generate some kind of AST, serialize it to JSON, and then somehow turn that into actual Rust source code that I can check into source control. What tools can I use to accomplish this?

To rephrase this in a hopefully clearer way:

Is there any existing tooling that can take a JSON AST (such as what's produced by clang's -ast-dump=json) and spit out Rust source code?

You may be interested in a recent thread about going the other direction from Rust to C

It's a lot more complicated than you might expect to transpile between languages.

If you're primarily interested in generating struct definitions from C headers, bindgen can do that.

Ah, sorry for being unclear: I want to write code in another language that will output Rust, not transpile. I could spit out Rust source directly, but working with strings directly is a PITA.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.