https://github.com/Slowki/tree-sitter-languages-rs
A Rust crate to download and link Tree-sitter grammars
https://github.com/Slowki/tree-sitter-languages-rs
tree-sitter
Last synced: over 1 year ago
JSON representation
A Rust crate to download and link Tree-sitter grammars
- Host: GitHub
- URL: https://github.com/Slowki/tree-sitter-languages-rs
- Owner: Slowki
- License: other
- Created: 2019-06-08T03:57:33.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-08T15:36:17.000Z (about 7 years ago)
- Last Synced: 2025-02-10T06:24:25.956Z (over 1 year ago)
- Topics: tree-sitter
- Language: Rust
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# `tree-sitter-languages`
A library to download and link [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) [grammars](https://tree-sitter.github.io/tree-sitter/using-parsers).
## Usage
### Example Crate
For an example, see the example crate in [`./example`](./example)
### `Cargo.toml`
Add this crate to your dependencies
```toml
tree-sitter = ""
# Replace the features array with an array of whichever grammars you want to enable
tree-sitter-languages = { git = "https://github.com/Slowki/tree-sitter-languages-rs.git", features = ["rust", "python"] }
```
### Feature Flags
This crate has 3 features flags for each supported language:
* `-latest` (example: `rust-latest`): Use the latest tagged version for a given grammar
* `-master` (example: `rust-master`): Use the master branch for a given grammar
* `` (example: `rust`): An alias for `-latest`
You can also enable every language by using the `all` feature, which enables the `-latest` feature for each grammar.
### Using the Grammars
```rust
use tree_sitter_languages::{python_is_available};
fn main() {
//...
// A _is_available macro is generated for each grammar
if python_is_available!() {
// A get_ function is generated for each grammar, it returns a normal Tree-sitter
// Language object which can be used by tree_sitter::Parser
let language: tree_sitter::Language = tree_sitter_languages::get_python();
// ...
}
//...
}
```