What should I use in Rust? - In the past I've hacked away with nom, syn, quote, and prettyplease… it would be nice to see a higher level API that enables:
parsing—without evaluation—and emission of the following:
derives and other macros
imports (use)
structs
impl blocks
fnprototypes (I don't care about body-parsing, just want to understand the interface and be able to replace the interface and push the body back verbatim)
Yeah tree-sitter isn't bad. I tried contributing back in 2022; to no avail. Here I am asking just about Rust not about any other language. But yes, you are correct, tree-sitter would still be a viable option.
(keeping this forum thread open so others can contribute further suggestions)
I've linked the Rust syntax implementation for tree-sitter above. Is tree-sitter's generic tree structure not sufficient enough / clunky to use in your scenario? I haven't built anything with tree-sitter yet (hopefully in the near future though—as of late I'm trying really hard to formulate problems at work in terms of context-free grammars, just so I can use a parser to solve them), so I'm curious about your setup and how tree-sitter fits as a possible solution.
TL;DR - tree-sitter is decent, but very generic. So you could take it as the base for a more specific; say mutating visitor pattern; API that would actually be usable.
Look at the other language AST libraries I linked and what functions that expose; compare this to what tree-sitter exposes. Very different.
Tree-sitter was originally created for IDE purposes (think JSON-RPC LangServ stuff like: rename, move, syntax highlight SQL within string of different programming language, etc.); whereas my interest is in understanding structs and function prototypes then transforming these betwixt eachother and to/fro JSON-schema and OpenAPI more broadly.
TBH, if you're emitting things that you want to be more stable, consider instead starting from an IDL and generating the rust code, rather than the other way around. That's often much easier.
(static) from new parsing [static analysis] of codebase, focussing on diesel struct and utoipa::path decorated actix-web routes
So with that in mind; much like my Python and C implementations; my Rust implementation must be whitespace and comment aware, yet work at a high enough level to be ergonomic.
Note that you canuse syn to parse raw strings, so it may be a good option to get going quickly, especially as it's already set up to quasi-quote etc. with quote