diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-05-26 17:58:28 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-05-26 17:58:28 +0200 |
| commit | 6c354f9af1d6a79f80772ffec8c719469fd19d69 (patch) | |
| tree | 81630fdd769f5c1ff0c6473e187d610f4cbcf761 /tree-sitter-yts/bindings/rust/lib.rs | |
| parent | chore(version): v1.9.0 (diff) | |
| download | yt-6c354f9af1d6a79f80772ffec8c719469fd19d69.zip | |
build(tree-sitter-yts): Reduce bindings and update to latest tree-sitter version
Diffstat (limited to '')
| -rw-r--r-- | tree-sitter-yts/bindings/rust/lib.rs | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/tree-sitter-yts/bindings/rust/lib.rs b/tree-sitter-yts/bindings/rust/lib.rs index 0880238..35f14ce 100644 --- a/tree-sitter-yts/bindings/rust/lib.rs +++ b/tree-sitter-yts/bindings/rust/lib.rs @@ -1,54 +1,52 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. - -//! This crate provides yts language support for the [tree-sitter][] parsing library. +//! This crate provides YTS language support for the [tree-sitter] parsing library. //! -//! Typically, you will use the [language][language func] function to add this language to a -//! tree-sitter [Parser][], and then use the parser to parse some code: +//! Typically, you will use the [`LANGUAGE`] constant to add this language to a +//! tree-sitter [`Parser`], and then use the parser to parse some code: //! //! ``` -//! let code = ""; +//! let code = r#" +//! "#; //! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_yts::language()).expect("Error loading yts grammar"); +//! let language = tree_sitter_YTS::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading YTS parser"); //! let tree = parser.parse(code, None).unwrap(); +//! assert!(!tree.root_node().has_error()); //! ``` //! -//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -//! [language func]: fn.language.html -//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html +//! [`Parser`]: https://docs.rs/tree-sitter/0.26.8/tree_sitter/struct.Parser.html //! [tree-sitter]: https://tree-sitter.github.io/ -use tree_sitter::Language; +use tree_sitter_language::LanguageFn; extern "C" { - fn tree_sitter_yts() -> Language; + fn tree_sitter_YTS() -> *const (); } -/// Get the tree-sitter [Language][] for this grammar. -/// -/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -pub fn language() -> Language { - unsafe { tree_sitter_yts() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_YTS) }; -/// The content of the [`node-types.json`][] file for this grammar. +/// The content of the [`node-types.json`] file for this grammar. /// -/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types -pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); +/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types +pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); + +#[cfg(with_highlights_query)] +/// The syntax highlighting query for this grammar. +pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); + +#[cfg(with_injections_query)] +/// The language injection query for this grammar. +pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); -// Uncomment these to include any queries that this grammar contains +#[cfg(with_locals_query)] +/// The local variable query for this grammar. +pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); -// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); -// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); -// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); -// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); +#[cfg(with_tags_query)] +/// The symbol tagging query for this grammar. +pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); #[cfg(test)] mod tests { @@ -56,7 +54,7 @@ mod tests { fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser - .set_language(super::language()) - .expect("Error loading yts language"); + .set_language(&super::LANGUAGE.into()) + .expect("Error loading YTS parser"); } } |
