Live data from Hacker News

Rust-sitter: Define your entire tree-sitter grammar in Rust code

github.com

11–16 of 16 posts

Re: Rust-sitter: Define your entire tree-sitter grammar in Rust code

#11
post #6
post #4

Earlier quoted context omitted.

Great project! I'm curious about the set of available parser annotations. I went through the list but I didn't see anything which allows for optional elements. One example would be dangling commas. Did I miss it or are there plans to support such constructs?

We support optional elements by wrapping them in `Option ` (other annotations are applied to the contents of the option)! So you can define struct ... { ... #[rust_sitter::leaf(text = ",") _dangling_comma: Option }

Perfect, thanks!

Re: Rust-sitter: Define your entire tree-sitter grammar in Rust code

#14

I'm super excited about the ability to get good quality bindings to tree-sitter! Tree-sitter is a very cool project but it needs a little love in a few regards. A better WebAssembly story, good bindings, and the ability to construct trees synthetically (to facilitate code generation) would make it a really remarkable tool. As for rust-sitter, it's a very promising direction. The error story needs a little work. I fou…

Yeah, definitely agree on WebAssembly! We have https://github.com/shadaj/tree-sitter-c2rust for running Tree Sitter on WASM via Rust, but definitely more potential in that direction. And very much agree on the error story needing work, right now it's mostly `panic`s everywhere and could definitely be improved with richer diagnostics.

Re: Rust-sitter: Define your entire tree-sitter grammar in Rust code

#15
post #13

does it support callbacks to handle semantic space languages like haskell and python?

Not yet, but this is something I've been investigating. The general plan is to have safe Rust bindings to the underlying Tree Sitter APIs used by custom scanners, and then have the Rust Sitter proc macro expose a Rust scanner as an `extern` function that the Tree Sitter runtime can call back to.

Re: Rust-sitter: Define your entire tree-sitter grammar in Rust code

#16
post #5

Earlier quoted context omitted.

Yes! Right now, the main benefits are the ability to write grammar definitions that are quite close to the ideal AST structure (made possible by Tree Sitter's grammar format), and being able to embed the parser in many different applications (including WASM via https://github.com/shadaj/tree-sitter-c2rust ). Rust Sitter also gives quite nice error diagnostics with spans thanks to Tree Sitter's recovery logic. Fallibl…

I would like to delve into the compatibility with tree-sitter, since in other features tree-sitter being under the hood is mostly an implementation detail: If I were to write my parser using rust-sitter, would I be able to still generate the final standalone tree-sitter parser as a `.so`? That way I could integrate with tools supporting tree-sitter parsers (for instance https://github.com/nvim-treesitter/nvim-treesit…

In principle, yes, you can use the `rust-sitter-tool` crate to generate the Tree Sitter JSON definition and then compile it to a standalone parser. The grammar is auto-generated though so it may be a bit trickier to integrate into other tooling? The general problem of exporting just the grammar is something that's been on my radar, but haven't had a chance to think through it too deeply yet.
Post reply on HN