I finally got around to wrapping up and publishing a first version of my #Rust crate ts-typed-ast. It's a crate inspired by Rowan that automatically generates a typed AST from a tree-sitter grammar. You can find it here: https://crates.io/crates/ts-typed-ast
It works similarly to Rowan and Swift's libsyntax. tree-sitter provides the green nodes, while this crate generates the red nodes.
I've used it a few times already, to prototype various toy programming languages. You write a grammar in tree-sitter, and then either evaluate the ts-typed-ast tree directly, or convert it to some other IR.
Using tree-sitter as the parser generator for a toy project is pretty nice. You get a powerful, declarative way to create a parser, and at the same time you benefit from the whole tree-sitter ecosystem. Things like incremental parsing, syntax highlighting, structural editing, and formatting with Topiary.
Main downside is that tree-sitter does not (yet) offer good error reporting and recovery, so when parsing fails it's often in dramatic, unhelpful ways. Not a big issue for experimenting, which is what this crate is for. Production-ready languages probably need bespoke parsers anyway.
#parser #treesitter #pl #programming