Skip to content

Commit

Permalink
Merge pull request #124 from wetneb/tree-sitter-0.23
Browse files Browse the repository at this point in the history
feat: upgrade tree-sitter to 0.23
  • Loading branch information
Mic92 authored Jan 13, 2025
2 parents 21897cc + c32d58a commit 4b952d9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
41 changes: 28 additions & 13 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,37 @@
//! 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
//! [language func]: fn.language.html
//! [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.
///
Expand All @@ -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)]
Expand All @@ -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");
}
}
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4b952d9

Please sign in to comment.