#node #tree-sitter #typed #generate #grammar #wrapper #bindings-generator

app type-sitter-cli

CLI for type-sitter (generate typed wrappers for tree-sitter grammars from node-types.json and queries)

11 unstable releases (5 breaking)

0.6.0 Nov 30, 2024
0.5.3 Nov 25, 2024
0.5.2 Oct 20, 2024
0.4.0 Apr 1, 2024
0.1.2 May 8, 2023

#26 in Programming languages

Download history 5/week @ 2024-09-20 3/week @ 2024-09-27 1/week @ 2024-10-04 288/week @ 2024-10-18 17/week @ 2024-10-25 1/week @ 2024-11-01 124/week @ 2024-11-22 154/week @ 2024-11-29 68/week @ 2024-12-06

346 downloads per month

MIT/Apache

2MB
39K SLoC

type-sitter-cli: Command-line utility to generate source files with type-sitter wrappers

crates.io

See type-sitter for background information, and type-sitter#cli-tool for a guide on how to use that applied to most cases. This is the command-line tool which generates typed-safe wrappers for tree-sitter nodes.

Advanced usage

Remember, if -o isn't specified it defaults to src/type_sitter.

# Generate bindings for the `yak-sitter` feature
type-sitter-cli vendor/tree-sitter-foobar-lang --use-yak-sitter
echo "pub mod foobar_lang;\n" > src/type_sitter.rs
# You can generate bindings for multiple grammars in the same directory
type-sitter-cli vendor/tree-sitter-typescript --use-yak-sitter
echo "pub mod typescript;\n" >> src/type_sitter.rs
# Generate only node types or queries
type-sitter-cli vendor/tree-sitter-rust/src/node-types.json --use-yak-sitter
echo "pub mod rust;\n" >> src/type_sitter.rs  # src/type_sitter/rust.rs contains only node types
type-sitter-cli vendor/tree-sitter-json/queries/json --use-yak-sitter
echo "pub mod json;\n" >> src/type_sitter.rs  # src/type_sitter/json.rs contains only queries
# To see help for the CLI program
type-sitter-cli --help

Issues

  • Q: I can't import the generated sources.
  • A: type-sitter-cli doesn't generate the root module for generated sources itself, you must do so manually. e.g. if the root module is the default (src/type_sitter), either create src/type_sitter.rs or src/type_sitter/mod.rs and add pub mod <my_language>; to it.

  • Q: I get build errors for missing symbols within type_sitter.
  • A: Make sure you have the type-sitter dependency in your Cargo.toml. Also, make sure use-default-features is set to false, because the default features includes the proc macros, which the CLI is an alternative to.

  • Q: I get build errors for symbols within tree-sitter.
  • A: Make sure you are using tree-sitter 0.22.

Dependencies

~8–17MB
~191K SLoC