diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..d3a8b5b69 --- /dev/null +++ b/.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/.gitattributes b/.gitattributes new file mode 100644 index 000000000..ffb52abec --- /dev/null +++ b/.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/.gitignore b/.gitignore index b91d23de4..70bef74bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,38 @@ -*.log -*.tgz -.DS_Store +# Rust artifacts Cargo.lock -build -node_modules -package-lock.json -yarn.lock -target - -examples/**/* -!examples/*.* +target/ + +# Node artifacts +build/ +node_modules/ +*.tgz + +# Swift artifacts +.build/ + +# Go artifacts +go.sum +_obj/ + +# Python artifacts +.venv/ +dist/ +*.egg-info +*.whl + +# C artifacts +*.a +*.so +*.so.* +*.dylib +*.dll +*.pc + +# Example dirs +/examples/*/ + +# Grammar volatiles +dsl.d.ts +*.wasm +*.obj +*.o diff --git a/Cargo.toml b/Cargo.toml index 0ba0b02b6..ed9bb4a8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,29 +1,24 @@ [package] name = "tree-sitter-lua" -description = "Lua grammar for the tree-sitter parsing library" +description = "Lua grammar for tree-sitter" version = "0.0.19" -authors = [ - "Munif Tanjim ", -] license = "MIT" -keywords = ["incremental", "parsing", "lua"] +readme = "README.md" +keywords = ["incremental", "parsing", "tree-sitter", "lua"] categories = ["parsing", "text-editors"] repository = "https://github.com/tree-sitter-grammars/tree-sitter-lua" -edition = "2018" +authors = ["Munif Tanjim "] +edition = "2021" +autoexamples = false build = "bindings/rust/build.rs" -include = [ - "bindings/rust/*", - "grammar.js", - "queries/*", - "src/*", -] +include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] [lib] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "0.20" +tree-sitter = ">=0.21.0" [build-dependencies] -cc = "1.0" +cc = "^1.0.89" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..ae8a786ce --- /dev/null +++ b/Makefile @@ -0,0 +1,109 @@ +VERSION := 0.0.19 + +LANGUAGE_NAME := tree-sitter-lua + +# 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/Package.swift b/Package.swift new file mode 100644 index 000000000..c44e40990 --- /dev/null +++ b/Package.swift @@ -0,0 +1,48 @@ +// swift-tools-version:5.3 +import PackageDescription + +let package = Package( + name: "TreeSitterLua", + platforms: [.macOS(.v10_13), .iOS(.v11)], + products: [ + .library(name: "TreeSitterLua", targets: ["TreeSitterLua"]), + ], + dependencies: [], + targets: [ + .target(name: "TreeSitterLua", + path: ".", + exclude: [ + "Cargo.toml", + "Makefile", + "binding.gyp", + "bindings/c", + "bindings/go", + "bindings/node", + "bindings/python", + "bindings/rust", + "examples", + "grammar.js", + "package.json", + "package-lock.json", + "pyproject.toml", + "setup.py", + "test", + "types", + "examples", + ".editorconfig", + ".github", + ".gitignore", + ".gitattributes", + ], + sources: [ + "src/parser.c", + "src/scanner.c", + ], + resources: [ + .copy("queries") + ], + publicHeadersPath: "bindings/swift", + cSettings: [.headerSearchPath("src")]) + ], + cLanguageStandard: .c11 +) diff --git a/binding.gyp b/binding.gyp index 6ad07c449..b8142ff0a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,18 +2,20 @@ "targets": [ { "target_name": "tree_sitter_lua_binding", + "dependencies": [ + " -#include "nan.h" +#include -using namespace v8; +typedef struct TSLanguage TSLanguage; -extern "C" TSLanguage * tree_sitter_lua(); +extern "C" TSLanguage *tree_sitter_lua(); -namespace { +// "tree-sitter", "language" hashed with BLAKE2 +const napi_type_tag LANGUAGE_TYPE_TAG = { + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 +}; -NAN_METHOD(New) {} - -void Init(Local exports, Local module) { - Local tpl = Nan::New(New); - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); - Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_lua()); - - Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("lua").ToLocalChecked()); - Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports["name"] = Napi::String::New(env, "lua"); + auto language = Napi::External::New(env, tree_sitter_lua()); + language.TypeTag(&LANGUAGE_TYPE_TAG); + exports["language"] = language; + return exports; } -NODE_MODULE(tree_sitter_lua_binding, Init) - -} // namespace +NODE_API_MODULE(tree_sitter_lua_binding, Init) diff --git a/bindings/node/index.d.ts b/bindings/node/index.d.ts new file mode 100644 index 000000000..efe259eed --- /dev/null +++ b/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/bindings/python/tree_sitter_lua/__init__.py b/bindings/python/tree_sitter_lua/__init__.py new file mode 100644 index 000000000..1ccaaefcc --- /dev/null +++ b/bindings/python/tree_sitter_lua/__init__.py @@ -0,0 +1,3 @@ +"Lua grammar for tree-sitter" + +from ._binding import language diff --git a/bindings/python/tree_sitter_lua/__init__.pyi b/bindings/python/tree_sitter_lua/__init__.pyi new file mode 100644 index 000000000..5416666fc --- /dev/null +++ b/bindings/python/tree_sitter_lua/__init__.pyi @@ -0,0 +1 @@ +def language() -> int: ... diff --git a/bindings/python/tree_sitter_lua/binding.c b/bindings/python/tree_sitter_lua/binding.c new file mode 100644 index 000000000..4ac029d8e --- /dev/null +++ b/bindings/python/tree_sitter_lua/binding.c @@ -0,0 +1,27 @@ +#include + +typedef struct TSLanguage TSLanguage; + +TSLanguage *tree_sitter_lua(void); + +static PyObject* _binding_language(PyObject *self, PyObject *args) { + return PyLong_FromVoidPtr(tree_sitter_lua()); +} + +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/bindings/python/tree_sitter_lua/py.typed b/bindings/python/tree_sitter_lua/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index f7aaf1661..bfe252b1c 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -2,37 +2,18 @@ fn main() { let src_dir = std::path::Path::new("src"); let mut c_config = cc::Build::new(); - c_config.include(&src_dir); + c_config.include(src_dir); c_config .flag_if_supported("-Wno-unused-parameter") .flag_if_supported("-Wno-unused-but-set-variable") .flag_if_supported("-Wno-trigraphs"); 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: + println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 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()); - */ + c_config.compile("tree-sitter-lua"); } diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 08ce613d3..7a64e74c5 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,13 +1,16 @@ -//! This crate provides lua language support for the [tree-sitter][] parsing library. +//! This crate provides Lua language support for the [tree-sitter][] parsing library. //! //! 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: //! //! ``` -//! let code = ""; +//! let code = r#" +//! return 42 +//! "#; //! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_lua::language()).expect("Error loading lua grammar"); +//! parser.set_language(&tree_sitter_lua::language()).expect("Error loading lua grammar"); //! let tree = parser.parse(code, None).unwrap(); +//! assert!(!tree.root_node().has_error()); //! ``` //! //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html @@ -31,14 +34,12 @@ pub fn language() -> Language { /// The content of the [`node-types.json`][] file for this grammar. /// /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types -pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); +pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); -// Uncomment these to include any queries that this grammar contains - -pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); -pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); -pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); -pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); +pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); +pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); +pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); +pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); #[cfg(test)] mod tests { @@ -46,7 +47,7 @@ mod tests { fn test_can_load_grammar() { let mut parser = tree_sitter::Parser::new(); parser - .set_language(super::language()) - .expect("Error loading lua language"); + .set_language(&super::language()) + .expect("Error loading Lua language"); } } diff --git a/bindings/swift/TreeSitterLua/lua.h b/bindings/swift/TreeSitterLua/lua.h new file mode 100644 index 000000000..1934db8e8 --- /dev/null +++ b/bindings/swift/TreeSitterLua/lua.h @@ -0,0 +1,16 @@ +#ifndef TREE_SITTER_LUA_H_ +#define TREE_SITTER_LUA_H_ + +typedef struct TSLanguage TSLanguage; + +#ifdef __cplusplus +extern "C" { +#endif + +const TSLanguage *tree_sitter_lua(void); + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_LUA_H_ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..420dd0f6d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "@muniftanjim/tree-sitter-lua", + "version": "0.0.19", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@muniftanjim/tree-sitter-lua", + "version": "0.0.19", + "license": "MIT", + "dependencies": { + "node-addon-api": "^7.1.0" + }, + "devDependencies": { + "tree-sitter-cli": "^0.21.0" + } + }, + "node_modules/node-addon-api": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.0.tgz", + "integrity": "sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g==", + "engines": { + "node": "^16 || ^18 || >= 20" + } + }, + "node_modules/tree-sitter-cli": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.21.0.tgz", + "integrity": "sha512-wA7wT5724fNQW82XDH6zT6ZcYonjrAKLCHHuhLsPcAKULrhp3rNuMvlgBdB5FUBvmjHNhtTZF/qpHenMoRJPBw==", + "dev": true, + "hasInstallScript": true, + "bin": { + "tree-sitter": "cli.js" + } + } + } +} diff --git a/package.json b/package.json index f7fa06fbc..b9dafde6e 100644 --- a/package.json +++ b/package.json @@ -2,35 +2,34 @@ "name": "@muniftanjim/tree-sitter-lua", "version": "0.0.19", "description": "Lua grammar for tree-sitter", + "repository": "tree-sitter-grammars/tree-sitter-lua", + "author": "Munif Tanjim (https://muniftanjim.dev)", + "license": "MIT", + "main": "bindings/node", + "types": "bindings/node", "keywords": [ + "incremental", + "parsing", "tree-sitter", - "parser", "lua" ], - "homepage": "https://github.com/tree-sitter-grammars/tree-sitter-lua#readme", - "bugs": "https://github.com/tree-sitter-grammars/tree-sitter-lua/issues", - "license": "MIT", - "author": "Munif Tanjim (https://muniftanjim.dev)", "files": [ - "bindings", - "queries", - "src", + "grammar.js", "binding.gyp", - "grammar.js" + "types/dsl.d.ts", + "bindings/node/*", + "queries/**", + "src/**" ], - "main": "bindings/node", - "repository": "https://github.com/tree-sitter-grammars/tree-sitter-lua", - "scripts": { - "build": "tree-sitter generate", - "postbuild": "node-gyp build", - "test": "tree-sitter test", - "posttest": "./script/parse-examples lua" - }, "dependencies": { - "nan": "^2.17.0" + "node-addon-api": "^7.1.0" }, "devDependencies": { - "tree-sitter-cli": "^0.20.8" + "tree-sitter-cli": "^0.21.0" + }, + "scripts": { + "build": "tree-sitter generate --no-bindings", + "test": "tree-sitter test" }, "publishConfig": { "access": "public" @@ -38,6 +37,9 @@ "tree-sitter": [ { "scope": "source.lua", + "highlights": "queries/highlights.scm", + "injections": "queries/injections.scm", + "tags": "queries/tags.scm", "file-types": [ "lua" ] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..905633939 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "tree-sitter-lua" +description = "Lua grammar for tree-sitter" +version = "0.0.19" +keywords = ["incremental", "parsing", "tree-sitter", "lua"] +classifiers = [ + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Topic :: Software Development :: Compilers", + "Topic :: Text Processing :: Linguistic", + "Typing :: Typed" +] +authors = [ + {name = "Munif Tanjim", email = "hello@muniftanjim.dev"} +] +requires-python = ">=3.8" +license.text = "MIT" +readme = "README.md" + +[project.urls] +Homepage = "https://github.com/tree-sitter-grammars/tree-sitter-lua" + +[project.optional-dependencies] +core = ["tree-sitter~=0.21"] + +[tool.cibuildwheel] +build = "cp38-*" +build-frontend = "build" diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..c1d124c76 --- /dev/null +++ b/setup.py @@ -0,0 +1,57 @@ +from os.path import isdir, join +from platform import system + +from setuptools import Extension, find_packages, setup +from setuptools.command.build import build +from wheel.bdist_wheel import bdist_wheel + + +class Build(build): + def run(self): + if isdir("queries"): + dest = join(self.build_lib, "tree_sitter_lua", "queries") + self.copy_tree("queries", dest) + super().run() + + +class BdistWheel(bdist_wheel): + def get_tag(self): + python, abi, platform = super().get_tag() + if python.startswith("cp"): + python, abi = "cp38", "abi3" + return python, abi, platform + + +setup( + packages=find_packages("bindings/python"), + package_dir={"": "bindings/python"}, + package_data={ + "tree_sitter_lua": ["*.pyi", "py.typed"], + "tree_sitter_lua.queries": ["*.scm"], + }, + ext_package="tree_sitter_lua", + ext_modules=[ + Extension( + name="_binding", + sources=[ + "bindings/python/tree_sitter_lua/binding.c", + "src/parser.c", + "src/scanner.c", + ], + extra_compile_args=( + ["-std=c11"] if system() != 'Windows' else [] + ), + define_macros=[ + ("Py_LIMITED_API", "0x03080000"), + ("PY_SSIZE_T_CLEAN", None) + ], + include_dirs=["src"], + py_limited_api=True, + ) + ], + cmdclass={ + "build": Build, + "bdist_wheel": BdistWheel + }, + zip_safe=False +) diff --git a/src/grammar.json b/src/grammar.json index f88415dae..1bae017b7 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1187,7 +1187,8 @@ }, { "type": "PATTERN", - "value": "U?LL" + "value": "U?LL", + "flags": "i" } ] }, @@ -1374,7 +1375,8 @@ }, { "type": "PATTERN", - "value": "U?LL" + "value": "U?LL", + "flags": "i" } ] }, @@ -3094,4 +3096,3 @@ "variable" ] } - diff --git a/src/parser.c b/src/parser.c index c9207e0d7..4e15b879e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,7 +1,6 @@ -#include +#include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -16,7 +15,7 @@ #define MAX_ALIAS_SEQUENCE_LENGTH 7 #define PRODUCTION_ID_COUNT 59 -enum { +enum ts_symbol_identifiers { sym_identifier = 1, sym_hash_bang_line = 2, anon_sym_return = 3, @@ -990,7 +989,7 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { }, }; -enum { +enum ts_field_identifiers { field_alternative = 1, field_arguments = 2, field_attribute = 3, @@ -1594,25 +1593,23 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '-') ADVANCE(69); if (lookahead == '.') ADVANCE(27); if (lookahead == '/') ADVANCE(71); - if (lookahead == '0') ADVANCE(33); + if (lookahead == '0') ADVANCE(34); if (lookahead == ':') ADVANCE(28); if (lookahead == ';') ADVANCE(22); if (lookahead == '<') ADVANCE(29); if (lookahead == '=') ADVANCE(23); if (lookahead == '>') ADVANCE(31); if (lookahead == '[') ADVANCE(54); - if (lookahead == '\\') ADVANCE(8); + if (lookahead == '\\') ADVANCE(6); if (lookahead == ']') ADVANCE(55); if (lookahead == '^') ADVANCE(75); if (lookahead == '{') ADVANCE(56); if (lookahead == '|') ADVANCE(62); if (lookahead == '}') ADVANCE(57); if (lookahead == '~') ADVANCE(64); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(17) - if (('1' <= lookahead && lookahead <= '9')) ADVANCE(34); + if (('1' <= lookahead && lookahead <= '9')) ADVANCE(33); if (lookahead != 0 && lookahead > 31 && (lookahead < 127 || 159 < lookahead)) ADVANCE(77); @@ -1620,20 +1617,16 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 1: if (lookahead == '"') ADVANCE(39); if (lookahead == '-') ADVANCE(42); - if (lookahead == '\\') ADVANCE(8); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (lookahead == '\\') ADVANCE(6); + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') ADVANCE(41); if (lookahead != 0) ADVANCE(43); END_STATE(); case 2: if (lookahead == '\'') ADVANCE(40); if (lookahead == '-') ADVANCE(45); - if (lookahead == '\\') ADVANCE(8); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (lookahead == '\\') ADVANCE(6); + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') ADVANCE(44); if (lookahead != 0) ADVANCE(46); END_STATE(); @@ -1651,32 +1644,34 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ('a' <= lookahead && lookahead <= 'f')) ADVANCE(35); END_STATE(); case 6: - if (lookahead == 'L') ADVANCE(32); - END_STATE(); - case 7: - if (lookahead == 'L') ADVANCE(6); - END_STATE(); - case 8: - if (lookahead == 'u') ADVANCE(9); + if (lookahead == 'u') ADVANCE(7); if (lookahead == 'x') ADVANCE(16); if (lookahead == 'z') ADVANCE(48); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(50); if (sym_escape_sequence_character_set_1(lookahead)) ADVANCE(47); END_STATE(); - case 9: + case 7: if (lookahead == '{') ADVANCE(15); END_STATE(); - case 10: + case 8: if (lookahead == '}') ADVANCE(47); if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'F') || - ('a' <= lookahead && lookahead <= 'f')) ADVANCE(10); + ('a' <= lookahead && lookahead <= 'f')) ADVANCE(8); END_STATE(); - case 11: + case 9: if (lookahead == '+' || lookahead == '-') ADVANCE(12); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(38); END_STATE(); + case 10: + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(32); + END_STATE(); + case 11: + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(10); + END_STATE(); case 12: if (('0' <= lookahead && lookahead <= '9')) ADVANCE(38); END_STATE(); @@ -1693,7 +1688,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 15: if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'F') || - ('a' <= lookahead && lookahead <= 'f')) ADVANCE(10); + ('a' <= lookahead && lookahead <= 'f')) ADVANCE(8); END_STATE(); case 16: if (('0' <= lookahead && lookahead <= '9') || @@ -1715,7 +1710,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '-') ADVANCE(69); if (lookahead == '.') ADVANCE(27); if (lookahead == '/') ADVANCE(71); - if (lookahead == '0') ADVANCE(33); + if (lookahead == '0') ADVANCE(34); if (lookahead == ':') ADVANCE(28); if (lookahead == ';') ADVANCE(22); if (lookahead == '<') ADVANCE(29); @@ -1728,11 +1723,9 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '|') ADVANCE(62); if (lookahead == '}') ADVANCE(57); if (lookahead == '~') ADVANCE(64); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(17) - if (('1' <= lookahead && lookahead <= '9')) ADVANCE(34); + if (('1' <= lookahead && lookahead <= '9')) ADVANCE(33); if (lookahead != 0 && lookahead > 31 && lookahead != '\\' && @@ -1747,18 +1740,16 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == ')') ADVANCE(53); if (lookahead == '-') ADVANCE(69); if (lookahead == '.') ADVANCE(3); - if (lookahead == '0') ADVANCE(33); + if (lookahead == '0') ADVANCE(34); if (lookahead == ';') ADVANCE(22); if (lookahead == '>') ADVANCE(30); if (lookahead == '[') ADVANCE(54); if (lookahead == '{') ADVANCE(56); if (lookahead == '}') ADVANCE(57); if (lookahead == '~') ADVANCE(63); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(18) - if (('1' <= lookahead && lookahead <= '9')) ADVANCE(34); + if (('1' <= lookahead && lookahead <= '9')) ADVANCE(33); if (lookahead != 0 && lookahead > 31 && (lookahead < '%' || '=' < lookahead) && @@ -1792,9 +1783,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '|') ADVANCE(62); if (lookahead == '}') ADVANCE(57); if (lookahead == '~') ADVANCE(64); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(19) if (lookahead != 0 && lookahead > 31 && @@ -1856,35 +1845,41 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(sym_number); if (lookahead == '.') ADVANCE(36); if (lookahead == 'E' || - lookahead == 'e') ADVANCE(11); + lookahead == 'e') ADVANCE(9); if (lookahead == 'I' || lookahead == 'i') ADVANCE(32); - if (lookahead == 'L') ADVANCE(6); - if (lookahead == 'U') ADVANCE(7); - if (lookahead == 'X' || - lookahead == 'x') ADVANCE(5); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34); + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(10); + if (lookahead == 'U' || + lookahead == 'u') ADVANCE(11); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(33); END_STATE(); case 34: ACCEPT_TOKEN(sym_number); if (lookahead == '.') ADVANCE(36); if (lookahead == 'E' || - lookahead == 'e') ADVANCE(11); + lookahead == 'e') ADVANCE(9); if (lookahead == 'I' || lookahead == 'i') ADVANCE(32); - if (lookahead == 'L') ADVANCE(6); - if (lookahead == 'U') ADVANCE(7); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34); + if (lookahead == 'X' || + lookahead == 'x') ADVANCE(5); + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(10); + if (lookahead == 'U' || + lookahead == 'u') ADVANCE(11); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(33); END_STATE(); case 35: ACCEPT_TOKEN(sym_number); if (lookahead == '.') ADVANCE(37); if (lookahead == 'I' || lookahead == 'i') ADVANCE(32); - if (lookahead == 'L') ADVANCE(6); if (lookahead == 'P' || - lookahead == 'p') ADVANCE(11); - if (lookahead == 'U') ADVANCE(7); + lookahead == 'p') ADVANCE(9); + if (lookahead == 'L' || + lookahead == 'l') ADVANCE(10); + if (lookahead == 'U' || + lookahead == 'u') ADVANCE(11); if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'F') || ('a' <= lookahead && lookahead <= 'f')) ADVANCE(35); @@ -1892,7 +1887,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 36: ACCEPT_TOKEN(sym_number); if (lookahead == 'E' || - lookahead == 'e') ADVANCE(11); + lookahead == 'e') ADVANCE(9); if (lookahead == 'I' || lookahead == 'i') ADVANCE(32); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(36); @@ -1902,7 +1897,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'I' || lookahead == 'i') ADVANCE(32); if (lookahead == 'P' || - lookahead == 'p') ADVANCE(11); + lookahead == 'p') ADVANCE(9); if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'F') || ('a' <= lookahead && lookahead <= 'f')) ADVANCE(37); @@ -1922,9 +1917,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 41: ACCEPT_TOKEN(aux_sym__doublequote_string_content_token1); if (lookahead == '-') ADVANCE(42); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') ADVANCE(41); if (lookahead != 0 && lookahead != '"' && @@ -1946,9 +1939,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 44: ACCEPT_TOKEN(aux_sym__singlequote_string_content_token1); if (lookahead == '-') ADVANCE(45); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') ADVANCE(44); if (lookahead != 0 && lookahead != '\'' && @@ -1972,9 +1963,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 48: ACCEPT_TOKEN(sym_escape_sequence); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') ADVANCE(48); END_STATE(); case 49: @@ -2090,10 +2079,11 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(aux_sym_comment_token1); if (lookahead == '-') ADVANCE(81); if (lookahead == '\t' || + lookahead == 11 || + lookahead == '\f' || lookahead == ' ') ADVANCE(80); if (lookahead != 0 && - lookahead != '\n' && - lookahead != '\r') ADVANCE(82); + (lookahead < '\n' || '\r' < lookahead)) ADVANCE(82); END_STATE(); case 81: ACCEPT_TOKEN(aux_sym_comment_token1); @@ -2132,9 +2122,7 @@ static bool ts_lex_keywords(TSLexer *lexer, TSStateId state) { if (lookahead == 't') ADVANCE(12); if (lookahead == 'u') ADVANCE(13); if (lookahead == 'w') ADVANCE(14); - if (lookahead == '\t' || - lookahead == '\n' || - lookahead == '\r' || + if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(0) END_STATE(); case 1: @@ -2649,58 +2637,6 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [261] = {(TSStateId)(-1)}, }; -enum { - ts_external_token__block_comment_start = 0, - ts_external_token__block_comment_content = 1, - ts_external_token__block_comment_end = 2, - ts_external_token__block_string_start = 3, - ts_external_token__block_string_content = 4, - ts_external_token__block_string_end = 5, -}; - -static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = { - [ts_external_token__block_comment_start] = sym__block_comment_start, - [ts_external_token__block_comment_content] = sym__block_comment_content, - [ts_external_token__block_comment_end] = sym__block_comment_end, - [ts_external_token__block_string_start] = sym__block_string_start, - [ts_external_token__block_string_content] = sym__block_string_content, - [ts_external_token__block_string_end] = sym__block_string_end, -}; - -static const bool ts_external_scanner_states[8][EXTERNAL_TOKEN_COUNT] = { - [1] = { - [ts_external_token__block_comment_start] = true, - [ts_external_token__block_comment_content] = true, - [ts_external_token__block_comment_end] = true, - [ts_external_token__block_string_start] = true, - [ts_external_token__block_string_content] = true, - [ts_external_token__block_string_end] = true, - }, - [2] = { - [ts_external_token__block_comment_start] = true, - }, - [3] = { - [ts_external_token__block_comment_start] = true, - [ts_external_token__block_string_start] = true, - }, - [4] = { - [ts_external_token__block_comment_start] = true, - [ts_external_token__block_comment_content] = true, - }, - [5] = { - [ts_external_token__block_comment_start] = true, - [ts_external_token__block_string_end] = true, - }, - [6] = { - [ts_external_token__block_comment_start] = true, - [ts_external_token__block_string_content] = true, - }, - [7] = { - [ts_external_token__block_comment_start] = true, - [ts_external_token__block_comment_end] = true, - }, -}; - static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [0] = { [sym_comment] = STATE(0), @@ -7093,7 +7029,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(69), 1, sym_comment, - STATE(103), 1, + STATE(104), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -7260,7 +7196,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(21), 1, + STATE(34), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -7380,7 +7316,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(74), 1, sym_comment, - STATE(108), 1, + STATE(116), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -7431,12 +7367,12 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(20), 1, - sym_expression, STATE(39), 1, sym__block_string, STATE(41), 1, sym__quote_string, + STATE(52), 1, + sym_expression, STATE(75), 1, sym_comment, STATE(156), 1, @@ -7488,14 +7424,14 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(37), 1, - sym_expression, STATE(39), 1, sym__block_string, STATE(41), 1, sym__quote_string, STATE(76), 1, sym_comment, + STATE(106), 1, + sym_expression, STATE(156), 1, sym__prefix_expression, STATE(159), 1, @@ -7545,7 +7481,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(35), 1, + STATE(20), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -7659,7 +7595,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(34), 1, + STATE(37), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -7716,7 +7652,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(38), 1, + STATE(35), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -7773,14 +7709,14 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, + STATE(38), 1, + sym_expression, STATE(39), 1, sym__block_string, STATE(41), 1, sym__quote_string, STATE(81), 1, sym_comment, - STATE(106), 1, - sym_expression, STATE(156), 1, sym__prefix_expression, STATE(159), 1, @@ -7830,7 +7766,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(23), 1, + STATE(21), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -7887,7 +7823,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(24), 1, + STATE(23), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -7944,7 +7880,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(25), 1, + STATE(24), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -8007,7 +7943,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(85), 1, sym_comment, - STATE(104), 1, + STATE(101), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8064,7 +8000,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(86), 1, sym_comment, - STATE(110), 1, + STATE(114), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8115,7 +8051,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(26), 1, + STATE(25), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -8172,7 +8108,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, - STATE(27), 1, + STATE(26), 1, sym_expression, STATE(39), 1, sym__block_string, @@ -8229,14 +8165,14 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_LBRACE, ACTIONS(264), 1, sym__block_string_start, + STATE(27), 1, + sym_expression, STATE(39), 1, sym__block_string, STATE(41), 1, sym__quote_string, STATE(89), 1, sym_comment, - STATE(99), 1, - sym_expression, STATE(156), 1, sym__prefix_expression, STATE(159), 1, @@ -8292,7 +8228,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(90), 1, sym_comment, - STATE(113), 1, + STATE(117), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8349,7 +8285,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(91), 1, sym_comment, - STATE(105), 1, + STATE(99), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8406,7 +8342,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(92), 1, sym_comment, - STATE(118), 1, + STATE(108), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8520,7 +8456,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(94), 1, sym_comment, - STATE(111), 1, + STATE(115), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8577,7 +8513,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(95), 1, sym_comment, - STATE(116), 1, + STATE(111), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8634,7 +8570,7 @@ static const uint16_t ts_small_parse_table[] = { sym__quote_string, STATE(96), 1, sym_comment, - STATE(114), 1, + STATE(105), 1, sym_expression, STATE(156), 1, sym__prefix_expression, @@ -8689,10 +8625,10 @@ static const uint16_t ts_small_parse_table[] = { sym__block_string, STATE(41), 1, sym__quote_string, - STATE(52), 1, - sym_expression, STATE(97), 1, sym_comment, + STATE(118), 1, + sym_expression, STATE(156), 1, sym__prefix_expression, STATE(159), 1, @@ -8868,44 +8804,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_function, anon_sym_local, sym_identifier, - [7759] = 9, - ACTIONS(3), 1, - anon_sym_DASH_DASH, - ACTIONS(5), 1, - sym__block_comment_start, - ACTIONS(306), 1, - anon_sym_COMMA, - ACTIONS(308), 1, - anon_sym_LT, - STATE(101), 1, - sym_comment, - STATE(115), 1, - aux_sym__att_name_list_repeat1, - STATE(117), 1, - sym__attrib, - ACTIONS(302), 5, - ts_builtin_sym_end, - anon_sym_SEMI, - anon_sym_EQ, - anon_sym_COLON_COLON, - anon_sym_LPAREN, - ACTIONS(304), 15, - anon_sym_return, - sym_break_statement, - anon_sym_goto, - anon_sym_do, - anon_sym_end, - anon_sym_while, - anon_sym_repeat, - anon_sym_until, - anon_sym_if, - anon_sym_elseif, - anon_sym_else, - anon_sym_for, - anon_sym_function, - anon_sym_local, - sym_identifier, - [7805] = 18, + [7759] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -8930,7 +8829,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_or, ACTIONS(292), 1, anon_sym_and, - STATE(102), 1, + STATE(101), 1, sym_comment, ACTIONS(127), 2, anon_sym_LT_LT, @@ -8942,7 +8841,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_STAR, anon_sym_SLASH_SLASH, anon_sym_PERCENT, - ACTIONS(310), 3, + ACTIONS(302), 3, anon_sym_SEMI, anon_sym_COMMA, anon_sym_RBRACE, @@ -8951,7 +8850,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_EQ_EQ, anon_sym_TILDE_EQ, anon_sym_GT_EQ, - [7869] = 20, + [7823] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -8972,18 +8871,12 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_TILDE, ACTIONS(137), 1, anon_sym_PIPE, - ACTIONS(286), 1, - anon_sym_COMMA, ACTIONS(290), 1, anon_sym_or, ACTIONS(292), 1, anon_sym_and, - ACTIONS(312), 1, - anon_sym_RPAREN, - STATE(103), 1, + STATE(102), 1, sym_comment, - STATE(197), 1, - aux_sym__expression_list_repeat1, ACTIONS(127), 2, anon_sym_LT_LT, anon_sym_GT_GT, @@ -8994,12 +8887,53 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_STAR, anon_sym_SLASH_SLASH, anon_sym_PERCENT, + ACTIONS(304), 3, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RBRACE, ACTIONS(135), 4, anon_sym_LT_EQ, anon_sym_EQ_EQ, anon_sym_TILDE_EQ, anon_sym_GT_EQ, - [7937] = 18, + [7887] = 9, + ACTIONS(3), 1, + anon_sym_DASH_DASH, + ACTIONS(5), 1, + sym__block_comment_start, + ACTIONS(310), 1, + anon_sym_COMMA, + ACTIONS(312), 1, + anon_sym_LT, + STATE(103), 1, + sym_comment, + STATE(109), 1, + aux_sym__att_name_list_repeat1, + STATE(110), 1, + sym__attrib, + ACTIONS(306), 5, + ts_builtin_sym_end, + anon_sym_SEMI, + anon_sym_EQ, + anon_sym_COLON_COLON, + anon_sym_LPAREN, + ACTIONS(308), 15, + anon_sym_return, + sym_break_statement, + anon_sym_goto, + anon_sym_do, + anon_sym_end, + anon_sym_while, + anon_sym_repeat, + anon_sym_until, + anon_sym_if, + anon_sym_elseif, + anon_sym_else, + anon_sym_for, + anon_sym_function, + anon_sym_local, + sym_identifier, + [7933] = 20, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -9020,12 +8954,18 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_TILDE, ACTIONS(137), 1, anon_sym_PIPE, + ACTIONS(286), 1, + anon_sym_COMMA, ACTIONS(290), 1, anon_sym_or, ACTIONS(292), 1, anon_sym_and, + ACTIONS(314), 1, + anon_sym_RPAREN, STATE(104), 1, sym_comment, + STATE(197), 1, + aux_sym__expression_list_repeat1, ACTIONS(127), 2, anon_sym_LT_LT, anon_sym_GT_GT, @@ -9036,10 +8976,6 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_STAR, anon_sym_SLASH_SLASH, anon_sym_PERCENT, - ACTIONS(314), 3, - anon_sym_SEMI, - anon_sym_COMMA, - anon_sym_RBRACE, ACTIONS(135), 4, anon_sym_LT_EQ, anon_sym_EQ_EQ, @@ -9142,11 +9078,11 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_DASH_DASH, ACTIONS(5), 1, sym__block_comment_start, - ACTIONS(308), 1, + ACTIONS(312), 1, anon_sym_LT, STATE(107), 1, sym_comment, - STATE(123), 1, + STATE(121), 1, sym__attrib, ACTIONS(322), 6, ts_builtin_sym_end, @@ -9197,7 +9133,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(292), 1, anon_sym_and, ACTIONS(326), 1, - anon_sym_COMMA, + anon_sym_then, STATE(108), 1, sym_comment, ACTIONS(127), 2, @@ -9220,11 +9156,11 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_DASH_DASH, ACTIONS(5), 1, sym__block_comment_start, - ACTIONS(306), 1, + ACTIONS(310), 1, anon_sym_COMMA, STATE(109), 1, sym_comment, - STATE(112), 1, + STATE(113), 1, aux_sym__att_name_list_repeat1, ACTIONS(328), 5, ts_builtin_sym_end, @@ -9248,51 +9184,40 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_function, anon_sym_local, sym_identifier, - [8273] = 18, + [8273] = 7, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, sym__block_comment_start, - ACTIONS(111), 1, - anon_sym_CARET, - ACTIONS(117), 1, - anon_sym_PLUS, - ACTIONS(119), 1, - anon_sym_DASH, - ACTIONS(123), 1, - anon_sym_SLASH, - ACTIONS(125), 1, - anon_sym_DOT_DOT, - ACTIONS(129), 1, - anon_sym_AMP, - ACTIONS(131), 1, - anon_sym_TILDE, - ACTIONS(137), 1, - anon_sym_PIPE, - ACTIONS(290), 1, - anon_sym_or, - ACTIONS(292), 1, - anon_sym_and, - ACTIONS(332), 1, - anon_sym_RBRACK, + ACTIONS(310), 1, + anon_sym_COMMA, STATE(110), 1, sym_comment, - ACTIONS(127), 2, - anon_sym_LT_LT, - anon_sym_GT_GT, - ACTIONS(133), 2, - anon_sym_LT, - anon_sym_GT, - ACTIONS(121), 3, - anon_sym_STAR, - anon_sym_SLASH_SLASH, - anon_sym_PERCENT, - ACTIONS(135), 4, - anon_sym_LT_EQ, - anon_sym_EQ_EQ, - anon_sym_TILDE_EQ, - anon_sym_GT_EQ, - [8335] = 18, + STATE(112), 1, + aux_sym__att_name_list_repeat1, + ACTIONS(332), 5, + ts_builtin_sym_end, + anon_sym_SEMI, + anon_sym_EQ, + anon_sym_COLON_COLON, + anon_sym_LPAREN, + ACTIONS(334), 15, + anon_sym_return, + sym_break_statement, + anon_sym_goto, + anon_sym_do, + anon_sym_end, + anon_sym_while, + anon_sym_repeat, + anon_sym_until, + anon_sym_if, + anon_sym_elseif, + anon_sym_else, + anon_sym_for, + anon_sym_function, + anon_sym_local, + sym_identifier, + [8313] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -9317,8 +9242,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_or, ACTIONS(292), 1, anon_sym_and, - ACTIONS(334), 1, - anon_sym_RPAREN, + ACTIONS(336), 1, + anon_sym_RBRACK, STATE(111), 1, sym_comment, ACTIONS(127), 2, @@ -9336,23 +9261,24 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_EQ_EQ, anon_sym_TILDE_EQ, anon_sym_GT_EQ, - [8397] = 6, + [8375] = 7, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, sym__block_comment_start, - ACTIONS(340), 1, + ACTIONS(310), 1, anon_sym_COMMA, - STATE(112), 2, + STATE(112), 1, sym_comment, + STATE(113), 1, aux_sym__att_name_list_repeat1, - ACTIONS(336), 5, + ACTIONS(338), 5, ts_builtin_sym_end, anon_sym_SEMI, anon_sym_EQ, anon_sym_COLON_COLON, anon_sym_LPAREN, - ACTIONS(338), 15, + ACTIONS(340), 15, anon_sym_return, sym_break_statement, anon_sym_goto, @@ -9368,7 +9294,39 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_function, anon_sym_local, sym_identifier, - [8435] = 18, + [8415] = 6, + ACTIONS(3), 1, + anon_sym_DASH_DASH, + ACTIONS(5), 1, + sym__block_comment_start, + ACTIONS(346), 1, + anon_sym_COMMA, + STATE(113), 2, + sym_comment, + aux_sym__att_name_list_repeat1, + ACTIONS(342), 5, + ts_builtin_sym_end, + anon_sym_SEMI, + anon_sym_EQ, + anon_sym_COLON_COLON, + anon_sym_LPAREN, + ACTIONS(344), 15, + anon_sym_return, + sym_break_statement, + anon_sym_goto, + anon_sym_do, + anon_sym_end, + anon_sym_while, + anon_sym_repeat, + anon_sym_until, + anon_sym_if, + anon_sym_elseif, + anon_sym_else, + anon_sym_for, + anon_sym_function, + anon_sym_local, + sym_identifier, + [8453] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -9393,9 +9351,9 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_or, ACTIONS(292), 1, anon_sym_and, - ACTIONS(343), 1, - anon_sym_do, - STATE(113), 1, + ACTIONS(349), 1, + anon_sym_RBRACK, + STATE(114), 1, sym_comment, ACTIONS(127), 2, anon_sym_LT_LT, @@ -9412,7 +9370,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_EQ_EQ, anon_sym_TILDE_EQ, anon_sym_GT_EQ, - [8497] = 18, + [8515] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -9437,9 +9395,9 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_or, ACTIONS(292), 1, anon_sym_and, - ACTIONS(345), 1, - anon_sym_do, - STATE(114), 1, + ACTIONS(351), 1, + anon_sym_RPAREN, + STATE(115), 1, sym_comment, ACTIONS(127), 2, anon_sym_LT_LT, @@ -9456,40 +9414,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_EQ_EQ, anon_sym_TILDE_EQ, anon_sym_GT_EQ, - [8559] = 7, - ACTIONS(3), 1, - anon_sym_DASH_DASH, - ACTIONS(5), 1, - sym__block_comment_start, - ACTIONS(306), 1, - anon_sym_COMMA, - STATE(112), 1, - aux_sym__att_name_list_repeat1, - STATE(115), 1, - sym_comment, - ACTIONS(347), 5, - ts_builtin_sym_end, - anon_sym_SEMI, - anon_sym_EQ, - anon_sym_COLON_COLON, - anon_sym_LPAREN, - ACTIONS(349), 15, - anon_sym_return, - sym_break_statement, - anon_sym_goto, - anon_sym_do, - anon_sym_end, - anon_sym_while, - anon_sym_repeat, - anon_sym_until, - anon_sym_if, - anon_sym_elseif, - anon_sym_else, - anon_sym_for, - anon_sym_function, - anon_sym_local, - sym_identifier, - [8599] = 18, + [8577] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, @@ -9514,8 +9439,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_or, ACTIONS(292), 1, anon_sym_and, - ACTIONS(351), 1, - anon_sym_RBRACK, + ACTIONS(353), 1, + anon_sym_COMMA, STATE(116), 1, sym_comment, ACTIONS(127), 2, @@ -9533,39 +9458,50 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_EQ_EQ, anon_sym_TILDE_EQ, anon_sym_GT_EQ, - [8661] = 7, + [8639] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, ACTIONS(5), 1, sym__block_comment_start, - ACTIONS(306), 1, - anon_sym_COMMA, - STATE(109), 1, - aux_sym__att_name_list_repeat1, + ACTIONS(111), 1, + anon_sym_CARET, + ACTIONS(117), 1, + anon_sym_PLUS, + ACTIONS(119), 1, + anon_sym_DASH, + ACTIONS(123), 1, + anon_sym_SLASH, + ACTIONS(125), 1, + anon_sym_DOT_DOT, + ACTIONS(129), 1, + anon_sym_AMP, + ACTIONS(131), 1, + anon_sym_TILDE, + ACTIONS(137), 1, + anon_sym_PIPE, + ACTIONS(290), 1, + anon_sym_or, + ACTIONS(292), 1, + anon_sym_and, + ACTIONS(355), 1, + anon_sym_do, STATE(117), 1, sym_comment, - ACTIONS(353), 5, - ts_builtin_sym_end, - anon_sym_SEMI, - anon_sym_EQ, - anon_sym_COLON_COLON, - anon_sym_LPAREN, - ACTIONS(355), 15, - anon_sym_return, - sym_break_statement, - anon_sym_goto, - anon_sym_do, - anon_sym_end, - anon_sym_while, - anon_sym_repeat, - anon_sym_until, - anon_sym_if, - anon_sym_elseif, - anon_sym_else, - anon_sym_for, - anon_sym_function, - anon_sym_local, - sym_identifier, + ACTIONS(127), 2, + anon_sym_LT_LT, + anon_sym_GT_GT, + ACTIONS(133), 2, + anon_sym_LT, + anon_sym_GT, + ACTIONS(121), 3, + anon_sym_STAR, + anon_sym_SLASH_SLASH, + anon_sym_PERCENT, + ACTIONS(135), 4, + anon_sym_LT_EQ, + anon_sym_EQ_EQ, + anon_sym_TILDE_EQ, + anon_sym_GT_EQ, [8701] = 18, ACTIONS(3), 1, anon_sym_DASH_DASH, @@ -9592,7 +9528,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(292), 1, anon_sym_and, ACTIONS(357), 1, - anon_sym_then, + anon_sym_do, STATE(118), 1, sym_comment, ACTIONS(127), 2, @@ -12051,22 +11987,22 @@ static const uint32_t ts_small_parse_table_map[] = { [SMALL_STATE(99)] = 7643, [SMALL_STATE(100)] = 7715, [SMALL_STATE(101)] = 7759, - [SMALL_STATE(102)] = 7805, - [SMALL_STATE(103)] = 7869, - [SMALL_STATE(104)] = 7937, + [SMALL_STATE(102)] = 7823, + [SMALL_STATE(103)] = 7887, + [SMALL_STATE(104)] = 7933, [SMALL_STATE(105)] = 8001, [SMALL_STATE(106)] = 8065, [SMALL_STATE(107)] = 8130, [SMALL_STATE(108)] = 8171, [SMALL_STATE(109)] = 8233, [SMALL_STATE(110)] = 8273, - [SMALL_STATE(111)] = 8335, - [SMALL_STATE(112)] = 8397, - [SMALL_STATE(113)] = 8435, - [SMALL_STATE(114)] = 8497, - [SMALL_STATE(115)] = 8559, - [SMALL_STATE(116)] = 8599, - [SMALL_STATE(117)] = 8661, + [SMALL_STATE(111)] = 8313, + [SMALL_STATE(112)] = 8375, + [SMALL_STATE(113)] = 8415, + [SMALL_STATE(114)] = 8453, + [SMALL_STATE(115)] = 8515, + [SMALL_STATE(116)] = 8577, + [SMALL_STATE(117)] = 8639, [SMALL_STATE(118)] = 8701, [SMALL_STATE(119)] = 8763, [SMALL_STATE(120)] = 8825, @@ -12270,21 +12206,21 @@ static const TSParseActionEntry ts_parse_actions[] = { [105] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_table_constructor, 3), [107] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_unary_expression, 2, .production_id = 16), [109] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_unary_expression, 2, .production_id = 16), - [111] = {.entry = {.count = 1, .reusable = true}}, SHIFT(76), + [111] = {.entry = {.count = 1, .reusable = true}}, SHIFT(79), [113] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_binary_expression, 3, .production_id = 29), [115] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_binary_expression, 3, .production_id = 29), - [117] = {.entry = {.count = 1, .reusable = true}}, SHIFT(80), - [119] = {.entry = {.count = 1, .reusable = false}}, SHIFT(80), - [121] = {.entry = {.count = 1, .reusable = true}}, SHIFT(79), - [123] = {.entry = {.count = 1, .reusable = false}}, SHIFT(79), - [125] = {.entry = {.count = 1, .reusable = true}}, SHIFT(77), - [127] = {.entry = {.count = 1, .reusable = true}}, SHIFT(72), + [117] = {.entry = {.count = 1, .reusable = true}}, SHIFT(81), + [119] = {.entry = {.count = 1, .reusable = false}}, SHIFT(81), + [121] = {.entry = {.count = 1, .reusable = true}}, SHIFT(72), + [123] = {.entry = {.count = 1, .reusable = false}}, SHIFT(72), + [125] = {.entry = {.count = 1, .reusable = true}}, SHIFT(80), + [127] = {.entry = {.count = 1, .reusable = true}}, SHIFT(82), [129] = {.entry = {.count = 1, .reusable = true}}, SHIFT(71), - [131] = {.entry = {.count = 1, .reusable = false}}, SHIFT(82), - [133] = {.entry = {.count = 1, .reusable = false}}, SHIFT(88), - [135] = {.entry = {.count = 1, .reusable = true}}, SHIFT(88), - [137] = {.entry = {.count = 1, .reusable = true}}, SHIFT(83), - [139] = {.entry = {.count = 1, .reusable = false}}, SHIFT(84), + [131] = {.entry = {.count = 1, .reusable = false}}, SHIFT(83), + [133] = {.entry = {.count = 1, .reusable = false}}, SHIFT(89), + [135] = {.entry = {.count = 1, .reusable = true}}, SHIFT(89), + [137] = {.entry = {.count = 1, .reusable = true}}, SHIFT(84), + [139] = {.entry = {.count = 1, .reusable = false}}, SHIFT(87), [141] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__function_body, 3, .production_id = 41), [143] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__function_body, 3, .production_id = 41), [145] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__function_body, 2, .production_id = 27), @@ -12314,7 +12250,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [206] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__variable_assignment_explist, 1, .production_id = 15), [208] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__variable_assignment_explist, 1, .production_id = 15), [210] = {.entry = {.count = 1, .reusable = true}}, SHIFT(78), - [212] = {.entry = {.count = 1, .reusable = false}}, SHIFT(87), + [212] = {.entry = {.count = 1, .reusable = false}}, SHIFT(88), [214] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_elseif_statement, 3, .production_id = 30), [216] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__variable_assignment_explist_repeat1, 2, .production_id = 50), [218] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__variable_assignment_explist_repeat1, 2, .production_id = 50), @@ -12338,8 +12274,8 @@ static const TSParseActionEntry ts_parse_actions[] = { [254] = {.entry = {.count = 1, .reusable = true}}, SHIFT(179), [256] = {.entry = {.count = 1, .reusable = true}}, SHIFT(182), [258] = {.entry = {.count = 1, .reusable = true}}, SHIFT(61), - [260] = {.entry = {.count = 1, .reusable = true}}, SHIFT(75), - [262] = {.entry = {.count = 1, .reusable = false}}, SHIFT(75), + [260] = {.entry = {.count = 1, .reusable = true}}, SHIFT(77), + [262] = {.entry = {.count = 1, .reusable = false}}, SHIFT(77), [264] = {.entry = {.count = 1, .reusable = true}}, SHIFT(249), [266] = {.entry = {.count = 1, .reusable = false}}, SHIFT(65), [268] = {.entry = {.count = 1, .reusable = true}}, SHIFT(95), @@ -12348,55 +12284,55 @@ static const TSParseActionEntry ts_parse_actions[] = { [274] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__field_list, 3), [276] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_return_statement, 1), [278] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__field_list, 2), - [280] = {.entry = {.count = 1, .reusable = false}}, SHIFT(91), + [280] = {.entry = {.count = 1, .reusable = false}}, SHIFT(96), [282] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), [284] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expression_list, 1), - [286] = {.entry = {.count = 1, .reusable = true}}, SHIFT(89), + [286] = {.entry = {.count = 1, .reusable = true}}, SHIFT(91), [288] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__expression_list, 1), - [290] = {.entry = {.count = 1, .reusable = true}}, SHIFT(87), - [292] = {.entry = {.count = 1, .reusable = true}}, SHIFT(84), + [290] = {.entry = {.count = 1, .reusable = true}}, SHIFT(88), + [292] = {.entry = {.count = 1, .reusable = true}}, SHIFT(87), [294] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__expression_list_repeat1, 2), [296] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__expression_list_repeat1, 2), [298] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_statement, 1), [300] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_statement, 1), - [302] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 1, .production_id = 4), - [304] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 1, .production_id = 4), - [306] = {.entry = {.count = 1, .reusable = true}}, SHIFT(217), - [308] = {.entry = {.count = 1, .reusable = true}}, SHIFT(241), - [310] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field, 1, .production_id = 15), - [312] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), - [314] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field, 5, .production_id = 56), + [302] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field, 5, .production_id = 56), + [304] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field, 1, .production_id = 15), + [306] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 1, .production_id = 4), + [308] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 1, .production_id = 4), + [310] = {.entry = {.count = 1, .reusable = true}}, SHIFT(217), + [312] = {.entry = {.count = 1, .reusable = true}}, SHIFT(241), + [314] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), [316] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field, 3, .production_id = 42), - [318] = {.entry = {.count = 1, .reusable = true}}, SHIFT(96), + [318] = {.entry = {.count = 1, .reusable = true}}, SHIFT(97), [320] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_for_numeric_clause, 5, .production_id = 55), [322] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 25), [324] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 25), - [326] = {.entry = {.count = 1, .reusable = true}}, SHIFT(81), - [328] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 3, .production_id = 36), - [330] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 3, .production_id = 36), - [332] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), - [334] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), - [336] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 37), - [338] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 37), - [340] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 37), SHIFT_REPEAT(217), - [343] = {.entry = {.count = 1, .reusable = true}}, SHIFT(50), - [345] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_for_numeric_clause, 7, .production_id = 58), - [347] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 2, .production_id = 21), - [349] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 2, .production_id = 21), - [351] = {.entry = {.count = 1, .reusable = true}}, SHIFT(228), - [353] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 2, .production_id = 20), - [355] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 2, .production_id = 20), - [357] = {.entry = {.count = 1, .reusable = true}}, SHIFT(46), + [326] = {.entry = {.count = 1, .reusable = true}}, SHIFT(46), + [328] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 2, .production_id = 21), + [330] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 2, .production_id = 21), + [332] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 2, .production_id = 20), + [334] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 2, .production_id = 20), + [336] = {.entry = {.count = 1, .reusable = true}}, SHIFT(228), + [338] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__att_name_list, 3, .production_id = 36), + [340] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__att_name_list, 3, .production_id = 36), + [342] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 37), + [344] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 37), + [346] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 2, .production_id = 37), SHIFT_REPEAT(217), + [349] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), + [351] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), + [353] = {.entry = {.count = 1, .reusable = true}}, SHIFT(76), + [355] = {.entry = {.count = 1, .reusable = true}}, SHIFT(50), + [357] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_for_numeric_clause, 7, .production_id = 58), [359] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42), [361] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__variable_assignment_explist_repeat1, 2, .production_id = 51), [363] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__variable_assignment_explist_repeat1, 2, .production_id = 51), [365] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__variable_assignment_explist_repeat1, 2, .production_id = 51), SHIFT_REPEAT(78), - [368] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__attrib, 3), - [370] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__attrib, 3), + [368] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 3, .production_id = 49), + [370] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__att_name_list_repeat1, 3, .production_id = 49), [372] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__variable_assignment_explist, 2, .production_id = 39), [374] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__variable_assignment_explist, 2, .production_id = 39), - [376] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__att_name_list_repeat1, 3, .production_id = 49), - [378] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__att_name_list_repeat1, 3, .production_id = 49), + [376] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__attrib, 3), + [378] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__attrib, 3), [380] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_variable_declaration, 2, .production_id = 9), [382] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_variable_declaration, 2, .production_id = 9), [384] = {.entry = {.count = 1, .reusable = true}}, SHIFT(68), @@ -12471,7 +12407,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [522] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__variable_assignment_varlist, 1, .production_id = 4), [524] = {.entry = {.count = 1, .reusable = true}}, SHIFT(161), [526] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__variable_assignment_varlist_repeat1, 2, .production_id = 25), - [528] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__expression_list_repeat1, 2), SHIFT_REPEAT(89), + [528] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__expression_list_repeat1, 2), SHIFT_REPEAT(91), [531] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), [533] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expression_list, 2), [535] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__expression_list, 2), @@ -12507,7 +12443,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [598] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__block, 2), [600] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym__block, 2), [602] = {.entry = {.count = 1, .reusable = true}}, SHIFT(187), - [604] = {.entry = {.count = 1, .reusable = false}}, SHIFT(101), + [604] = {.entry = {.count = 1, .reusable = false}}, SHIFT(103), [606] = {.entry = {.count = 1, .reusable = false}}, SHIFT(235), [608] = {.entry = {.count = 1, .reusable = false}}, SHIFT(15), [610] = {.entry = {.count = 1, .reusable = true}}, SHIFT(74), @@ -12556,7 +12492,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [699] = {.entry = {.count = 1, .reusable = true}}, SHIFT(209), [701] = {.entry = {.count = 1, .reusable = true}}, SHIFT(132), [703] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), - [705] = {.entry = {.count = 1, .reusable = true}}, SHIFT(121), + [705] = {.entry = {.count = 1, .reusable = true}}, SHIFT(123), [707] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_for_generic_clause, 3, .production_id = 34), [709] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), [711] = {.entry = {.count = 1, .reusable = true}}, SHIFT(85), @@ -12576,7 +12512,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [739] = {.entry = {.count = 1, .reusable = true}}, SHIFT(125), [741] = {.entry = {.count = 1, .reusable = true}}, SHIFT(67), [743] = {.entry = {.count = 1, .reusable = true}}, SHIFT(55), - [745] = {.entry = {.count = 1, .reusable = true}}, SHIFT(97), + [745] = {.entry = {.count = 1, .reusable = true}}, SHIFT(75), [747] = {.entry = {.count = 1, .reusable = true}}, SHIFT(141), [749] = {.entry = {.count = 1, .reusable = true}}, SHIFT(142), [751] = {.entry = {.count = 1, .reusable = true}}, SHIFT(154), @@ -12593,6 +12529,58 @@ static const TSParseActionEntry ts_parse_actions[] = { [773] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_comment, 3, .production_id = 12), }; +enum ts_external_scanner_symbol_identifiers { + ts_external_token__block_comment_start = 0, + ts_external_token__block_comment_content = 1, + ts_external_token__block_comment_end = 2, + ts_external_token__block_string_start = 3, + ts_external_token__block_string_content = 4, + ts_external_token__block_string_end = 5, +}; + +static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = { + [ts_external_token__block_comment_start] = sym__block_comment_start, + [ts_external_token__block_comment_content] = sym__block_comment_content, + [ts_external_token__block_comment_end] = sym__block_comment_end, + [ts_external_token__block_string_start] = sym__block_string_start, + [ts_external_token__block_string_content] = sym__block_string_content, + [ts_external_token__block_string_end] = sym__block_string_end, +}; + +static const bool ts_external_scanner_states[8][EXTERNAL_TOKEN_COUNT] = { + [1] = { + [ts_external_token__block_comment_start] = true, + [ts_external_token__block_comment_content] = true, + [ts_external_token__block_comment_end] = true, + [ts_external_token__block_string_start] = true, + [ts_external_token__block_string_content] = true, + [ts_external_token__block_string_end] = true, + }, + [2] = { + [ts_external_token__block_comment_start] = true, + }, + [3] = { + [ts_external_token__block_comment_start] = true, + [ts_external_token__block_string_start] = true, + }, + [4] = { + [ts_external_token__block_comment_start] = true, + [ts_external_token__block_comment_content] = true, + }, + [5] = { + [ts_external_token__block_comment_start] = true, + [ts_external_token__block_string_end] = true, + }, + [6] = { + [ts_external_token__block_comment_start] = true, + [ts_external_token__block_string_content] = true, + }, + [7] = { + [ts_external_token__block_comment_start] = true, + [ts_external_token__block_comment_end] = true, + }, +}; + #ifdef __cplusplus extern "C" { #endif @@ -12602,11 +12590,17 @@ bool tree_sitter_lua_external_scanner_scan(void *, TSLexer *, const bool *); unsigned tree_sitter_lua_external_scanner_serialize(void *, char *); void tree_sitter_lua_external_scanner_deserialize(void *, const char *, unsigned); +#ifdef TS_PUBLIC +#undef TS_PUBLIC +#endif + #ifdef _WIN32 -#define extern __declspec(dllexport) +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) #endif -extern const TSLanguage *tree_sitter_lua(void) { +TS_PUBLIC const TSLanguage *tree_sitter_lua() { static const TSLanguage language = { .version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h new file mode 100644 index 000000000..4cb7e187f --- /dev/null +++ b/src/tree_sitter/alloc.h @@ -0,0 +1,60 @@ +#ifndef TREE_SITTER_ALLOC_H_ +#define TREE_SITTER_ALLOC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#ifdef _WIN32 +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) +#endif + +TS_PUBLIC extern void *(*ts_current_malloc)(size_t); +TS_PUBLIC extern void *(*ts_current_calloc)(size_t, size_t); +TS_PUBLIC extern void *(*ts_current_realloc)(void *, size_t); +TS_PUBLIC extern void (*ts_current_free)(void *); + +// Allow clients to override allocation functions +#ifdef TREE_SITTER_REUSE_ALLOCATOR + +#ifndef ts_malloc +#define ts_malloc ts_current_malloc +#endif +#ifndef ts_calloc +#define ts_calloc ts_current_calloc +#endif +#ifndef ts_realloc +#define ts_realloc ts_current_realloc +#endif +#ifndef ts_free +#define ts_free ts_current_free +#endif + +#else + +#ifndef ts_malloc +#define ts_malloc malloc +#endif +#ifndef ts_calloc +#define ts_calloc calloc +#endif +#ifndef ts_realloc +#define ts_realloc realloc +#endif +#ifndef ts_free +#define ts_free free +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ALLOC_H_ diff --git a/src/tree_sitter/array.h b/src/tree_sitter/array.h new file mode 100644 index 000000000..186ba6739 --- /dev/null +++ b/src/tree_sitter/array.h @@ -0,0 +1,287 @@ +#ifndef TREE_SITTER_ARRAY_H_ +#define TREE_SITTER_ARRAY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "./alloc.h" + +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(disable : 4101) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +#define Array(T) \ + struct { \ + T *contents; \ + uint32_t size; \ + uint32_t capacity; \ + } + +/// Initialize an array. +#define array_init(self) \ + ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL) + +/// Create an empty array. +#define array_new() \ + { NULL, 0, 0 } + +/// Get a pointer to the element at a given `index` in the array. +#define array_get(self, _index) \ + (assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index]) + +/// Get a pointer to the first element in the array. +#define array_front(self) array_get(self, 0) + +/// Get a pointer to the last element in the array. +#define array_back(self) array_get(self, (self)->size - 1) + +/// Clear the array, setting its size to zero. Note that this does not free any +/// memory allocated for the array's contents. +#define array_clear(self) ((self)->size = 0) + +/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is +/// less than the array's current capacity, this function has no effect. +#define array_reserve(self, new_capacity) \ + _array__reserve((Array *)(self), array_elem_size(self), new_capacity) + +/// Free any memory allocated for this array. Note that this does not free any +/// memory allocated for the array's contents. +#define array_delete(self) _array__delete((Array *)(self)) + +/// Push a new `element` onto the end of the array. +#define array_push(self, element) \ + (_array__grow((Array *)(self), 1, array_elem_size(self)), \ + (self)->contents[(self)->size++] = (element)) + +/// Increase the array's size by `count` elements. +/// New elements are zero-initialized. +#define array_grow_by(self, count) \ + (_array__grow((Array *)(self), count, array_elem_size(self)), \ + memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)), \ + (self)->size += (count)) + +/// Append all elements from one array to the end of another. +#define array_push_all(self, other) \ + array_extend((self), (other)->size, (other)->contents) + +/// Append `count` elements to the end of the array, reading their values from the +/// `contents` pointer. +#define array_extend(self, count, contents) \ + _array__splice( \ + (Array *)(self), array_elem_size(self), (self)->size, \ + 0, count, contents \ + ) + +/// Remove `old_count` elements from the array starting at the given `index`. At +/// the same index, insert `new_count` new elements, reading their values from the +/// `new_contents` pointer. +#define array_splice(self, _index, old_count, new_count, new_contents) \ + _array__splice( \ + (Array *)(self), array_elem_size(self), _index, \ + old_count, new_count, new_contents \ + ) + +/// Insert one `element` into the array at the given `index`. +#define array_insert(self, _index, element) \ + _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element)) + +/// Remove one element from the array at the given `index`. +#define array_erase(self, _index) \ + _array__erase((Array *)(self), array_elem_size(self), _index) + +/// Pop the last element off the array, returning the element by value. +#define array_pop(self) ((self)->contents[--(self)->size]) + +/// Assign the contents of one array to another, reallocating if necessary. +#define array_assign(self, other) \ + _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self)) + +/// Swap one array with another +#define array_swap(self, other) \ + _array__swap((Array *)(self), (Array *)(other)) + +/// Get the size of the array contents +#define array_elem_size(self) (sizeof *(self)->contents) + +/// Search a sorted array for a given `needle` value, using the given `compare` +/// callback to determine the order. +/// +/// If an existing element is found to be equal to `needle`, then the `index` +/// out-parameter is set to the existing value's index, and the `exists` +/// out-parameter is set to true. Otherwise, `index` is set to an index where +/// `needle` should be inserted in order to preserve the sorting, and `exists` +/// is set to false. +#define array_search_sorted_with(self, compare, needle, _index, _exists) \ + _array__search_sorted(self, 0, compare, , needle, _index, _exists) + +/// Search a sorted array for a given `needle` value, using integer comparisons +/// of a given struct field (specified with a leading dot) to determine the order. +/// +/// See also `array_search_sorted_with`. +#define array_search_sorted_by(self, field, needle, _index, _exists) \ + _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists) + +/// Insert a given `value` into a sorted array, using the given `compare` +/// callback to determine the order. +#define array_insert_sorted_with(self, compare, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_with(self, compare, &(value), &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) + +/// Insert a given `value` into a sorted array, using integer comparisons of +/// a given struct field (specified with a leading dot) to determine the order. +/// +/// See also `array_search_sorted_by`. +#define array_insert_sorted_by(self, field, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_by(self, field, (value) field, &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) + +// Private + +typedef Array(void) Array; + +/// This is not what you're looking for, see `array_delete`. +static inline void _array__delete(Array *self) { + if (self->contents) { + ts_free(self->contents); + self->contents = NULL; + self->size = 0; + self->capacity = 0; + } +} + +/// This is not what you're looking for, see `array_erase`. +static inline void _array__erase(Array *self, size_t element_size, + uint32_t index) { + assert(index < self->size); + char *contents = (char *)self->contents; + memmove(contents + index * element_size, contents + (index + 1) * element_size, + (self->size - index - 1) * element_size); + self->size--; +} + +/// This is not what you're looking for, see `array_reserve`. +static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) { + if (new_capacity > self->capacity) { + if (self->contents) { + self->contents = ts_realloc(self->contents, new_capacity * element_size); + } else { + self->contents = ts_malloc(new_capacity * element_size); + } + self->capacity = new_capacity; + } +} + +/// This is not what you're looking for, see `array_assign`. +static inline void _array__assign(Array *self, const Array *other, size_t element_size) { + _array__reserve(self, element_size, other->size); + self->size = other->size; + memcpy(self->contents, other->contents, self->size * element_size); +} + +/// This is not what you're looking for, see `array_swap`. +static inline void _array__swap(Array *self, Array *other) { + Array swap = *other; + *other = *self; + *self = swap; +} + +/// This is not what you're looking for, see `array_push` or `array_grow_by`. +static inline void _array__grow(Array *self, uint32_t count, size_t element_size) { + uint32_t new_size = self->size + count; + if (new_size > self->capacity) { + uint32_t new_capacity = self->capacity * 2; + if (new_capacity < 8) new_capacity = 8; + if (new_capacity < new_size) new_capacity = new_size; + _array__reserve(self, element_size, new_capacity); + } +} + +/// This is not what you're looking for, see `array_splice`. +static inline void _array__splice(Array *self, size_t element_size, + uint32_t index, uint32_t old_count, + uint32_t new_count, const void *elements) { + uint32_t new_size = self->size + new_count - old_count; + uint32_t old_end = index + old_count; + uint32_t new_end = index + new_count; + assert(old_end <= self->size); + + _array__reserve(self, element_size, new_size); + + char *contents = (char *)self->contents; + if (self->size > old_end) { + memmove( + contents + new_end * element_size, + contents + old_end * element_size, + (self->size - old_end) * element_size + ); + } + if (new_count > 0) { + if (elements) { + memcpy( + (contents + index * element_size), + elements, + new_count * element_size + ); + } else { + memset( + (contents + index * element_size), + 0, + new_count * element_size + ); + } + } + self->size += new_count - old_count; +} + +/// A binary search routine, based on Rust's `std::slice::binary_search_by`. +/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`. +#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \ + do { \ + *(_index) = start; \ + *(_exists) = false; \ + uint32_t size = (self)->size - *(_index); \ + if (size == 0) break; \ + int comparison; \ + while (size > 1) { \ + uint32_t half_size = size / 2; \ + uint32_t mid_index = *(_index) + half_size; \ + comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \ + if (comparison <= 0) *(_index) = mid_index; \ + size -= half_size; \ + } \ + comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \ + if (comparison == 0) *(_exists) = true; \ + else if (comparison < 0) *(_index) += 1; \ + } while (0) + +/// Helper macro for the `_sorted_by` routines below. This takes the left (existing) +/// parameter by reference in order to work with the generic sorting function above. +#define _compare_int(a, b) ((int)*(a) - (int)(b)) + +#ifdef _MSC_VER +#pragma warning(default : 4101) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ARRAY_H_ diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 2b14ac104..17b4fde98 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -13,9 +13,8 @@ extern "C" { #define ts_builtin_sym_end 0 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 -typedef uint16_t TSStateId; - #ifndef TREE_SITTER_API_H_ +typedef uint16_t TSStateId; typedef uint16_t TSSymbol; typedef uint16_t TSFieldId; typedef struct TSLanguage TSLanguage; @@ -130,9 +129,16 @@ struct TSLanguage { * Lexer Macros */ +#ifdef _MSC_VER +#define UNUSED __pragma(warning(suppress : 4101)) +#else +#define UNUSED __attribute__((unused)) +#endif + #define START_LEXER() \ bool result = false; \ bool skip = false; \ + UNUSED \ bool eof = false; \ int32_t lookahead; \ goto start; \ @@ -166,7 +172,7 @@ struct TSLanguage { * Parse Table Macros */ -#define SMALL_STATE(id) id - LARGE_STATE_COUNT +#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) #define STATE(id) id @@ -176,7 +182,7 @@ struct TSLanguage { {{ \ .shift = { \ .type = TSParseActionTypeShift, \ - .state = state_value \ + .state = (state_value) \ } \ }} @@ -184,7 +190,7 @@ struct TSLanguage { {{ \ .shift = { \ .type = TSParseActionTypeShift, \ - .state = state_value, \ + .state = (state_value), \ .repetition = true \ } \ }}