From b1362598f640c8f4b9376cc661bd7429665d159d Mon Sep 17 00:00:00 2001 From: totodore Date: Thu, 21 Aug 2025 00:04:46 +0200 Subject: [PATCH 1/3] feat: add rust bindings --- .gitignore | 3 ++- Cargo.toml | 10 ++++------ bindings/rust/build.rs | 9 +++++++++ bindings/rust/lib.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 bindings/rust/build.rs create mode 100644 bindings/rust/lib.rs diff --git a/.gitignore b/.gitignore index de2e14a..ce23b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules -bindings build testfile log.html +target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index ec3bb2c..c161a3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,7 @@ edition = "2018" license = "MIT" build = "bindings/rust/build.rs" -include = [ - "bindings/rust/*", - "grammar.js", - "queries/*", - "src/*", -] +include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] [lib] path = "bindings/rust/lib.rs" @@ -22,5 +17,8 @@ path = "bindings/rust/lib.rs" [dependencies] tree-sitter-language = "0.1.0" +[dev-dependencies] +tree-sitter = "0.25" + [build-dependencies] cc = "1.0" diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs new file mode 100644 index 0000000..2e5d5cd --- /dev/null +++ b/bindings/rust/build.rs @@ -0,0 +1,9 @@ +fn main() { + // Tell Cargo to rerun this build script if parser.c changes + println!("cargo:rerun-if-changed=src/parser.c"); + + cc::Build::new() + .file("src/parser.c") + .include("src/tree_sitter") + .compile("tree-sitter-http"); +} diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs new file mode 100644 index 0000000..67c62cf --- /dev/null +++ b/bindings/rust/lib.rs @@ -0,0 +1,27 @@ +use tree_sitter_language::LanguageFn; + +extern "C" { + fn tree_sitter_http() -> *const (); +} + +/// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar. +/// +/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_http) }; + +/// The syntax highlighting query for this language. +pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); + +/// The injections query for this language. +pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); + +#[cfg(test)] +mod tests { + #[test] + fn test_can_load_grammar() { + let mut parser = tree_sitter::Parser::new(); + parser + .set_language(&super::LANGUAGE.into()) + .expect("Error loading Rust parser"); + } +} From 949f500eb83a1497f751ce6040b304b8a33069aa Mon Sep 17 00:00:00 2001 From: totodore Date: Thu, 21 Aug 2025 00:07:29 +0200 Subject: [PATCH 2/3] feat: add rust bindings --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c161a3e..9a6c52b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ version = "0.0.1" keywords = ["incremental", "parsing", "http"] categories = ["parsing", "text-editors"] repository = "https://github.com/tree-sitter/tree-sitter-javascript" -edition = "2018" +edition = "2024" license = "MIT" build = "bindings/rust/build.rs" @@ -15,7 +15,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter-language = "0.1.0" +tree-sitter-language = "0.1" [dev-dependencies] tree-sitter = "0.25" From 453876beabf8db1a4a4f6c7a18e6a95614bc4980 Mon Sep 17 00:00:00 2001 From: totodore Date: Thu, 21 Aug 2025 00:08:01 +0200 Subject: [PATCH 3/3] feat: add rust bindings --- bindings/rust/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 67c62cf..496c5c5 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,6 +1,6 @@ use tree_sitter_language::LanguageFn; -extern "C" { +unsafe extern "C" { fn tree_sitter_http() -> *const (); }