diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2024-04-28 23:51:13 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2024-04-28 23:51:13 -0700 |
commit | 9207220a028dc44b2e705bdc6ff96c88bcfbad49 (patch) | |
tree | 4028dce1e46317e118a94a243010b5f8c7909eec | |
parent | ecaee577b23a68f47aded6d2ce07e30d31331149 (diff) | |
parent | 20ffd6d3b4da1acdbf2d08204b2130a5b2f7c4b3 (diff) |
Merge commit '20ffd6d3b4da1acdbf2d08204b2130a5b2f7c4b3'
48 files changed, 11228 insertions, 15817 deletions
diff --git a/vendored_parsers/tree-sitter-cmake/.editorconfig b/vendored_parsers/tree-sitter-cmake/.editorconfig new file mode 100644 index 000000000..d3a8b5b69 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/.editorconfig @@ -0,0 +1,39 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,toml,yml,gyp}] +indent_style = space +indent_size = 2 + +[*.js] +indent_style = space +indent_size = 2 + +[*.rs] +indent_style = space +indent_size = 4 + +[*.{c,cc,h}] +indent_style = space +indent_size = 4 + +[*.{py,pyi}] +indent_style = space +indent_size = 4 + +[*.swift] +indent_style = space +indent_size = 4 + +[*.go] +indent_style = tab +indent_size = 8 + +[Makefile] +indent_style = tab +indent_size = 8 diff --git a/vendored_parsers/tree-sitter-cmake/.gitattributes b/vendored_parsers/tree-sitter-cmake/.gitattributes new file mode 100644 index 000000000..ffb52abec --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/.gitattributes @@ -0,0 +1,11 @@ +* text eol=lf + +src/*.json linguist-generated +src/parser.c linguist-generated +src/tree_sitter/* linguist-generated + +bindings/** linguist-generated +binding.gyp linguist-generated +setup.py linguist-generated +Makefile linguist-generated +Package.swift linguist-generated diff --git a/vendored_parsers/tree-sitter-cmake/Cargo.toml b/vendored_parsers/tree-sitter-cmake/Cargo.toml index 3e38b25ba..dd5832f3a 100644 --- a/vendored_parsers/tree-sitter-cmake/Cargo.toml +++ b/vendored_parsers/tree-sitter-cmake/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-cmake" description = "cmake grammar for the tree-sitter parsing library" -version = "0.2.0" +version = "0.4.3" keywords = ["incremental", "parsing", "cmake"] categories = ["parsing", "text-editors"] repository = "https://github.com/uyha/tree-sitter-cmake" @@ -20,7 +20,7 @@ include = [ path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "~0.20" +tree-sitter = ">=0.22" [build-dependencies] cc = "1.0" diff --git a/vendored_parsers/tree-sitter-cmake/Makefile b/vendored_parsers/tree-sitter-cmake/Makefile new file mode 100644 index 000000000..ea22a792e --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/Makefile @@ -0,0 +1,109 @@ +VERSION := 0.0.1 + +LANGUAGE_NAME := tree-sitter-cmake + +# 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 + +# 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)) + +# flags +ARFLAGS := rcs +override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC + +# OS-specific bits +ifeq ($(OS),Windows_NT) + $(error "Windows is not supported") +else ifeq ($(shell uname),Darwin) + SOEXT = dylib + SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib + SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib + 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 +else + SOEXT = so + SOEXTVER_MAJOR = so.$(SONAME_MAJOR) + SOEXTVER = so.$(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) +endif +ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) + PCLIBDIR := $(PREFIX)/libdata/pkgconfig +endif + +all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc + +lib$(LANGUAGE_NAME).a: $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) + $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ +ifneq ($(STRIP),) + $(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)|' $< > $@ + +$(SRC_DIR)/parser.c: grammar.js + $(TS) generate --no-bindings + +install: all + install -Dm644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h + install -Dm644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + install -Dm755 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) + +uninstall: + $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ + '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ + '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + +clean: + $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) + +test: + $(TS) test + +.PHONY: all install uninstall clean test diff --git a/vendored_parsers/tree-sitter-cmake/Package.swift b/vendored_parsers/tree-sitter-cmake/Package.swift new file mode 100644 index 000000000..64f4c0826 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/Package.swift @@ -0,0 +1,48 @@ +// swift-tools-version:5.3 +import PackageDescription + +let package = Package( + name: "TreeSitterCmake", + platforms: [.macOS(.v10_13), .iOS(.v11)], + products: [ + .library(name: "TreeSitterCmake", targets: ["TreeSitterCmake"]), + ], + dependencies: [], + targets: [ + .target(name: "TreeSitterCmake", + 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")]) + ], + cLanguageStandard: .c11 +) diff --git a/vendored_parsers/tree-sitter-cmake/binding.gyp b/vendored_parsers/tree-sitter-cmake/binding.gyp index a2beb8a05..33c973d4d 100644 --- a/vendored_parsers/tree-sitter-cmake/binding.gyp +++ b/vendored_parsers/tree-sitter-cmake/binding.gyp @@ -1,19 +1,21 @@ { "targets": [ { - "target_name": "tree_sitter_CMake_binding", + "target_name": "tree_sitter_cmake_binding", + "dependencies": [ + "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except", + ], "include_dirs": [ - "<!(node -e \"require('nan')\")", - "src" + "src", ], "sources": [ "bindings/node/binding.cc", "src/parser.c", - # If your language uses an external scanner, add it here. + # NOTE: if your language has an external scanner, add it here. ], "cflags_c": [ - "-std=c99", - ] + "-std=c11", + ], } ] } diff --git a/vendored_parsers/tree-sitter-cmake/bindings/c/tree-sitter-cmake.h b/vendored_parsers/tree-sitter-cmake/bindings/c/tree-sitter-cmake.h new file mode 100644 index 000000000..b7d7d2d12 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/c/tree-sitter-cmake.h @@ -0,0 +1,16 @@ +#ifndef TREE_SITTER_CMAKE_H_ +#define TREE_SITTER_CMAKE_H_ + +typedef struct TSLanguage TSLanguage; + +#ifdef __cplusplus +extern "C" { +#endif + +const TSLanguage *tree_sitter_cmake(void); + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_CMAKE_H_ diff --git a/vendored_parsers/tree-sitter-cmake/bindings/c/tree-sitter-cmake.pc.in b/vendored_parsers/tree-sitter-cmake/bindings/c/tree-sitter-cmake.pc.in new file mode 100644 index 000000000..95738e639 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/c/tree-sitter-cmake.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: tree-sitter-cmake +Description: Cmake grammar for tree-sitter +URL: @URL@ +Version: @VERSION@ +Requires: @REQUIRES@ +Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-cmake +Cflags: -I${includedir} diff --git a/vendored_parsers/tree-sitter-cmake/bindings/go/binding.go b/vendored_parsers/tree-sitter-cmake/bindings/go/binding.go new file mode 100644 index 000000000..01a2b9ee6 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/go/binding.go @@ -0,0 +1,13 @@ +package tree_sitter_cmake + +// #cgo CFLAGS: -std=c11 -fPIC +// #include "../../src/parser.c" +// // NOTE: if your language has an external scanner, add it here. +import "C" + +import "unsafe" + +// Get the tree-sitter Language for this grammar. +func Language() unsafe.Pointer { + return unsafe.Pointer(C.tree_sitter_cmake()) +} diff --git a/vendored_parsers/tree-sitter-cmake/bindings/go/binding_test.go b/vendored_parsers/tree-sitter-cmake/bindings/go/binding_test.go new file mode 100644 index 000000000..25e6d9a07 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/go/binding_test.go @@ -0,0 +1,15 @@ +package tree_sitter_cmake_test + +import ( + "testing" + + tree_sitter "github.com/smacker/go-tree-sitter" + "github.com/tree-sitter/tree-sitter-cmake" +) + +func TestCanLoadGrammar(t *testing.T) { + language := tree_sitter.NewLanguage(tree_sitter_cmake.Language()) + if language == nil { + t.Errorf("Error loading Cmake grammar") + } +} diff --git a/vendored_parsers/tree-sitter-cmake/bindings/go/go.mod b/vendored_parsers/tree-sitter-cmake/bindings/go/go.mod new file mode 100644 index 000000000..e71d38915 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/go/go.mod @@ -0,0 +1,5 @@ +module github.com/tree-sitter/tree-sitter-cmake + +go 1.22 + +require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 diff --git a/vendored_parsers/tree-sitter-cmake/bindings/node/binding.cc b/vendored_parsers/tree-sitter-cmake/bindings/node/binding.cc index 5a78d71e5..01009b679 100644 --- a/vendored_parsers/tree-sitter-cmake/bindings/node/binding.cc +++ b/vendored_parsers/tree-sitter-cmake/bindings/node/binding.cc @@ -1,28 +1,20 @@ -#include "tree_sitter/parser.h" -#include <node.h> -#include "nan.h" +#include <napi.h> -using namespace v8; +typedef struct TSLanguage TSLanguage; -extern "C" TSLanguage * tree_sitter_cmake(); +extern "C" TSLanguage *tree_sitter_cmake(); -namespace { +// "tree-sitter", "language" hashed with BLAKE2 +const napi_type_tag LANGUAGE_TYPE_TAG = { + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 +}; -NAN_METHOD(New) {} - -void Init(Local<Object> exports, Local<Object> module) { - Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked(); - Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_cmake()); - - Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("cmake").ToLocalChecked()); - Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports["name"] = Napi::String::New(env, "cmake"); + auto language = Napi::External<TSLanguage>::New(env, tree_sitter_cmake()); + language.TypeTag(&LANGUAGE_TYPE_TAG); + exports["language"] = language; + return exports; } -NODE_MODULE(tree_sitter_cmake_binding, Init) - -} // namespace +NODE_API_MODULE(tree_sitter_cmake_binding, Init) diff --git a/vendored_parsers/tree-sitter-cmake/bindings/node/index.d.ts b/vendored_parsers/tree-sitter-cmake/bindings/node/index.d.ts new file mode 100644 index 000000000..efe259eed --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/node/index.d.ts @@ -0,0 +1,28 @@ +type BaseNode = { + type: string; + named: boolean; +}; + +type ChildNode = { + multiple: boolean; + required: boolean; + types: BaseNode[]; +}; + +type NodeInfo = + | (BaseNode & { + subtypes: BaseNode[]; + }) + | (BaseNode & { + fields: { [name: string]: ChildNode }; + children: ChildNode[]; + }); + +type Language = { + name: string; + language: unknown; + nodeTypeInfo: NodeInfo[]; +}; + +declare const language: Language; +export = language; diff --git a/vendored_parsers/tree-sitter-cmake/bindings/node/index.js b/vendored_parsers/tree-sitter-cmake/bindings/node/index.js index 12513d4a2..6657bcf42 100644 --- a/vendored_parsers/tree-sitter-cmake/bindings/node/index.js +++ b/vendored_parsers/tree-sitter-cmake/bindings/node/index.js @@ -1,18 +1,6 @@ -try { - module.exports = require("../../build/Release/tree_sitter_cmake_binding"); -} catch (error1) { - if (error1.code !== 'MODULE_NOT_FOUND') { - throw error1; - } - try { - module.exports = require("../../build/Debug/tree_sitter_cmake_binding"); - } catch (error2) { - if (error2.code !== 'MODULE_NOT_FOUND') { - throw error2; - } - throw error1 - } -} +const root = require("path").join(__dirname, "..", ".."); + +module.exports = require("node-gyp-build")(root); try { module.exports.nodeTypeInfo = require("../../src/node-types.json"); diff --git a/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/__init__.py b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/__init__.py new file mode 100644 index 000000000..c8043ee7d --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/__init__.py @@ -0,0 +1,5 @@ +"Cmake grammar for tree-sitter" + +from ._binding import language + +__all__ = ["language"] diff --git a/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/__init__.pyi b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/__init__.pyi new file mode 100644 index 000000000..5416666fc --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/__init__.pyi @@ -0,0 +1 @@ +def language() -> int: ... diff --git a/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/binding.c b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/binding.c new file mode 100644 index 000000000..d8edae252 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/binding.c @@ -0,0 +1,27 @@ +#include <Python.h> + +typedef struct TSLanguage TSLanguage; + +TSLanguage *tree_sitter_cmake(void); + +static PyObject* _binding_language(PyObject *self, PyObject *args) { + return PyLong_FromVoidPtr(tree_sitter_cmake()); +} + +static PyMethodDef methods[] = { + {"language", _binding_language, METH_NOARGS, + "Get the tree-sitter language for this grammar."}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef module = { + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "_binding", + .m_doc = NULL, + .m_size = -1, + .m_methods = methods +}; + +PyMODINIT_FUNC PyInit__binding(void) { + return PyModule_Create(&module); +} diff --git a/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/py.typed b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/py.typed new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/python/tree_sitter_cmake/py.typed diff --git a/vendored_parsers/tree-sitter-cmake/bindings/rust/build.rs b/vendored_parsers/tree-sitter-cmake/bindings/rust/build.rs index 618e90a3a..8f87ee668 100644 --- a/vendored_parsers/tree-sitter-cmake/bindings/rust/build.rs +++ b/vendored_parsers/tree-sitter-cmake/bindings/rust/build.rs @@ -10,29 +10,10 @@ fn main() { let parser_path = src_dir.join("parser.c"); c_config.file(&parser_path); - // If your language uses an external scanner written in C, - // then include this block of code: - - /* let scanner_path = src_dir.join("scanner.c"); c_config.file(&scanner_path); println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); - */ c_config.compile("parser"); println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); - - // If your language uses an external scanner written in C++, - // then include this block of code: - - let mut cpp_config = cc::Build::new(); - cpp_config.cpp(true); - cpp_config.include(&src_dir); - cpp_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable"); - let scanner_path = src_dir.join("scanner.cc"); - cpp_config.file(&scanner_path); - cpp_config.compile("scanner"); - println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); } diff --git a/vendored_parsers/tree-sitter-cmake/bindings/swift/TreeSitterCmake/cmake.h b/vendored_parsers/tree-sitter-cmake/bindings/swift/TreeSitterCmake/cmake.h new file mode 100644 index 000000000..b7d7d2d12 --- /dev/null +++ b/vendored_parsers/tree-sitter-cmake/bindings/swift/TreeSitterCmake/cmake.h @@ -0,0 +1,16 @@ +#ifndef TREE_SITTER_CMAKE_H_ +#define TREE_SITTER_CMAKE_H_ + +typedef struct TSLanguage TSLanguage; + +#ifdef __cplusplus +extern "C" { +#endif + +const TSLanguage *tree_sitter_cmake(void); + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTE |