diff --git a/Cargo.toml b/Cargo.toml index 1f6e658..9c54d10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-python" description = "Python grammar for tree-sitter" -version = "0.20.4" +version = "0.21.0" authors = [ "Max Brunsfeld ", "Amaan Qureshi ", diff --git a/Makefile b/Makefile index f83eb21..199bfab 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.0.1 +VERSION := 0.21.0 LANGUAGE_NAME := tree-sitter-python @@ -15,6 +15,8 @@ ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),) endif endif +TS ?= tree-sitter + # ABI versioning SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) @@ -79,6 +81,9 @@ $(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in -e 's|=$(PREFIX)|=$${prefix}|' \ -e 's|@PREFIX@|$(PREFIX)|' $< > $@ +$(SRC_DIR)/parser.c: grammar.js + $(TS) generate --no-bindings + 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 @@ -99,4 +104,7 @@ uninstall: clean: $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) -.PHONY: all install uninstall clean +test: + $(TS) test + +.PHONY: all install uninstall clean test diff --git a/Package.swift b/Package.swift index f0ba6b7..6cd9539 100644 --- a/Package.swift +++ b/Package.swift @@ -32,16 +32,16 @@ let package = Package( ".github", ".gitignore", ".gitattributes", - ".gitmodules", ], sources: [ "src/parser.c", - // NOTE: if your language has an external scanner, add it here. + "src/scanner.c", ], resources: [ .copy("queries") ], publicHeadersPath: "bindings/swift", cSettings: [.headerSearchPath("src")]) - ] + ], + cLanguageStandard: .c11 ) diff --git a/binding.gyp b/binding.gyp index a2d04f2..3724f73 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,8 +2,10 @@ "targets": [ { "target_name": "tree_sitter_python_binding", + "dependencies": [ + " - -using namespace v8; +#include typedef struct TSLanguage TSLanguage; -extern "C" const TSLanguage *tree_sitter_python(void); - -namespace { - -NAN_METHOD(New) {} +extern "C" TSLanguage *tree_sitter_python(); -void Init(Local exports, Local module) { - Local tpl = Nan::New(New); - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); +// "tree-sitter", "language" hashed with BLAKE2 +const napi_type_tag LANGUAGE_TYPE_TAG = { + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 +}; - Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); - Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, (void *)tree_sitter_python()); - - Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("python").ToLocalChecked()); - Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports["name"] = Napi::String::New(env, "python"); + auto language = Napi::External::New(env, tree_sitter_python()); + language.TypeTag(&LANGUAGE_TYPE_TAG); + exports["language"] = language; + return exports; } -NODE_MODULE_CONTEXT_AWARE(tree_sitter_python_binding, Init) - -} // namespace +NODE_API_MODULE(tree_sitter_python_binding, Init) diff --git a/bindings/node/index.d.ts b/bindings/node/index.d.ts new file mode 100644 index 0000000..efe259e --- /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/package-lock.json b/package-lock.json index d2ec89d..f7e36e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "tree-sitter-python", - "version": "0.20.4", + "version": "0.21.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tree-sitter-python", - "version": "0.20.4", + "version": "0.21.0", "license": "MIT", "dependencies": { - "nan": "^2.18.0" + "node-addon-api": "^7.1.0" }, "devDependencies": { "eslint": "^8.57.0", @@ -807,17 +807,20 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "node_modules/nan": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", - "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==" - }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "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/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", diff --git a/package.json b/package.json index cb627bd..812cba4 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,29 @@ { "name": "tree-sitter-python", - "version": "0.20.4", + "version": "0.21.0", "description": "Python grammar for tree-sitter", "main": "bindings/node", + "types": "bindings/node", + "files": [ + "grammar.js", + "binding.gyp", + "bindings/node/*", + "queries/*", + "src/**" + ], "keywords": [ - "parser", - "lexer", + "incremental", + "parsing", + "tree-sitter", "python" ], "author": "Max Brunsfeld", + "maintainers": [ + "Amaan Qureshi" + ], "license": "MIT", "dependencies": { - "nan": "^2.18.0" + "node-addon-api": "^7.1.0" }, "devDependencies": { "eslint": "^8.57.0", @@ -19,7 +31,7 @@ "tree-sitter-cli": "^0.21.0" }, "scripts": { - "build": "tree-sitter generate && node-gyp build", + "build": "tree-sitter generate --no-bindings", "lint": "eslint grammar.js", "parse": "tree-sitter parse", "test": "tree-sitter test" diff --git a/pyproject.toml b/pyproject.toml index a8eca35..c143b03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "tree-sitter-python" description = "Python grammar for tree-sitter" -version = "0.0.1" +version = "0.21.0" keywords = ["parsing", "incremental", "python"] classifiers = [ "Development Status :: 4 - Beta", @@ -14,8 +14,12 @@ classifiers = [ "Topic :: Software Development :: Compilers", "Topic :: Text Processing :: Linguistic", ] +authors = [ + {name = "Max Brunsfeld"}, + {name = "Amaan Qureshi"} +] requires-python = ">=3.8" -license.file = "LICENSE" +license.text = "MIT" readme = "README.md" [project.optional-dependencies]