diff --git a/Cargo.lock b/Cargo.lock index 9d25483..a246eee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,30 +4,45 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "cc" -version = "1.0.72" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +dependencies = [ + "shlex", +] [[package]] name = "memchr" -version = "2.4.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "regex" -version = "1.5.4" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -36,24 +51,39 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "shlex" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "tree-sitter" -version = "0.20.2" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36be3222512d85a112491ae0cc280a38076022414f00b64582da1b7565ffd82" +checksum = "20f4cd3642c47a85052a887d86704f4eac272969f61b686bdd3f772122aabaff" dependencies = [ "cc", "regex", + "regex-syntax", + "tree-sitter-language", ] [[package]] name = "tree-sitter-gleam" -version = "0.27.0" +version = "1.0.0" dependencies = [ "cc", "tree-sitter", + "tree-sitter-language", ] + +[[package]] +name = "tree-sitter-language" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2545046bd1473dac6c626659cc2567c6c0ff302fc8b84a56c4243378276f7f57" diff --git a/Cargo.toml b/Cargo.toml index 78cf14d..0e5e6ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 0b43322..4de561c 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,13 +1,25 @@ -//! 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 @@ -15,29 +27,27 @@ //! [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)] @@ -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"); } }