From 9cb3ffe8bbd2fa8fb42428ebc28e027fa2542dbc Mon Sep 17 00:00:00 2001 From: Rebecca Valentine Date: Thu, 26 Sep 2024 11:12:16 -0700 Subject: [PATCH 1/2] Bumps tree-sitter to 0.23 --- Cargo.lock | 1 + Cargo.toml | 5 ++++- bindings/rust/lib.rs | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6597820..c0b5d24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,4 +92,5 @@ version = "0.0.1" dependencies = [ "cc", "tree-sitter", + "tree-sitter-language", ] diff --git a/Cargo.toml b/Cargo.toml index ae8a104..c58d561 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,10 @@ include = [ path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "0.24" +tree-sitter-language = "0.1.0" + +[dev-dependencies] +tree-sitter = ">=0.23" [build-dependencies] cc = "1.0" diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index d334201..3ec0f2b 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -4,10 +4,22 @@ //! tree-sitter [Parser][], and then use the parser to parse some code: //! //! ``` -//! let code = ""; -//! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(&tree_sitter_nix::language()).expect("Error loading nix grammar"); +//! use tree_sitter::Parser; +//! +//! let code = r#" +//! let +//! b = a + 1; +//! a = 1; +//! in +//! a + b +//! "#; +//! let mut parser = Parser::new(); +//! let language = tree_sitter_nix::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading nix 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 @@ -15,18 +27,14 @@ //! [Parser]: https://docs.rs/tree-sitter/*/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_nix() -> Language; + fn tree_sitter_nix() -> *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_nix() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_nix) }; /// The content of the [`node-types.json`][] file for this grammar. /// @@ -35,9 +43,16 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); // Uncomment these to include any queries that this grammar contains +/// The syntax highlighting query for this language. pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); + +// The injections query for this language. // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); + +// The locals tagging query for this language. // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); + +/// The symbol tagging query for this language. // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); #[cfg(test)] @@ -46,7 +61,7 @@ mod tests { fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser - .set_language(&super::language()) - .expect("Error loading nix language"); + .set_language(&super::LANGUAGE.into()) + .expect("Error loading nix parser"); } } From c32d58a8da40ac0385c032c54716be7cc20a13e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 13 Jan 2025 15:04:26 +0100 Subject: [PATCH 2/2] fix github matrix --- flake.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/flake.nix b/flake.nix index f1ebd25..f12976e 100644 --- a/flake.nix +++ b/flake.nix @@ -108,6 +108,12 @@ githubActions = nix-github-actions.lib.mkGithubMatrix { # Inherit GHA actions matrix from a subset of platforms supported by hosted runners + platforms = { + "x86_64-linux" = "nscloud-ubuntu-22.04-amd64-4x16"; + "x86_64-darwin" = "macos-13"; + "aarch64-darwin" = "macos-latest"; + "aarch64-linux" = "nscloud-ubuntu-22.04-arm64-4x16"; + }; checks = { inherit (self.checks) x86_64-linux;