diff --git a/.editorconfig b/.editorconfig index f363cc5..7756ee9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,10 @@ indent_size = 2 indent_style = space indent_size = 2 +[*.scm] +indent_style = space +indent_size = 2 + [*.{c,cc,h}] indent_style = space indent_size = 4 diff --git a/.gitattributes b/.gitattributes index 4cb1058..9d5c5d4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,4 +8,6 @@ bindings/** linguist-generated binding.gyp linguist-generated setup.py linguist-generated Makefile linguist-generated +CMakeLists.txt linguist-generated Package.swift linguist-generated +go.mod linguist-generated diff --git a/.gitignore b/.gitignore index 2fd9dac..308fcab 100644 --- a/.gitignore +++ b/.gitignore @@ -5,11 +5,9 @@ target/ build/ prebuilds/ node_modules/ -*.tgz # Swift artifacts .build/ -Package.resolved # Go artifacts _obj/ @@ -35,3 +33,8 @@ dist/ *.wasm *.obj *.o + +# Archives +*.tar.gz +*.tgz +*.zip diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index d68aa73..0000000 --- a/.prettierrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "arrowParens": "avoid" -} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c9f787d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.13) + +project(tree-sitter-scala + VERSION "0.23.2" + DESCRIPTION "Scala grammar for tree-sitter" + HOMEPAGE_URL "https://github.com/tree-sitter/tree-sitter-scala" + LANGUAGES C) + +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) +option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF) + +set(TREE_SITTER_ABI_VERSION 14 CACHE STRING "Tree-sitter ABI version") +if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") + unset(TREE_SITTER_ABI_VERSION CACHE) + message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") +endif() + +find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") + +add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" + COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json + --abi=${TREE_SITTER_ABI_VERSION} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "Generating parser.c") + +add_library(tree-sitter-scala src/parser.c) +if(EXISTS src/scanner.c) + target_sources(tree-sitter-scala PRIVATE src/scanner.c) +endif() +target_include_directories(tree-sitter-scala PRIVATE src) + +target_compile_definitions(tree-sitter-scala PRIVATE + $<$:TREE_SITTER_REUSE_ALLOCATOR> + $<$:TREE_SITTER_DEBUG>) + +set_target_properties(tree-sitter-scala + PROPERTIES + C_STANDARD 11 + POSITION_INDEPENDENT_CODE ON + SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" + DEFINE_SYMBOL "") + +configure_file(bindings/c/tree-sitter-scala.pc.in + "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-scala.pc" @ONLY) + +include(GNUInstallDirs) + +install(FILES bindings/c/tree-sitter-scala.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-scala.pc" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") +install(TARGETS tree-sitter-scala + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + +add_custom_target(test "${TREE_SITTER_CLI}" test + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "tree-sitter test") + +# vim:ft=cmake: diff --git a/Cargo.lock b/Cargo.lock index 2657b38..2a10028 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.15" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" dependencies = [ "shlex", ] @@ -61,15 +61,22 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" + [[package]] name = "tree-sitter" -version = "0.23.0" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20f4cd3642c47a85052a887d86704f4eac272969f61b686bdd3f772122aabaff" +checksum = "f9871f16d6cf5c4757dcf30d5d2172a2df6987c510c017bbb7abfb7f9aa24d06" dependencies = [ "cc", "regex", "regex-syntax", + "streaming-iterator", "tree-sitter-language", ] @@ -81,7 +88,7 @@ checksum = "2545046bd1473dac6c626659cc2567c6c0ff302fc8b84a56c4243378276f7f57" [[package]] name = "tree-sitter-scala" -version = "0.23.0" +version = "0.23.2" dependencies = [ "cc", "tree-sitter", diff --git a/Cargo.toml b/Cargo.toml index 9c6c395..b33010f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,9 +2,11 @@ name = "tree-sitter-scala" description = "Scala grammar for tree-sitter" version = "0.23.2" +authors = ["Max Brunsfeld "] license = "MIT" +readme = "README.md" keywords = ["incremental", "parsing", "tree-sitter", "scala"] -categories = ["parsing", "text-editors"] +categories = ["parser-implementations", "parsing", "text-editors"] repository = "https://github.com/tree-sitter/tree-sitter-scala" edition = "2021" autoexamples = false @@ -16,10 +18,10 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter-language = "0.1.0" +tree-sitter-language = "0.1" [build-dependencies] -cc = "1.1.15" +cc = "1.1" [dev-dependencies] -tree-sitter = "0.23" +tree-sitter = "0.24" diff --git a/Makefile b/Makefile index 492f812..f5a436d 100644 --- a/Makefile +++ b/Makefile @@ -2,23 +2,13 @@ ifeq ($(OS),Windows_NT) $(error Windows is not supported) endif -VERSION := 0.23.2 - LANGUAGE_NAME := tree-sitter-scala +HOMEPAGE_URL := https://github.com/tree-sitter/tree-sitter-scala +VERSION := 0.23.2 # repository SRC_DIR := src -PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null) - -ifeq ($(PARSER_URL),) - PARSER_URL := $(subst .git,,$(PARSER_REPO_URL)) -ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),) - PARSER_URL := $(subst :,/,$(PARSER_URL)) - PARSER_URL := $(subst git@,https://,$(PARSER_URL)) -endif -endif - TS ?= tree-sitter # install directory layout @@ -37,28 +27,20 @@ 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)) +SONAME_MAJOR = $(shell sed -n 's/\#define LANGUAGE_VERSION //p' $(PARSER)) +SONAME_MINOR = $(word 1,$(subst ., ,$(VERSION))) # OS-specific bits ifeq ($(shell uname),Darwin) SOEXT = 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).$(SOEXTVER),-rpath,@executable_path/../Frameworks + LINKSHARED = -dynamiclib -Wl,-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks else SOEXT = so 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).$(SOEXTVER) + LINKSHARED = -shared -Wl,-soname,lib$(LANGUAGE_NAME).$(SOEXTVER) endif ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) PCLIBDIR := $(PREFIX)/libdata/pkgconfig @@ -76,17 +58,15 @@ ifneq ($(STRIP),) endif $(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in - sed -e 's|@URL@|$(PARSER_URL)|' \ - -e 's|@VERSION@|$(VERSION)|' \ - -e 's|@LIBDIR@|$(LIBDIR)|' \ - -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ - -e 's|@REQUIRES@|$(REQUIRES)|' \ - -e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \ - -e 's|=$(PREFIX)|=$${prefix}|' \ - -e 's|@PREFIX@|$(PREFIX)|' $< > $@ + sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \ + -e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR:$(PREFIX)/%=%)|' \ + -e 's|@CMAKE_INSTALL_INCLUDEDIR@|$(INCLUDEDIR:$(PREFIX)/%=%)|' \ + -e 's|@PROJECT_DESCRIPTION@|$(DESCRIPTION)|' \ + -e 's|@PROJECT_HOMEPAGE_URL@|$(HOMEPAGE_URL)|' \ + -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@ $(PARSER): $(SRC_DIR)/grammar.json - $(TS) generate --no-bindings $^ + $(TS) generate $^ install: all install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..9e0a023 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "SwiftTreeSitter", + "repositoryURL": "https://github.com/ChimeHQ/SwiftTreeSitter", + "state": { + "branch": null, + "revision": "2599e95310b3159641469d8a21baf2d3d200e61f", + "version": "0.8.0" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift index 00dfb5f..886639d 100644 --- a/Package.swift +++ b/Package.swift @@ -14,29 +14,6 @@ let package = Package( name: "TreeSitterScala", 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", diff --git a/bindings/c/tree-sitter-scala.pc.in b/bindings/c/tree-sitter-scala.pc.in index 96ff5e8..54f1df7 100644 --- a/bindings/c/tree-sitter-scala.pc.in +++ b/bindings/c/tree-sitter-scala.pc.in @@ -1,11 +1,11 @@ -prefix=@PREFIX@ -libdir=@LIBDIR@ -includedir=@INCLUDEDIR@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: tree-sitter-scala -Description: Scala grammar for tree-sitter -URL: @URL@ -Version: @VERSION@ -Requires: @REQUIRES@ -Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-scala +Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ +Version: @PROJECT_VERSION@ +Requires: @TS_REQUIRES@ +Libs: -L${libdir} -ltree-sitter-scala Cflags: -I${includedir} diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 31f4eab..f72dbfb 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,6 +1,6 @@ //! This crate provides Scala language support for the [tree-sitter][] parsing library. //! -//! Typically, you will use the [language][language func] function to add this language to a +//! Typically, you will use the [LANGUAGE][] constant to add this language to a //! tree-sitter [Parser][], and then use the parser to parse some code: //! //! ``` @@ -22,8 +22,6 @@ //! assert!(!tree.root_node().has_error()); //! ``` //! -//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -//! [language func]: fn.language.html //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html //! [tree-sitter]: https://tree-sitter.github.io/ @@ -33,7 +31,9 @@ extern "C" { fn tree_sitter_scala() -> *const (); } -/// The tree-sitter [`LanguageFn`] for this grammar. +/// 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_scala) }; /// The content of the [`node-types.json`][] file for this grammar. diff --git a/bindings/swift/TreeSitterScala/scala.h b/bindings/swift/TreeSitterScala/scala.h index b2ed699..e55a209 100644 --- a/bindings/swift/TreeSitterScala/scala.h +++ b/bindings/swift/TreeSitterScala/scala.h @@ -7,7 +7,7 @@ typedef struct TSLanguage TSLanguage; extern "C" { #endif -extern TSLanguage *tree_sitter_scala(); +const TSLanguage *tree_sitter_scala(void); #ifdef __cplusplus } diff --git a/go.mod b/go.mod index 899da64..7924be3 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module github.com/tree-sitter/tree-sitter-scala go 1.23 -require github.com/tree-sitter/go-tree-sitter v0.23.1 +require github.com/tree-sitter/go-tree-sitter v0.24.0 require github.com/mattn/go-pointer v0.0.1 // indirect diff --git a/go.sum b/go.sum index d775361..b4baa26 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT 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/go-tree-sitter v0.24.0 h1:kRZb6aBNfcI/u0Qh8XEt3zjNVnmxTisDBN+kXK0xRYQ= +github.com/tree-sitter/go-tree-sitter v0.24.0/go.mod h1:x681iFVoLMEwOSIHA1chaLkXlroXEN7WY+VHGFaoDbk= 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= diff --git a/grammar.js b/grammar.js index 63954fa..5a63033 100644 --- a/grammar.js +++ b/grammar.js @@ -1424,8 +1424,6 @@ module.exports = grammar({ ), ), - symbol_literal: $ => "__no_longer_used_symbol_literal_", - /** * id ::= plainid * | ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq diff --git a/package-lock.json b/package-lock.json index 565d63c..7ce00b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,12 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { - "node-addon-api": "^8.1.0", + "node-addon-api": "^8.2.1", "node-gyp-build": "^4.8.2" }, "devDependencies": { "prebuildify": "^6.0.1", - "prettier": "3.0.0-alpha.6", - "tree-sitter-cli": "0.23.0" + "tree-sitter-cli": "0.24.3" }, "peerDependencies": { "tree-sitter": "^0.21.1" @@ -152,9 +151,9 @@ } }, "node_modules/node-addon-api": { - "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==", + "version": "8.2.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.2.1.tgz", + "integrity": "sha512-vmEOvxwiH8tlOcv4SyE8RH34rI5/nWVaigUeAUPawC6f0+HoDthwI0vkMu4tbtsZrXq6QXFfrkhjofzKEs5tpA==", "engines": { "node": "^18 || ^20 || >= 21" } @@ -216,21 +215,6 @@ "prebuildify": "bin.js" } }, - "node_modules/prettier": { - "version": "3.0.0-alpha.6", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0-alpha.6.tgz", - "integrity": "sha512-AdbQSZ6Oo+iy9Ekzmsgno05P1uX2vqPkjOMJqRfP8hTe+m6iDw4Nt7bPFpWZ/HYCU+3f0P5U0o2ghxQwwkLH7A==", - "dev": true, - "bin": { - "prettier": "bin/prettier.cjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -337,9 +321,9 @@ } }, "node_modules/tree-sitter-cli": { - "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==", + "version": "0.24.3", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.24.3.tgz", + "integrity": "sha512-5vS0SiJf31tMTn9CYLsu5l18qXaw5MLFka3cuGxOB5f4TtgoUSK1Sog6rKmqBc7PvFJq37YcQBjj9giNy2cJPw==", "dev": true, "hasInstallScript": true, "bin": { diff --git a/package.json b/package.json index 0a6a69c..8216736 100644 --- a/package.json +++ b/package.json @@ -19,24 +19,24 @@ "prebuilds/**", "bindings/node/*", "queries/*", - "src/**" + "src/**", + "*.wasm" ], "dependencies": { - "node-addon-api": "^8.1.0", + "node-addon-api": "^8.2.1", "node-gyp-build": "^4.8.2" }, - "peerDependencies": { - "tree-sitter": "^0.21.1" - }, "devDependencies": { - "tree-sitter-cli": "0.23.0", - "prettier": "3.0.0-alpha.6", + "tree-sitter-cli": "0.24.3", "prebuildify": "^6.0.1" }, + "peerDependencies": { + "tree-sitter": "^0.21.1" + }, "scripts": { "install": "node-gyp-build", "prestart": "tree-sitter build --wasm", "start": "tree-sitter playground", "test": "node --test bindings/node/*_test.js" } -} \ No newline at end of file +} diff --git a/pyproject.toml b/pyproject.toml index 634f6b6..6809ff8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,8 +12,9 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Compilers", "Topic :: Text Processing :: Linguistic", - "Typing :: Typed" + "Typing :: Typed", ] +authors = [{ name = "Max Brunsfeld", email = "maxbrunsfeld@gmail.com" }] requires-python = ">=3.9" license.text = "MIT" readme = "README.md" @@ -22,7 +23,7 @@ readme = "README.md" Homepage = "https://github.com/tree-sitter/tree-sitter-scala" [project.optional-dependencies] -core = ["tree-sitter~=0.21"] +core = ["tree-sitter~=0.23"] [tool.cibuildwheel] build = "cp39-*" diff --git a/tree-sitter.json b/tree-sitter.json index dfcffbb..d702bff 100644 --- a/tree-sitter.json +++ b/tree-sitter.json @@ -35,4 +35,4 @@ "rust": true, "swift": true } -} \ No newline at end of file +}