3 ms·
The generated parsers are implemented in C, and so currently the only way to use them is via FFI. (Unless you're writing your analysis tool itself in C!) The `
by dcreager 5y ago
The generated parsers are implemented in C, and so currently the only way to use them is via FFI. (Unless you're writing your analysis tool itself in C!)
The `tree-sitter generate` command also produces a full description of the grammar itself (typically written to src/grammar.json). In theory you could use this to generate each grammar implementation in other languages, as well. No one has tackled this yet, though, because in practice it has worked well enough to FFI in the C parser implementations.
Also, depending on what language you're trying to consume tree-sitter parsers in, we're trying to leverage the language's package ecosystem as much as we can to simplify this process. If you're using Rust, for instance, we publish crates for tree-sitter itself [1] and for various language grammars [2,3,4]. So you can often just add some dependencies to your Cargo.toml and the Rust build system takes care of everything for you. (Note that these crates also provide a more Rust-idiomatic API, instead of making you call the FFI'ed C functions directly.)
[1] https://crates.io/crates/tree-sitter https://crates.io/crates/tree-sitter
[2] https://crates.io/crates/tree-sitter-python https://crates.io/crates/tree-sitter-python
[3] https://crates.io/crates/tree-sitter-javascript https://crates.io/crates/tree-sitter-javascript
[4] https://crates.io/crates/tree-sitter-ruby https://crates.io/crates/tree-sitter-ruby
- josteink 5y ago> No one has tackled this yet, though, because in practice it has worked well enough to FFI in the C parser implementations. The only issue I’ve come up with so far is a very distinct lack of ARM(64) support in precompiled binaries for FOSS-projects using tree-sitter. One risks having to manually set up rust and build it yourself on your ARM-host (if your host is capable of that and your host-environment allows it), because currently there’s no easy way to cross-compile it, despite being largely rust-based: https://github.com/tree-sitter/tree-sitter/issues/1366 https://github.com/tree-sitter/tree-sitter/issues/1366 It’s literally the only thing I have not working on in my otherwise very portable Emacs-setup when deployed on an ARM host, so for me it kinda stands out.
- siraben 5y agoUsing Nix and home-manager I'm able to have this setup with Emacs work across Linux and macOS (x86 and arm64) because it compiles the grammars from Nixpkgs itself (the grammar list can also be augmented declaratively with other grammars). [0] https://github.com/siraben/dotfiles/blob/a0f49781ecb05693908f265d643d97f3cd0d4d95/home-manager/.config/nixpkgs/home.nix#L39 https://github.com/siraben/dotfiles/blob/a0f49781ecb05693908...
- josteink 5y agoThat’s a bit above my head, but if you could contribute with a “from scratch” ARM64 cross-build recipe for tree-sitter, in the official repo, that would be great!