From f20a2b31d550448c92420138680d80d945c9eb05 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Mon, 2 Sep 2024 20:44:59 -0400 Subject: [PATCH] build: update bindings --- .editorconfig | 9 +- .gitattributes | 4 - .github/workflows/ci.yml | 4 + .gitignore | 3 +- Cargo.lock | 89 +++++++++++++++++++ Cargo.toml | 5 +- Makefile | 41 +++++---- Package.swift | 83 +++++++++-------- binding.gyp | 13 ++- bindings/go/binding_test.go | 2 +- bindings/node/binding.cc | 2 +- bindings/node/binding_test.js | 9 ++ bindings/python/tests/test_binding.py | 11 +++ bindings/python/tree_sitter_cpp/__init__.py | 36 +++++++- bindings/python/tree_sitter_cpp/__init__.pyi | 8 +- bindings/python/tree_sitter_cpp/binding.c | 4 +- bindings/rust/lib.rs | 29 +++--- .../TreeSitterCPPTests.swift | 12 +++ go.mod | 8 +- go.sum | 34 +++++++ package-lock.json | 45 +++++----- package.json | 14 ++- pyproject.toml | 4 +- queries/highlights.scm | 2 +- setup.py | 17 ++-- 25 files changed, 359 insertions(+), 129 deletions(-) create mode 100644 Cargo.lock create mode 100644 bindings/node/binding_test.js create mode 100644 bindings/python/tests/test_binding.py create mode 100644 bindings/swift/TreeSitterCPPTests/TreeSitterCPPTests.swift create mode 100644 go.sum diff --git a/.editorconfig b/.editorconfig index 0463d52..f363cc5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,8 +2,6 @@ root = true [*] charset = utf-8 -insert_final_newline = true -trim_trailing_whitespace = true [*.{json,toml,yml,gyp}] indent_style = space @@ -13,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 @@ -36,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 6bda017..4cb1058 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,5 @@ * text=auto eol=lf -test/corpus/c/crlf.txt eol=crlf - -examples/* linguist-vendored - src/*.json linguist-generated src/parser.c linguist-generated src/tree_sitter/* linguist-generated diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index daef54a..74d3cfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,10 @@ jobs: uses: tree-sitter/parser-test-action@v2 with: test-rust: ${{runner.os == 'Linux'}} + test-node: true + test-python: true + test-go: true + test-swift: ${{runner.os == 'macOS'}} - name: Parse examples uses: tree-sitter/parse-action@v4 with: diff --git a/.gitignore b/.gitignore index 27fc43f..2fd9dac 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 new file mode 100644 index 0000000..3a4c42b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,89 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +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 = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "tree-sitter" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f4cd3642c47a85052a887d86704f4eac272969f61b686bdd3f772122aabaff" +dependencies = [ + "cc", + "regex", + "regex-syntax", + "tree-sitter-language", +] + +[[package]] +name = "tree-sitter-cpp" +version = "0.22.3" +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 35327df..72dffd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,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.94" + +[dev-dependencies] +tree-sitter = "0.23" diff --git a/Makefile b/Makefile index 3400460..28367a6 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +ifeq ($(OS),Windows_NT) +$(error Windows is not supported) +endif + VERSION := 0.22.3 LANGUAGE_NAME := tree-sitter-cpp @@ -17,44 +21,44 @@ 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 LIBDIR ?= $(PREFIX)/lib PCLIBDIR ?= $(LIBDIR)/pkgconfig -# object files -OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c)) +# source/object files +PARSER := $(SRC_DIR)/parser.c +EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c)) +OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) # flags -ARFLAGS := rcs +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 @@ -81,8 +85,8 @@ $(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in -e 's|=$(PREFIX)|=$${prefix}|' \ -e 's|@PREFIX@|$(PREFIX)|' $< > $@ -$(SRC_DIR)/parser.c: 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)' @@ -106,6 +110,5 @@ clean: test: $(TS) test - $(TS) parse examples/* --quiet --time .PHONY: all install uninstall clean test diff --git a/Package.swift b/Package.swift index 8a60cfc..0c5b379 100644 --- a/Package.swift +++ b/Package.swift @@ -6,42 +6,55 @@ let package = Package( products: [ .library(name: "TreeSitterCPP", targets: ["TreeSitterCPP"]), ], - dependencies: [], + dependencies: [ + .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"), + ], targets: [ - .target(name: "TreeSitterCPP", - 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: [ - "src/parser.c", - "src/scanner.c", - ], - resources: [ - .copy("queries") - ], - publicHeadersPath: "bindings/swift", - cSettings: [.headerSearchPath("src")]) + .target( + name: "TreeSitterCPP", + dependencies: [], + 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: [ + "src/parser.c", + "src/scanner.c", + ], + resources: [ + .copy("queries") + ], + publicHeadersPath: "bindings/swift", + cSettings: [.headerSearchPath("src")] + ), + .testTarget( + name: "TreeSitterCPPTests", + dependencies: [ + "SwiftTreeSitter", + "TreeSitterCPP", + ], + path: "bindings/swift/TreeSitterCPPTests" + ) ], cLanguageStandard: .c11 ) diff --git a/binding.gyp b/binding.gyp index 3166682..52dcf10 100644 --- a/binding.gyp +++ b/binding.gyp @@ -13,8 +13,17 @@ "src/parser.c", "src/scanner.c", ], - "cflags_c": [ - "-std=c11", + "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 cfbb030..eac8028 100644 --- a/bindings/go/binding_test.go +++ b/bindings/go/binding_test.go @@ -3,7 +3,7 @@ package tree_sitter_cpp_test import ( "testing" - tree_sitter "github.com/smacker/go-tree-sitter" + tree_sitter "github.com/tree-sitter/go-tree-sitter" tree_sitter_cpp "github.com/tree-sitter/tree-sitter-cpp/bindings/go" ) diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc index 7efc74f..24bcb1b 100644 --- a/bindings/node/binding.cc +++ b/bindings/node/binding.cc @@ -6,7 +6,7 @@ extern "C" TSLanguage *tree_sitter_cpp(); // "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 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..56d3a1d --- /dev/null +++ b/bindings/python/tests/test_binding.py @@ -0,0 +1,11 @@ +from unittest import TestCase + +import tree_sitter, tree_sitter_cpp + + +class TestLanguage(TestCase): + def test_can_load_grammar(self): + try: + tree_sitter.Language(tree_sitter_cpp.language()) + except Exception: + self.fail("Error loading C++ grammar") diff --git a/bindings/python/tree_sitter_cpp/__init__.py b/bindings/python/tree_sitter_cpp/__init__.py index 0d1fa87..d9dc42c 100644 --- a/bindings/python/tree_sitter_cpp/__init__.py +++ b/bindings/python/tree_sitter_cpp/__init__.py @@ -1,5 +1,37 @@ -"C++ grammar for tree-sitter" +"""C++ grammar for tree-sitter""" + +from importlib.resources import files as _files from ._binding import language -__all__ = ["language"] + +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", + "HIGHLIGHTS_QUERY", + "INJECTIONS_QUERY", + "TAGS_QUERY", +] + + +def __dir__(): + return sorted(__all__ + [ + "__all__", "__builtins__", "__cached__", "__doc__", "__file__", + "__loader__", "__name__", "__package__", "__path__", "__spec__", + ]) diff --git a/bindings/python/tree_sitter_cpp/__init__.pyi b/bindings/python/tree_sitter_cpp/__init__.pyi index 5416666..043c23f 100644 --- a/bindings/python/tree_sitter_cpp/__init__.pyi +++ b/bindings/python/tree_sitter_cpp/__init__.pyi @@ -1 +1,7 @@ -def language() -> int: ... +from typing import Final + +HIGHLIGHTS_QUERY: Final[str] +INJECTIONS_QUERY: Final[str] +TAGS_QUERY: Final[str] + +def language() -> object: ... diff --git a/bindings/python/tree_sitter_cpp/binding.c b/bindings/python/tree_sitter_cpp/binding.c index 56a78e2..abb0d05 100644 --- a/bindings/python/tree_sitter_cpp/binding.c +++ b/bindings/python/tree_sitter_cpp/binding.c @@ -4,8 +4,8 @@ typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_cpp(void); -static PyObject* _binding_language(PyObject *self, PyObject *args) { - return PyLong_FromVoidPtr(tree_sitter_cpp()); +static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_cpp(), "tree_sitter.Language", NULL); } static PyMethodDef methods[] = { diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 0f67744..47e815c 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,6 +1,6 @@ -//! This crate provides a C++ grammar for the [tree-sitter][] parsing library. +//! This crate provides C++ 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: //! //! ``` @@ -11,8 +11,11 @@ //! return x * 2; //! } //! "#; -//! let mut parser = Parser::new(); -//! parser.set_language(&tree_sitter_cpp::language()).expect("Error loading C++ grammar"); +//! let mut parser = tree_sitter::Parser::new(); +//! let language = tree_sitter_cpp::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading C++ parser"); //! let tree = parser.parse(code, None).unwrap(); //! assert!(!tree.root_node().has_error()); //! ``` @@ -22,18 +25,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_cpp() -> Language; + fn tree_sitter_cpp() -> *const (); } -/// Returns 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_cpp() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_cpp) }; /// The content of the [`node-types.json`][] file for this grammar. /// @@ -49,10 +48,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 C++ grammar"); + .set_language(&super::LANGUAGE.into()) + .expect("Error loading C++ parser"); } } diff --git a/bindings/swift/TreeSitterCPPTests/TreeSitterCPPTests.swift b/bindings/swift/TreeSitterCPPTests/TreeSitterCPPTests.swift new file mode 100644 index 0000000..350b8b5 --- /dev/null +++ b/bindings/swift/TreeSitterCPPTests/TreeSitterCPPTests.swift @@ -0,0 +1,12 @@ +import XCTest +import SwiftTreeSitter +import TreeSitterCPP + +final class TreeSitterCPPTests: XCTestCase { + func testCanLoadGrammar() throws { + let parser = Parser() + let language = Language(language: tree_sitter_cpp()) + XCTAssertNoThrow(try parser.setLanguage(language), + "Error loading C++ grammar") + } +} diff --git a/go.mod b/go.mod index 87d1dbc..5c050a0 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,9 @@ module github.com/tree-sitter/tree-sitter-cpp -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 0000000..88b8c41 --- /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-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-php v0.22.9-0.20240819002312-a552625b56c1 h1:ZXZMDwE+IhUtGug4Brv6NjJWUU3rfkZBKpemf6RY8/g= +github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1/go.mod h1:UKCLuYnJ312Mei+3cyTmGOHzn0YAnaPRECgJmHtzrqs= +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 add0151..d4eb7ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,21 +10,21 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { - "node-addon-api": "^8.0.0", - "node-gyp-build": "^4.8.1" + "node-addon-api": "^8.1.0", + "node-gyp-build": "^4.8.2" }, "devDependencies": { "eslint": "^8.57.0", "eslint-config-google": "^0.14.0", "prebuildify": "^6.0.1", - "tree-sitter-c": "^0.21.4", - "tree-sitter-cli": "^0.22.6" + "tree-sitter-c": "^0.23.0", + "tree-sitter-cli": "^0.23.0" }, "peerDependencies": { "tree-sitter": "^0.21.1" }, "peerDependenciesMeta": { - "tree_sitter": { + "tree-sitter": { "optional": true } } @@ -977,17 +977,17 @@ } }, "node_modules/node-addon-api": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.0.0.tgz", - "integrity": "sha512-ipO7rsHEBqa9STO5C5T10fj732ml+5kLN1cAG8/jdHd56ldQeGj3Q7+scUS+VHK/qy1zLEwC4wMK5+yM0btPvw==", + "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==", "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==", + "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", @@ -1377,6 +1377,7 @@ "resolved": "https://registry.npmjs.org/tree-sitter/-/tree-sitter-0.21.1.tgz", "integrity": "sha512-7dxoA6kYvtgWw80265MyqJlkRl4yawIjO7S5MigytjELkX43fV2WsAXzsNfO7sBpPPCF5Gp0+XzHk0DwLCq3xQ==", "hasInstallScript": true, + "optional": true, "peer": true, "dependencies": { "node-addon-api": "^8.0.0", @@ -1384,33 +1385,35 @@ } }, "node_modules/tree-sitter-c": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/tree-sitter-c/-/tree-sitter-c-0.21.4.tgz", - "integrity": "sha512-IahxFIhXiY15SUlrt2upBiKSBGdOaE1fjKLK1Ik5zxqGHf6T1rvr3IJrovbsE5sXhypx7Hnmf50gshsppaIihA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/tree-sitter-c/-/tree-sitter-c-0.23.0.tgz", + "integrity": "sha512-ZruwnqyMrTFEvDuglqpiN7Rjh8wczh7afNMRJGK/AHdCwmtcmUzZeOiF8ZDskryoWhmAzrMHQdhpV2bj2ohQNg==", "dev": true, "hasInstallScript": true, - "license": "MIT", "dependencies": { - "node-addon-api": "^8.0.0", - "node-gyp-build": "^4.8.1" + "node-addon-api": "^8.1.0", + "node-gyp-build": "^4.8.2" }, "peerDependencies": { "tree-sitter": "^0.21.0" }, "peerDependenciesMeta": { - "tree_sitter": { + "tree-sitter": { "optional": true } } }, "node_modules/tree-sitter-cli": { - "version": "0.22.6", - "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.22.6.tgz", - "integrity": "sha512-s7mYOJXi8sIFkt/nLJSqlYZP96VmKTc3BAwIX0rrrlRxWjWuCwixFqwzxWZBQz4R8Hx01iP7z3cT3ih58BUmZQ==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.23.0.tgz", + "integrity": "sha512-/DdQaPCCOrOYGp9FxGdhFUnHIrjhfbYatQXgNIcmaAOpPunpnDj2vsO/H+svsfQLaFsQ1C+BjgPhpbV28zka1w==", "dev": true, "hasInstallScript": true, "bin": { "tree-sitter": "cli.js" + }, + "engines": { + "node": ">=12.0.0" } }, "node_modules/type-check": { diff --git a/package.json b/package.json index 2074a20..e211e00 100644 --- a/package.json +++ b/package.json @@ -25,14 +25,14 @@ "src/**" ], "dependencies": { - "node-addon-api": "^8.0.0", - "node-gyp-build": "^4.8.1" + "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 } }, @@ -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 c1284a6..94f60c8 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-cpp" core = ["tree-sitter~=0.21"] [tool.cibuildwheel] -build = "cp38-*" +build = "cp39-*" build-frontend = "build" diff --git a/queries/highlights.scm b/queries/highlights.scm index 9d49318..394d4f9 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -62,7 +62,7 @@ "using" "concept" "requires" - (virtual) + "virtual" ] @keyword ; Strings diff --git a/setup.py b/setup.py index 05c390f..91f58eb 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ 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 @@ -38,12 +38,17 @@ def get_tag(self): "src/parser.c", "src/scanner.c", ], - extra_compile_args=( - ["-std=c11"] if system() != "Windows" else [] - ), + extra_compile_args=[ + "-std=c11", + "-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=["src"], py_limited_api=True,