From 8b747e2e348e52b748275834cfbe8e137959a2d2 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 1 Sep 2024 23:17:36 -0400 Subject: [PATCH] build: update bindings --- .gitattributes | 2 +- .github/workflows/ci.yml | 2 +- .gitignore | 2 - Cargo.lock | 89 +++++++++++++++++++ Cargo.toml | 7 +- Makefile | 43 ++++----- Package.swift | 83 +++++++++-------- bindings/go/binding_test.go | 2 +- bindings/node/binding.cc | 2 +- bindings/node/binding_test.js | 9 ++ bindings/python/tests/test_binding.py | 11 +++ .../python/tree_sitter_javascript/binding.c | 4 +- bindings/rust/lib.rs | 27 +++--- .../TreeSitterJavascriptTests.swift | 12 +++ go.mod | 8 +- go.sum | 34 +++++++ package-lock.json | 30 ++++--- package.json | 17 ++-- pyproject.toml | 4 +- src/tree_sitter/parser.h | 1 + test/corpus/destructuring.txt | 24 +++++ 21 files changed, 307 insertions(+), 106 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/TreeSitterJavascriptTests/TreeSitterJavascriptTests.swift create mode 100644 go.sum diff --git a/.gitattributes b/.gitattributes index ffb52abe..4cb10583 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -* text eol=lf +* text=auto eol=lf src/*.json linguist-generated src/parser.c linguist-generated diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc96b233..f9bdedd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: ["*"] + branches: [master] paths: - grammar.js - src/** diff --git a/.gitignore b/.gitignore index 27fc43f7..73b237ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Rust artifacts -Cargo.lock target/ # Node artifacts @@ -12,7 +11,6 @@ node_modules/ .build/ # Go artifacts -go.sum _obj/ # Python artifacts diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..c2712594 --- /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.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +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-javascript" +version = "0.21.4" +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 3fabb64a..342457c1 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.90" +cc = "1.1.15" + +[dev-dependencies] +tree-sitter = "0.23" diff --git a/Makefile b/Makefile index c718387f..3ac50f1f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ -VERSION := 0.21.4 +ifeq ($(OS),Windows_NT) +$(error Windows is not supported) +endif + +VERSION := 0.0.1 LANGUAGE_NAME := tree-sitter-javascript @@ -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 139cee98..86350ebd 100644 --- a/Package.swift +++ b/Package.swift @@ -6,42 +6,55 @@ let package = Package( products: [ .library(name: "TreeSitterJavascript", targets: ["TreeSitterJavascript"]), ], - dependencies: [], + dependencies: [ + .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"), + ], targets: [ - .target(name: "TreeSitterJavascript", - 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: "TreeSitterJavascript", + 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", + // NOTE: if your language has an external scanner, add it here. + ], + resources: [ + .copy("queries") + ], + publicHeadersPath: "bindings/swift", + cSettings: [.headerSearchPath("src")] + ), + .testTarget( + name: "TreeSitterJavascriptTests", + dependencies: [ + "SwiftTreeSitter", + "TreeSitterJavascript", + ], + path: "bindings/swift/TreeSitterJavascriptTests" + ) ], cLanguageStandard: .c11 ) diff --git a/bindings/go/binding_test.go b/bindings/go/binding_test.go index 2d318afb..cfb028f3 100644 --- a/bindings/go/binding_test.go +++ b/bindings/go/binding_test.go @@ -3,7 +3,7 @@ package tree_sitter_javascript_test import ( "testing" - tree_sitter "github.com/smacker/go-tree-sitter" + tree_sitter "github.com/tree-sitter/go-tree-sitter" tree_sitter_javascript "github.com/tree-sitter/tree-sitter-javascript/bindings/go" ) diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc index f70cde6b..e0a42aee 100644 --- a/bindings/node/binding.cc +++ b/bindings/node/binding.cc @@ -6,7 +6,7 @@ extern "C" TSLanguage *tree_sitter_javascript(); // "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..afede30a --- /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 00000000..1c895733 --- /dev/null +++ b/bindings/python/tests/test_binding.py @@ -0,0 +1,11 @@ +from unittest import TestCase + +import tree_sitter, tree_sitter_javascript + + +class TestLanguage(TestCase): + def test_can_load_grammar(self): + try: + tree_sitter.Language(tree_sitter_javascript.language()) + except Exception: + self.fail("Error loading Javascript grammar") diff --git a/bindings/python/tree_sitter_javascript/binding.c b/bindings/python/tree_sitter_javascript/binding.c index d255b6af..140fe399 100644 --- a/bindings/python/tree_sitter_javascript/binding.c +++ b/bindings/python/tree_sitter_javascript/binding.c @@ -4,8 +4,8 @@ typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_javascript(void); -static PyObject* _binding_language(PyObject *self, PyObject *args) { - return PyLong_FromVoidPtr(tree_sitter_javascript()); +static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_javascript(), "tree_sitter.Language", NULL); } static PyMethodDef methods[] = { diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 12a0db4a..0d61ca49 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,6 +1,6 @@ -//! This crate provides a JavaScript grammar for the [tree-sitter][] parsing library. +//! This crate provides Javascript 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: //! //! ``` @@ -12,7 +12,10 @@ //! } //! "#; //! let mut parser = Parser::new(); -//! parser.set_language(&tree_sitter_javascript::language()).expect("Error loading JavaScript grammar"); +//! let language = tree_sitter_javascript::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading Javascript 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_javascript() -> Language; + fn tree_sitter_javascript() -> *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_javascript() } -} +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_javascript) }; /// The content of the [`node-types.json`][] file for this grammar. /// @@ -58,10 +57,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 JavaScript grammar"); + .set_language(&super::LANGUAGE.into()) + .expect("Error loading Javascript parser"); } } diff --git a/bindings/swift/TreeSitterJavascriptTests/TreeSitterJavascriptTests.swift b/bindings/swift/TreeSitterJavascriptTests/TreeSitterJavascriptTests.swift new file mode 100644 index 00000000..ad80ca49 --- /dev/null +++ b/bindings/swift/TreeSitterJavascriptTests/TreeSitterJavascriptTests.swift @@ -0,0 +1,12 @@ +import XCTest +import SwiftTreeSitter +import TreeSitterJavascript + +final class TreeSitterJavascriptTests: XCTestCase { + func testCanLoadGrammar() throws { + let parser = Parser() + let language = Language(language: tree_sitter_javascript()) + XCTAssertNoThrow(try parser.setLanguage(language), + "Error loading Javascript grammar") + } +} diff --git a/go.mod b/go.mod index cb1c8703..9e49f795 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,9 @@ module github.com/tree-sitter/tree-sitter-javascript -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..a0c2c5b5 --- /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-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 9fdc040d..861f7afc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,20 +10,20 @@ "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-cli": "^0.22.6" + "tree-sitter-cli": "^0.23.0" }, "peerDependencies": { "tree-sitter": "^0.21.1" }, "peerDependenciesMeta": { - "tree_sitter": { + "tree-sitter": { "optional": true } } @@ -956,17 +956,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", @@ -1353,6 +1353,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", @@ -1360,13 +1361,16 @@ } }, "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 7280cb0a..4432a9d8 100644 --- a/package.json +++ b/package.json @@ -25,31 +25,28 @@ "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 } }, "devDependencies": { "eslint": "^8.57.0", "eslint-config-google": "^0.14.0", - "tree-sitter-cli": "^0.22.6", + "tree-sitter-cli": "^0.23.0", "prebuildify": "^6.0.1" }, "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 4932735c..10e839f2 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-javascript" core = ["tree-sitter~=0.21"] [tool.cibuildwheel] -build = "cp38-*" +build = "cp39-*" build-frontend = "build" diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 17f0e94b..799f599b 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -47,6 +47,7 @@ struct TSLexer { uint32_t (*get_column)(TSLexer *); bool (*is_at_included_range_start)(const TSLexer *); bool (*eof)(const TSLexer *); + void (*log)(const TSLexer *, const char *, ...); }; typedef enum { diff --git a/test/corpus/destructuring.txt b/test/corpus/destructuring.txt index 951ea35a..af5a5648 100644 --- a/test/corpus/destructuring.txt +++ b/test/corpus/destructuring.txt @@ -109,3 +109,27 @@ function b({c} = {}) {} (formal_parameters (assignment_pattern (object_pattern (shorthand_property_identifier_pattern)) (object))) (statement_block))) + +=================================================== +Extra complex literals in expressions +=================================================== + +if ({a: 'b'} {c: 'd'}) { + x = function(a) { b; } function(c) { d; } +} + +--- + +(program + (if_statement + (parenthesized_expression + (ERROR (object (pair (property_identifier) (string (string_fragment))))) + (object (pair (property_identifier) (string (string_fragment))))) + (statement_block + (expression_statement + (assignment_expression + (identifier) + (function_expression (formal_parameters (identifier)) (statement_block (expression_statement (identifier))))) + (MISSING ";")) + (expression_statement + (function_expression (formal_parameters (identifier)) (statement_block (expression_statement (identifier))))))))