3 ms·
@morgante Are you aware of any tools that do codegen from tree-sitter ASTs? A simple application would be to produce a code formatter like Black or ruff for py
by snthpy 3y ago
@morgante Are you aware of any tools that do codegen from tree-sitter ASTs?
A simple application would be to produce a code formatter like Black or ruff for python but which could support any tree-sitter supported language.
More specifically to my use case though, if I produced tree-sitter grammars with identical node structure and node names, e.g. for sqlite and postgresql, then wouldn't this make it simple to do full transpilation between the two?
- morgante 3y agoYou should check out https://github.com/tweag/topiary https://github.com/tweag/topiary Yes, theoretically if you had ~identical grammars you could use it to do a full transpilation. There's a lot of challenges with that though. Writing a correct grammar for 1 language is complicated enough, but writing one for two where all your nodes and fields end up the same is likely insurmountable. In practice, languages are either: - Far enough apart that any pure AST transformation is insufficient and you need an AI component to produce usable output - Close enough that you're better off just targeting the specific parts that differ and rewriting those while leaving the rest alone. I think GritQL can do well here.
- snthpy 3y agoAwesome, thanks. Big fan of the Tweag folks and Nix and Nickel so will definitely check it out.