diff --git a/Cargo.toml b/Cargo.toml index 86e2156..5f6e1a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,10 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = ">=0.21.0" +tree-sitter-language = "0.1.0" [build-dependencies] cc = "1.0.91" + +[dev-dependencies] +tree-sitter = "0.23.0" diff --git a/bindings/go/binding_test.go b/bindings/go/binding_test.go index 21d9ac9..41ec660 100644 --- a/bindings/go/binding_test.go +++ b/bindings/go/binding_test.go @@ -3,7 +3,7 @@ package tree_sitter_java_test import ( "testing" - tree_sitter "github.com/smacker/go-tree-sitter" + tree_sitter "github.com/tree-sitter/go-tree-sitter" tree_sitter_java "github.com/tree-sitter/tree-sitter-java/bindings/go" ) diff --git a/bindings/node/binding_test.js b/bindings/node/binding_test.js new file mode 100644 index 0000000..afede30 --- /dev/null +++ b/bindings/node/binding_test.js @@ -0,0 +1,9 @@ +/// + +const assert = require("node:assert"); +const { test } = require("node:test"); + +test("can load grammar", () => { + const parser = new (require("tree-sitter"))(); + assert.doesNotThrow(() => parser.setLanguage(require("."))); +}); diff --git a/bindings/python/tests/test_binding.py b/bindings/python/tests/test_binding.py new file mode 100644 index 0000000..041d148 --- /dev/null +++ b/bindings/python/tests/test_binding.py @@ -0,0 +1,11 @@ +from unittest import TestCase + +import tree_sitter, tree_sitter_java + + +class TestLanguage(TestCase): + def test_can_load_grammar(self): + try: + tree_sitter.Language(tree_sitter_java.language()) + except Exception: + self.fail("Error loading Java grammar") diff --git a/bindings/python/tree_sitter_java/binding.c b/bindings/python/tree_sitter_java/binding.c index 23b76d0..30386f9 100644 --- a/bindings/python/tree_sitter_java/binding.c +++ b/bindings/python/tree_sitter_java/binding.c @@ -4,8 +4,8 @@ typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_java(void); -static PyObject* _binding_language(PyObject *self, PyObject *args) { - return PyLong_FromVoidPtr(tree_sitter_java()); +static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_java(), "tree_sitter.Language", NULL); } static PyMethodDef methods[] = { diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index d5ab2df..86b9f8b 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -4,6 +4,9 @@ fn main() { let mut c_config = cc::Build::new(); c_config.std("c11").include(src_dir); + #[cfg(target_env = "msvc")] + c_config.flag("-utf-8"); + let parser_path = src_dir.join("parser.c"); c_config.file(&parser_path); println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 13895e7..d66d2c7 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,6 +1,6 @@ //! This crate provides Java language support for the [tree-sitter][] parsing library. //! -//! Typically, you will use the [language][language func] function to add this grammar to a +//! 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: //! //! ``` @@ -14,7 +14,10 @@ //! } //! "#; //! let mut parser = Parser::new(); -//! parser.set_language(&tree_sitter_java::language()).expect("Error loading Java grammar"); +//! let language = tree_sitter_java::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading Java parser"); //! let tree = parser.parse(code, None).unwrap(); //! assert!(!tree.root_node().has_error()); //! ``` @@ -24,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_java() -> Language; + fn tree_sitter_java() -> *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_java() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_java) }; /// The content of the [`node-types.json`][] file for this grammar. /// @@ -51,10 +50,10 @@ pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); #[cfg(test)] mod tests { #[test] - fn can_load_grammar() { + fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser - .set_language(&super::language()) - .expect("Error loading Java grammar"); + .set_language(&super::LANGUAGE.into()) + .expect("Error loading Java parser"); } } diff --git a/bindings/swift/TreeSitterJavaTests/TreeSitterJavaTests.swift b/bindings/swift/TreeSitterJavaTests/TreeSitterJavaTests.swift new file mode 100644 index 0000000..63c457f --- /dev/null +++ b/bindings/swift/TreeSitterJavaTests/TreeSitterJavaTests.swift @@ -0,0 +1,12 @@ +import XCTest +import SwiftTreeSitter +import TreeSitterJava + +final class TreeSitterJavaTests: XCTestCase { + func testCanLoadGrammar() throws { + let parser = Parser() + let language = Language(language: tree_sitter_java()) + XCTAssertNoThrow(try parser.setLanguage(language), + "Error loading Java grammar") + } +} diff --git a/go.mod b/go.mod index a1887c2..25c3f4d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/tree-sitter/tree-sitter-java -go 1.22 +go 1.23 -require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 +require github.com/tree-sitter/go-tree-sitter v0.23.1 + +require github.com/mattn/go-pointer v0.0.1 // indirect diff --git a/grammar.js b/grammar.js index 3c568ab..37d17bb 100644 --- a/grammar.js +++ b/grammar.js @@ -199,7 +199,7 @@ module.exports = grammar({ string_fragment: _ => token.immediate(prec(1, /[^"\\]+/)), _multiline_string_fragment: _ => choice( /[^"\\]+/, - seq(/"([^"\\]|\\")*/), + /"([^"\\]|\\")*/, ), string_interpolation: $ => seq( diff --git a/package.json b/package.json index 2338b72..f318940 100644 --- a/package.json +++ b/package.json @@ -45,12 +45,10 @@ }, "scripts": { "install": "node-gyp-build", - "prebuildify": "prebuildify --napi --strip", - "build": "tree-sitter generate --no-bindings", - "build-wasm": "tree-sitter build --wasm", "lint": "eslint grammar.js", - "parse": "tree-sitter parse", - "test": "tree-sitter test" + "prestart": "tree-sitter build --wasm", + "start": "tree-sitter playground", + "test": "node --test bindings/node/*_test.js" }, "tree-sitter": [ { diff --git a/pyproject.toml b/pyproject.toml index 74f8258..67a1ea6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ authors = [ { name = "Max Brunsfeld", email = "maxbrunsfeld@gmail.com" }, { name = "Amaan Qureshi", email = "amaanq12@gmail.com" }, ] -requires-python = ">=3.8" +requires-python = ">=3.9" license.text = "MIT" readme = "README.md" @@ -30,5 +30,5 @@ Homepage = "https://github.com/tree-sitter/tree-sitter-java" core = ["tree-sitter~=0.21"] [tool.cibuildwheel] -build = "cp38-*" +build = "cp39-*" build-frontend = "build"