Skip to content

Commit

Permalink
Bump tree-sitter Rust dep to 0.23 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
BekaValentine authored Sep 26, 2024
1 parent 9586f38 commit 57c9951
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 31 deletions.
56 changes: 43 additions & 13 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.20.0"
tree-sitter-language = "0.1.0"

[dev-dependencies]
tree-sitter = "0.23"

[build-dependencies]
cc = "1.0"
44 changes: 27 additions & 17 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
//! This crate provides gleam language support for the [tree-sitter][] parsing library.
//! This crate provides Gleam 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:
//!
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_gleam::language()).expect("Error loading gleam grammar");
//! use tree_sitter::Parser;
//!
//! let code = r#"
//! import gleam/io
//!
//! pub fn main() {
//! io.println("hello, friend!")
//! }
//! "#;
//! let mut parser = Parser::new();
//! let language = tree_sitter_gleam::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading Gleam 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_gleam() -> Language;
fn tree_sitter_gleam() -> *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_gleam() }
}
/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_gleam) };

/// 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");

// Uncomment these to include any queries that this grammar contains
/// The syntax highlighting query for this language.
pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");

pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// 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 +56,7 @@ mod tests {
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading gleam language");
.set_language(&super::LANGUAGE.into())
.expect("Error loading Gleam parser");
}
}

0 comments on commit 57c9951

Please sign in to comment.