diff --git a/.editorconfig b/.editorconfig index d3a8b5b6..f363cc55 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,9 +2,6 @@ root = true [*] charset = utf-8 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true [*.{json,toml,yml,gyp}] indent_style = space @@ -14,11 +11,11 @@ indent_size = 2 indent_style = space indent_size = 2 -[*.rs] +[*.{c,cc,h}] indent_style = space indent_size = 4 -[*.{c,cc,h}] +[*.rs] indent_style = space indent_size = 4 @@ -37,3 +34,6 @@ indent_size = 8 [Makefile] indent_style = tab indent_size = 8 + +[parser.c] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index ffb52abe..c2aadfdf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,12 @@ -* text eol=lf +* text=auto eol=lf -src/*.json linguist-generated -src/parser.c linguist-generated -src/tree_sitter/* linguist-generated +php/src/*.json linguist-generated +php/src/parser.c linguist-generated +php/src/tree_sitter/* linguist-generated + +php_only/src/*.json linguist-generated +php_only/src/parser.c linguist-generated +php_only/src/tree_sitter/* linguist-generated bindings/** linguist-generated binding.gyp linguist-generated diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a61f3e15..5bcac4d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: uses: tree-sitter/parser-test-action@v2 with: test-rust: ${{runner.os == 'Linux'}} + test-swift: ${{runner.os == 'macOS'}} - name: Parse examples id: test uses: tree-sitter/parse-action@v4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 103e92ae..11562607 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,18 +2,25 @@ name: Lint on: push: - branches: - - master + branches: [master] + paths: + - common/define-grammar.js pull_request: - branches: - - "**" + paths: + - common/define-grammar.js jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + cache: npm + node-version: ${{vars.NODE_VERSION}} - name: Install modules - run: npm install + run: npm ci --legacy-peer-deps - name: Run ESLint run: npm run lint diff --git a/.gitignore b/.gitignore index 27fc43f7..2fd9daca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Rust artifacts -Cargo.lock target/ # Node artifacts @@ -10,9 +9,9 @@ node_modules/ # Swift artifacts .build/ +Package.resolved # Go artifacts -go.sum _obj/ # Python artifacts diff --git a/Cargo.lock b/Cargo.lock index ad1de877..aa65d776 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,21 +13,24 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.96" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "regex" -version = "1.10.4" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -37,9 +40,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -48,24 +51,39 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +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 = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "tree-sitter" -version = "0.22.6" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca" +checksum = "20f4cd3642c47a85052a887d86704f4eac272969f61b686bdd3f772122aabaff" dependencies = [ "cc", "regex", + "regex-syntax", + "tree-sitter-language", ] +[[package]] +name = "tree-sitter-language" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2545046bd1473dac6c626659cc2567c6c0ff302fc8b84a56c4243378276f7f57" + [[package]] name = "tree-sitter-php" -version = "0.22.5" +version = "0.23.0" dependencies = [ "cc", "tree-sitter", + "tree-sitter-language", ] diff --git a/Cargo.toml b/Cargo.toml index 28007ede..01b5f6b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,10 @@ include = [ path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = ">=0.21.0" +tree-sitter-language = "0.1.0" [build-dependencies] -cc = "1.0.96" +cc = "1.1.15" + +[dev-dependencies] +tree-sitter = "0.23" diff --git a/Makefile b/Makefile index 9c137998..92000709 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +TS ?= tree-sitter + all install uninstall clean: $(MAKE) -C php $@ $(MAKE) -C php_only $@ diff --git a/Package.swift b/Package.swift index d55cf843..a93acb7d 100644 --- a/Package.swift +++ b/Package.swift @@ -6,12 +6,35 @@ let package = Package( products: [ .library(name: "TreeSitterPHP", targets: ["TreeSitterPHP"]), ], - dependencies: [], + dependencies: [ + .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"), + ], targets: [ .target( name: "TreeSitterPHP", path: ".", exclude: [ + "Cargo.toml", + "Makefile", + "binding.gyp", + "bindings/c", + "bindings/go", + "bindings/node", + "bindings/python", + "bindings/rust", + "prebuilds", + "grammar.js", + "package.json", + "package-lock.json", + "pyproject.toml", + "setup.py", + "test", + "examples", + ".editorconfig", + ".github", + ".gitignore", + ".gitattributes", + ".gitmodules", ], sources: [ "php/src/parser.c", @@ -24,6 +47,14 @@ let package = Package( ], publicHeadersPath: "bindings/swift", cSettings: [.headerSearchPath("php/src")] + ), + .testTarget( + name: "TreeSitterPHPTests", + dependencies: [ + "SwiftTreeSitter", + "TreeSitterPHP", + ], + path: "bindings/swift/TreeSitterPHPTests" ) ] ) diff --git a/binding.gyp b/binding.gyp index 4706cc89..10d8ba48 100644 --- a/binding.gyp +++ b/binding.gyp @@ -15,10 +15,18 @@ "php_only/src/scanner.c", "bindings/node/binding.cc", ], - "cflags_c": [ - "-std=c11", - "-Wno-unused-value", - ] + "conditions": [ + ["OS!='win'", { + "cflags_c": [ + "-std=c11", + ], + }, { # OS == "win" + "cflags_c": [ + "/std:c11", + "/utf-8", + ], + }], + ], } ] } diff --git a/bindings/go/binding_test.go b/bindings/go/binding_test.go index 86292e74..cfedf73f 100644 --- a/bindings/go/binding_test.go +++ b/bindings/go/binding_test.go @@ -3,7 +3,7 @@ package tree_sitter_php_test import ( "testing" - tree_sitter "github.com/smacker/go-tree-sitter" + tree_sitter "github.com/tree-sitter/go-tree-sitter" tree_sitter_php "github.com/tree-sitter/tree-sitter-php/bindings/go" ) diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc index 71b66bd4..322eabd4 100644 --- a/bindings/node/binding.cc +++ b/bindings/node/binding.cc @@ -7,7 +7,7 @@ extern "C" TSLanguage *tree_sitter_php_only(); // "tree-sitter", "language" hashed with BLAKE2 const napi_type_tag LANGUAGE_TYPE_TAG = { - 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 }; Napi::Object Init(Napi::Env env, Napi::Object exports) { diff --git a/bindings/node/binding_test.js b/bindings/node/binding_test.js new file mode 100644 index 00000000..c25e5ff2 --- /dev/null +++ b/bindings/node/binding_test.js @@ -0,0 +1,10 @@ +/// + +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(".").php)); + assert.doesNotThrow(() => parser.setLanguage(require(".").php_only)); +}); diff --git a/bindings/python/tests/test_binding.py b/bindings/python/tests/test_binding.py new file mode 100644 index 00000000..3124d213 --- /dev/null +++ b/bindings/python/tests/test_binding.py @@ -0,0 +1,12 @@ +from unittest import TestCase + +import tree_sitter, tree_sitter_php + + +class TestLanguage(TestCase): + def test_can_load_grammar(self): + try: + tree_sitter.Language(tree_sitter_php.language_php()) + tree_sitter.Language(tree_sitter_php.language_php_only()) + except Exception: + self.fail("Error loading PHP grammar") diff --git a/bindings/python/tree_sitter_php/__init__.py b/bindings/python/tree_sitter_php/__init__.py index 31718704..a0ab8e51 100644 --- a/bindings/python/tree_sitter_php/__init__.py +++ b/bindings/python/tree_sitter_php/__init__.py @@ -1,3 +1,31 @@ "PHP grammar for tree-sitter" +from importlib.resources import files as _files + from ._binding import language_php, language_php_only + + +def _get_query(name, file): + query = _files(f"{__package__}.queries") / file + globals()[name] = query.read_text() + return globals()[name] + + +def __getattr__(name): + if name == "HIGHLIGHTS_QUERY": + return _get_query("HIGHLIGHTS_QUERY", "highlights.scm") + if name == "INJECTIONS_QUERY": + return _get_query("INJECTIONS_QUERY", "injections.scm") + if name == "TAGS_QUERY": + return _get_query("TAGS_QUERY", "tags.scm") + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + + +__all__ = [ + "language_php", + "language_php_only", + "HIGHLIGHTS_QUERY", + "INJECTIONS_QUERY", + "TAGS_QUERY", +] diff --git a/bindings/python/tree_sitter_php/__init__.pyi b/bindings/python/tree_sitter_php/__init__.pyi index 6b4b7d57..a44ea2ef 100644 --- a/bindings/python/tree_sitter_php/__init__.pyi +++ b/bindings/python/tree_sitter_php/__init__.pyi @@ -1,3 +1,9 @@ +from typing import Final + +HIGHLIGHTS_QUERY: Final[str] +INJECTIONS_QUERY: Final[str] +TAGS_QUERY: Final[str] + def language_php() -> int: ... def language_php_only() -> int: ... diff --git a/bindings/python/tree_sitter_php/binding.c b/bindings/python/tree_sitter_php/binding.c index 4369fba1..972565f7 100644 --- a/bindings/python/tree_sitter_php/binding.c +++ b/bindings/python/tree_sitter_php/binding.c @@ -5,12 +5,12 @@ typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_php(void); TSLanguage *tree_sitter_php_only(void); -static PyObject* _binding_language_php(PyObject *self, PyObject *args) { - return PyLong_FromVoidPtr(tree_sitter_php()); +static PyObject* _binding_language_php(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_php(), "tree_sitter.Language", NULL); } -static PyObject* _binding_language_php_only(PyObject *self, PyObject *args) { - return PyLong_FromVoidPtr(tree_sitter_php_only()); +static PyObject* _binding_language_php_only(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_php_only(), "tree_sitter.Language", NULL); } static PyMethodDef methods[] = { diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 7f04bd70..c80e07fc 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -12,9 +12,10 @@ //! ?> //! "#; //! let mut parser = Parser::new(); +//! let language = tree_sitter_php::LANGUAGE_PHP; //! parser -//! .set_language(&tree_sitter_php::language_php()) -//! .expect("Error loading PHP grammar"); +//! .set_language(&language.into()) +//! .expect("Error loading PHP parser"); //! let tree = parser.parse(code, None).unwrap(); //! assert!(!tree.root_node().has_error()); //! ``` @@ -24,26 +25,18 @@ //! [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_php() -> Language; - fn tree_sitter_php_only() -> Language; + fn tree_sitter_php() -> *const (); + fn tree_sitter_php_only() -> *const (); } -/// Get the tree-sitter [Language][] for PHP. -/// -/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -pub fn language_php() -> Language { - unsafe { tree_sitter_php() } -} +/// The tree-sitter [`LanguageFn`] for PHP. +pub const LANGUAGE_PHP: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_php) }; -/// Get the tree-sitter [Language][] for PHP Only. -/// -/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -pub fn language_php_only() -> Language { - unsafe { tree_sitter_php_only() } -} +/// The tree-sitter [`LanguageFn`] for PHP-Only. +pub const LANGUAGE_PHP_ONLY: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_php_only) }; /// The content of the [`node-types.json`][] file for this grammar. /// @@ -66,7 +59,7 @@ mod tests { fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser - .set_language(&super::language_php()) - .expect("Error loading PHP grammar"); + .set_language(&super::LANGUAGE_PHP.into()) + .expect("Error loading PHP parser"); } } diff --git a/bindings/swift/TreeSitterPHPTests/TreeSitterPHPTests.swift b/bindings/swift/TreeSitterPHPTests/TreeSitterPHPTests.swift new file mode 100644 index 00000000..4e549117 --- /dev/null +++ b/bindings/swift/TreeSitterPHPTests/TreeSitterPHPTests.swift @@ -0,0 +1,15 @@ +import XCTest +import SwiftTreeSitter +import TreeSitterPHP + +final class TreeSitterPHPTests: XCTestCase { + func testCanLoadGrammar() throws { + let parser = Parser() + let language_php = Language(language: tree_sitter_php()) + XCTAssertNoThrow(try parser.setLanguage(language_php), + "Error loading PHP grammar") + let language_php_only = Language(language: tree_sitter_php_only()) + XCTAssertNoThrow(try parser.setLanguage(language_php_only), + "Error loading PHP-Only grammar") + } +} diff --git a/common/common.mak b/common/common.mak index 8ed8cf4b..39077b25 100644 --- a/common/common.mak +++ b/common/common.mak @@ -1,5 +1,11 @@ +ifeq ($(OS),Windows_NT) +$(error Windows is not supported) +endif + VERSION := 0.23.0 +LANGUAGE_NAME := tree-sitter-php + # repository SRC_DIR := src @@ -15,10 +21,6 @@ endif TS ?= tree-sitter -# ABI versioning -SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) -SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) - # install directory layout PREFIX ?= /usr/local INCLUDEDIR ?= $(PREFIX)/include @@ -34,27 +36,29 @@ OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) ARFLAGS ?= rcs override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC +# ABI versioning +SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) +SONAME_MINOR := $(shell sed -n 's/#define LANGUAGE_VERSION //p' $(PARSER)) + # OS-specific bits -ifeq ($(OS),Windows_NT) - $(error "Windows is not supported") -else ifeq ($(shell uname),Darwin) +ifeq ($(shell uname),Darwin) SOEXT = dylib - SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib - SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib + SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT) + SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT) LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, ifneq ($(ADDITIONAL_LIBS),) LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), endif - LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks + LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks else SOEXT = so - SOEXTVER_MAJOR = so.$(SONAME_MAJOR) - SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) + SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR) + SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR) LINKSHARED := $(LINKSHARED)-shared -Wl, ifneq ($(ADDITIONAL_LIBS),) LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) endif - LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR) + LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).$(SOEXTVER) endif ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) PCLIBDIR := $(PREFIX)/libdata/pkgconfig @@ -71,7 +75,7 @@ ifneq ($(STRIP),) $(STRIP) $@ endif -$(LANGUAGE_NAME).pc: ../bindings/c/$(LANGUAGE_NAME).pc.in +$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in sed -e 's|@URL@|$(PARSER_URL)|' \ -e 's|@VERSION@|$(VERSION)|' \ -e 's|@LIBDIR@|$(LIBDIR)|' \ @@ -81,14 +85,14 @@ $(LANGUAGE_NAME).pc: ../bindings/c/$(LANGUAGE_NAME).pc.in -e 's|=$(PREFIX)|=$${prefix}|' \ -e 's|@PREFIX@|$(PREFIX)|' $< > $@ -$(PARSER): grammar.js - $(TS) generate --no-bindings +$(PARSER): $(SRC_DIR)/grammar.json + $(TS) generate --no-bindings $^ install: all install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' - install -m644 ../bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h + install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc - install -m755 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a + install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) diff --git a/go.mod b/go.mod index 6a76073b..59281b47 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,9 @@ module github.com/tree-sitter/tree-sitter-php -go 1.22 +go 1.23 -require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 +toolchain go1.23.0 + +require github.com/tree-sitter/go-tree-sitter v0.23.1 + +require github.com/mattn/go-pointer v0.0.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..00687470 --- /dev/null +++ b/go.sum @@ -0,0 +1,34 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0= +github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tree-sitter/go-tree-sitter v0.23.1 h1:HCfaE19sKfG7q190xfM1loUZf6wEHa4TDqDEW46s9Lg= +github.com/tree-sitter/go-tree-sitter v0.23.1/go.mod h1:EvIVhMvvPNvhu9x+ddSPxSnUEU5AnsSwi1LMqXIVE3A= +github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb h1:A8425heRM8mylnv4H58FPUiH+aYivyitre0PzxrfmWs= +github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb/go.mod h1:dOF6gtQiF9UwNh995T5OphYmtIypkjsp3ap7r9AN/iA= +github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148 h1:AfFPZwtwGN01BW1jDdqBVqscTwetvMpydqYZz57RSlc= +github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148/go.mod h1:Bh6U3viD57rFXRYIQ+kmiYtr+1Bx0AceypDLJJSyi9s= +github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33 h1:TwqSV3qLp3tKSqirGLRHnjFk9Tc2oy57LIl+FQ4GjI4= +github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33/go.mod h1:CvCKCt3v04Ufos1zZnNCelBDeCGRpPucaN8QczoUsN4= +github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012 h1:Xvxck3tE5FW7F7bTS97iNM2ADMyCMJztVqn5HYKdJGo= +github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012/go.mod h1:T40D0O1cPvUU/+AmiXVXy1cncYQT6wem4Z0g4SfAYvY= +github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0 h1:c46K6uh5Dz00zJeU9BfjXdb8I+E4RkUdfnWJpQADXFo= +github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0/go.mod h1:hcNt/kOJHcIcuMvouE7LJcYdeFUFbVpBJ6d4wmOA+tU= +github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495 h1:jrt4qbJVEFs4H93/ITxygHc6u0TGqAkkate7TQ4wFSA= +github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495/go.mod h1:oyaR7fLnRV0hT9z6qwE9GkaeTom/hTDwK3H2idcOJFc= +github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5 h1:om4X9AVg3asL8gxNJDcz4e/Wp+VpQj1PY3uJXKr6EOg= +github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5/go.mod h1:nNqgPoV/h9uYWk6kYEFdEAhNVOacpfpRW5SFmdaP4tU= +github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5 h1:pfV3G3k7NCKqKk8THBmyuh2zA33lgYHS3GVrzRR8ry4= +github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5/go.mod h1:GbMKRjLfk0H+PI7nLi1Sx5lHf5wCpLz9al8tQYSxpEk= +github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb h1:EXEM82lFM7JjJb6qiKZXkpIDaCcbV2obNn82ghwj9lw= +github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb/go.mod h1:lXCF1nGG5Dr4J3BTS0ObN4xJCCICiSu/b+Xe/VqMV7g= +github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d h1:fcYCvoXdcP1uRQYXqJHRy6Hec+uKScQdKVtMwK9JeCI= +github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d/go.mod h1:T1nShQ4v5AJtozZ8YyAS4uzUtDAJj/iv4YfwXSbUHzg= +github.com/tree-sitter/tree-sitter-rust v0.21.3-0.20240818005432-2b43eafe6447 h1:o9alBu1J/WjrcTKEthYtXmdkDc5OVXD+PqlvnEZ0Lzc= +github.com/tree-sitter/tree-sitter-rust v0.21.3-0.20240818005432-2b43eafe6447/go.mod h1:1Oh95COkkTn6Ezp0vcMbvfhRP5gLeqqljR0BYnBzWvc= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/package-lock.json b/package-lock.json index af124b55..04d1abee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,12 +10,12 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { - "globals": "^15.4.0", - "node-addon-api": "^8.0.0", - "node-gyp-build": "^4.8.1" + "globals": "^15.9.0", + "node-addon-api": "^8.1.0", + "node-gyp-build": "^4.8.2" }, "devDependencies": { - "eslint": "^9.4.0", + "eslint": "^9.9.1", "eslint-config-google": "^0.14.0", "prebuildify": "^6.0.1", "tree-sitter-cli": "^0.23.0" @@ -24,7 +24,7 @@ "tree-sitter": "^0.21.1" }, "peerDependenciesMeta": { - "tree_sitter": { + "tree-sitter": { "optional": true } } @@ -73,7 +73,6 @@ "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", "dev": true, - "license": "Apache-2.0", "dependencies": { "@eslint/object-schema": "^2.1.4", "debug": "^4.3.1", @@ -125,7 +124,6 @@ "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.1.tgz", "integrity": "sha512-xIDQRsfg5hNBqHz04H1R3scSVwmI+KUbqjsQKHKQ1DAUSaUjYPReZZmS/5PNiKu1fUvzDd6H7DEDKACSEhu+TQ==", "dev": true, - "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -135,7 +133,6 @@ "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", "dev": true, - "license": "Apache-2.0", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -484,7 +481,6 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.1.tgz", "integrity": "sha512-dHvhrbfr4xFQ9/dq+jcVneZMyRYLjggWjk6RVsIiHsP8Rz6yZ8LvZ//iU4TrZF+SXWG+JkNF2OyiZRvzgRDqMg==", "dev": true, - "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", @@ -557,7 +553,6 @@ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", "integrity": "sha512-6E4xmrTw5wtxnLA5wYL3WDfhZ/1bUBGOXV0zQvVRDOtrR8D0p6W7fs3JweNYhwRYeGvd/1CKX2se0/2s7Q/nJA==", "dev": true, - "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" @@ -618,7 +613,6 @@ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, - "license": "BSD-2-Clause", "dependencies": { "estraverse": "^5.2.0" }, @@ -752,7 +746,6 @@ "version": "15.9.0", "resolved": "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz", "integrity": "sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA==", - "license": "MIT", "engines": { "node": ">=18" }, @@ -1017,16 +1010,14 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.1.0.tgz", "integrity": "sha512-yBY+qqWSv3dWKGODD6OGE6GnTX7Q2r+4+DfpqxHSHh8x0B4EKP9+wVGLS6U/AM1vxSNNmUEuIV5EGhYwPpfOwQ==", - "license": "MIT", "engines": { "node": "^18 || ^20 || >= 21" } }, "node_modules/node-gyp-build": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", - "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", - "license": "MIT", + "version": "4.8.2", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.2.tgz", + "integrity": "sha512-IRUxE4BVsHWXkV/SFOut4qTlagw2aM8T5/vnTsmrHJvVoKueJHRc/JaFND7QDDc61kLYUJ6qlZM3sqTSyx2dTw==", "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -1418,6 +1409,7 @@ "integrity": "sha512-7dxoA6kYvtgWw80265MyqJlkRl4yawIjO7S5MigytjELkX43fV2WsAXzsNfO7sBpPPCF5Gp0+XzHk0DwLCq3xQ==", "hasInstallScript": true, "license": "MIT", + "optional": true, "peer": true, "dependencies": { "node-addon-api": "^8.0.0", @@ -1430,7 +1422,6 @@ "integrity": "sha512-/DdQaPCCOrOYGp9FxGdhFUnHIrjhfbYatQXgNIcmaAOpPunpnDj2vsO/H+svsfQLaFsQ1C+BjgPhpbV28zka1w==", "dev": true, "hasInstallScript": true, - "license": "MIT", "bin": { "tree-sitter": "cli.js" }, diff --git a/package.json b/package.json index e32766fd..abe3b7b7 100644 --- a/package.json +++ b/package.json @@ -51,31 +51,30 @@ "common/**" ], "dependencies": { - "globals": "^15.4.0", - "node-addon-api": "^8.0.0", - "node-gyp-build": "^4.8.1" + "globals": "^15.9.0", + "node-addon-api": "^8.1.0", + "node-gyp-build": "^4.8.2" }, "peerDependencies": { "tree-sitter": "^0.21.1" }, "peerDependenciesMeta": { - "tree_sitter": { + "tree-sitter": { "optional": true } }, "devDependencies": { - "eslint": "^9.4.0", + "eslint": "^9.9.1", "eslint-config-google": "^0.14.0", "prebuildify": "^6.0.1", "tree-sitter-cli": "^0.23.0" }, "scripts": { "install": "node-gyp-build", - "prebuildify": "prebuildify --napi --strip", - "generate": "for dir in php php_only; do cd $dir && tree-sitter generate --no-bindings && cd ..; done", "lint": "eslint common/define-grammar.js", - "parse": "tree-sitter parse", - "test": "tree-sitter test" + "prestart": "tree-sitter build php --wasm -o php/tree-sitter-php.wasm", + "start": "tree-sitter playground --grammar-path php", + "test": "node --test bindings/node/*_test.js" }, "tree-sitter": [ { diff --git a/php/package.json b/php/package.json index 4820a82d..eba022a8 100644 --- a/php/package.json +++ b/php/package.json @@ -1,20 +1,3 @@ { - "main": "../bindings/node/php", - "tree-sitter": [ - { - "scope": "source.php", - "file-types": [ - "php" - ], - "highlights": "../queries/highlights.scm", - "injections": [ - "../queries/injections.scm", - "../queries/injections-text.scm" - ], - "tags": "../queries/tags.scm", - "external-files": [ - "../common/scanner.h" - ] - } - ] + "main": "../bindings/node/php" } diff --git a/php_only/package.json b/php_only/package.json index 622fd5b3..fcddd637 100644 --- a/php_only/package.json +++ b/php_only/package.json @@ -1,17 +1,3 @@ { - "main": "../bindings/node/php_only", - "tree-sitter": [ - { - "scope": "source.php", - "file-types": [ - "php" - ], - "highlights": "../queries/highlights.scm", - "injections": "../queries/injections.scm", - "tags": "../queries/tags.scm", - "external-files": [ - "../common/scanner.h" - ] - } - ] + "main": "../bindings/node/php_only" } diff --git a/pyproject.toml b/pyproject.toml index 7ecd4902..9325d5ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,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" @@ -29,5 +29,5 @@ Homepage = "https://github.com/tree-sitter/tree-sitter-php" core = ["tree-sitter~=0.21"] [tool.cibuildwheel] -build = "cp38-*" +build = "cp39-*" build-frontend = "build" diff --git a/setup.py b/setup.py index d5d1311a..f93261dd 100644 --- a/setup.py +++ b/setup.py @@ -18,13 +18,13 @@ class BdistWheel(bdist_wheel): def get_tag(self): python, abi, platform = super().get_tag() if python.startswith("cp"): - python, abi = "cp38", "abi3" + python, abi = "cp39", "abi3" return python, abi, platform setup( - packages=find_packages("bindings/python"), - package_dir={"": "bindings/python"}, + packages=find_packages("bindings/php"), + package_dir={"": "bindings/php"}, package_data={ "tree_sitter_php": ["*.pyi", "py.typed"], "tree_sitter_php.queries": ["*.scm"], @@ -42,12 +42,15 @@ def get_tag(self): ], extra_compile_args=[ "-std=c11", - "-Wno-unused-parameter", - "-Wno-unused-value", - ] if system() != "Windows" else [], + "-fvisibility=hidden", + ] if system() != "Windows" else [ + "/std:c11", + "/utf-8", + ], define_macros=[ - ("Py_LIMITED_API", "0x03080000"), - ("PY_SSIZE_T_CLEAN", None) + ("Py_LIMITED_API", "0x03090000"), + ("PY_SSIZE_T_CLEAN", None), + ("TREE_SITTER_HIDE_SYMBOLS", None), ], include_dirs=["php/src"], py_limited_api=True,