tss
Generated node type enums and metadata from tree-sitter languages.
Convenience crate
This is a convenience wrapper if you are using multiple crates, or just want to switch between languages easily.
Whereas the individual language crates provide NodeType, this crate re-exports each language you
configure in via the features with the language name appended in Pascal case
So the Rust language tree-sitter-rust crate NODE_TYPES constant shipped as NodeType in
tss-rust as tree_sitter_symbols_rust::NodeType is re-exported in tss as
tree_sitter_symbols::NodeTypeRust. Distinctly named types can reduce the ability to get confused
about which you're working with when handling tree-sitter parse trees in multiple languages.
Usage
[]
= { = "0.1", = ["lang-rust"] }
= "0.24"
= "0.24"
use NodeTypeRust;
use FromStr;
let node_type = from_str?;
assert_eq!;
assert_eq!;
I might change this to be modules that always re-export the name NodeType in future.
Features
Default includes all languages:
[]
# Convenience features
= ["lang-all"]
= ["lang-rust"]
# Language features
= ["dep:tss-rust"]
# ...
You can override that to select particular languages:
= { = "0.1", = false, = ["lang-rust"] }
For all available metadata features see the repo Cargo.toml.
How It Works
At build time, each language reads the corresponding tree-sitter-* language crate's NODE_TYPES constant and generates:
- A
NodeTypeenum with all node types FromStrfor parsing node type stringsDisplayfor converting back to strings- Documentation linking to language reference (best effort, not comprehensive)
This allows a crate to ship this information as an enum type with zero runtime dependencies. All generation happens at compile time. This is useful for type safety (rather than checking for strings, as well as hopefully to demystify how tree-sitter languages work.
Licensing
MIT licensed - see LICENSE for details.