tree-sitter-kdl 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -2
  3. package/binding.gyp +22 -6
  4. package/bindings/node/binding.cc +12 -23
  5. package/bindings/node/index.d.ts +60 -0
  6. package/bindings/node/index.js +33 -15
  7. package/grammar.js +193 -170
  8. package/package.json +47 -32
  9. package/prebuilds/darwin-arm64/tree-sitter-kdl.node +0 -0
  10. package/prebuilds/darwin-x64/tree-sitter-kdl.node +0 -0
  11. package/prebuilds/linux-arm64/tree-sitter-kdl.node +0 -0
  12. package/prebuilds/linux-x64/tree-sitter-kdl.node +0 -0
  13. package/prebuilds/win32-arm64/tree-sitter-kdl.node +0 -0
  14. package/prebuilds/win32-x64/tree-sitter-kdl.node +0 -0
  15. package/queries/highlights.scm +37 -17
  16. package/queries/indents.scm +1 -1
  17. package/queries/injections.scm +10 -0
  18. package/queries/locals.scm +3 -3
  19. package/src/grammar.json +744 -761
  20. package/src/node-types.json +271 -238
  21. package/src/parser.c +12895 -11901
  22. package/src/scanner.c +162 -55
  23. package/src/tree_sitter/alloc.h +54 -0
  24. package/src/tree_sitter/array.h +336 -0
  25. package/src/tree_sitter/parser.h +79 -17
  26. package/tree-sitter-kdl.wasm +0 -0
  27. package/tree-sitter.json +44 -0
  28. package/.eslintrc.js +0 -20
  29. package/.gitattributes +0 -7
  30. package/.github/workflows/ci.yml +0 -34
  31. package/.github/workflows/fuzz.yml +0 -21
  32. package/.github/workflows/lint.yml +0 -19
  33. package/.github/workflows/publish.yml +0 -81
  34. package/.github/workflows/release.yml +0 -35
  35. package/CHANGELOG.md +0 -14
  36. package/Cargo.toml +0 -27
  37. package/Package.swift +0 -38
  38. package/bindings/rust/README.md +0 -39
  39. package/bindings/rust/build.rs +0 -19
  40. package/bindings/rust/lib.rs +0 -68
  41. package/bindings/swift/kdl.h +0 -16
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023 Amaan Qureshi <amaanq12@gmail.com>, Andrew Hlynskyi <ahlincq@gmail.com>
3
+ Copyright (c) 2023 Amaan Qureshi <contact@amaanq.com>, Andrew Hlynskyi <ahlincq@gmail.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Build Status](https://github.com/amaanq/tree-sitter-kdl/actions/workflows/ci.yml/badge.svg)](https://github.com/amaanq/tree-sitter-kdl/actions/workflows/ci.yml)
4
4
  [![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord)](https://discord.gg/w7nTvsVJhm)
5
5
 
6
- KDL grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
6
+ KDL 1 and KDL 2 grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
7
7
 
8
- Adapted from the [official spec](https://github.com/kdl-org/kdl/blob/main/SPEC.md)
8
+ The grammar follows the [KDL 2.0 specification](https://github.com/kdl-org/kdl/blob/2.0.0/SPEC.md)
9
+ while preserving syntax from the [KDL 1.0 specification](https://github.com/kdl-org/kdl/blob/1.0.0/SPEC.md).
package/binding.gyp CHANGED
@@ -2,18 +2,34 @@
2
2
  "targets": [
3
3
  {
4
4
  "target_name": "tree_sitter_kdl_binding",
5
+ "dependencies": [
6
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
7
+ ],
5
8
  "include_dirs": [
6
- "<!(node -e \"require('nan')\")",
7
- "src"
9
+ "src",
8
10
  ],
9
11
  "sources": [
10
12
  "bindings/node/binding.cc",
11
13
  "src/parser.c",
12
- "src/scanner.c",
13
14
  ],
14
- "cflags_c": [
15
- "-std=c99",
16
- ]
15
+ "variables": {
16
+ "has_scanner": "<!(node -p \"fs.existsSync('src/scanner.c')\")"
17
+ },
18
+ "conditions": [
19
+ ["has_scanner=='true'", {
20
+ "sources+": ["src/scanner.c"],
21
+ }],
22
+ ["OS!='win'", {
23
+ "cflags_c": [
24
+ "-std=c11",
25
+ ],
26
+ }, { # OS == "win"
27
+ "cflags_c": [
28
+ "/std:c11",
29
+ "/utf-8",
30
+ ],
31
+ }],
32
+ ],
17
33
  }
18
34
  ]
19
35
  }
@@ -1,30 +1,19 @@
1
- #include "nan.h"
2
- #include "tree_sitter/parser.h"
3
- #include <node.h>
1
+ #include <napi.h>
4
2
 
5
- using namespace v8;
3
+ typedef struct TSLanguage TSLanguage;
6
4
 
7
5
  extern "C" TSLanguage *tree_sitter_kdl();
8
6
 
9
- namespace {
7
+ // "tree-sitter", "language" hashed with BLAKE2
8
+ const napi_type_tag LANGUAGE_TYPE_TAG = {
9
+ 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
10
+ };
10
11
 
11
- NAN_METHOD(New) {}
12
-
13
- void Init(Local<Object> exports, Local<Object> module) {
14
- Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15
- tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
17
-
18
- Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19
- Local<Object> instance =
20
- constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
21
- Nan::SetInternalFieldPointer(instance, 0, tree_sitter_kdl());
22
-
23
- Nan::Set(instance, Nan::New("name").ToLocalChecked(),
24
- Nan::New("kdl").ToLocalChecked());
25
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
12
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
13
+ auto language = Napi::External<TSLanguage>::New(env, tree_sitter_kdl());
14
+ language.TypeTag(&LANGUAGE_TYPE_TAG);
15
+ exports["language"] = language;
16
+ return exports;
26
17
  }
27
18
 
28
- NODE_MODULE(tree_sitter_kdl_binding, Init)
29
-
30
- } // namespace
19
+ NODE_API_MODULE(tree_sitter_kdl_binding, Init)
@@ -0,0 +1,60 @@
1
+ type BaseNode = {
2
+ type: string;
3
+ named: boolean;
4
+ };
5
+
6
+ type ChildNode = {
7
+ multiple: boolean;
8
+ required: boolean;
9
+ types: BaseNode[];
10
+ };
11
+
12
+ type NodeInfo =
13
+ | (BaseNode & {
14
+ subtypes: BaseNode[];
15
+ })
16
+ | (BaseNode & {
17
+ fields: { [name: string]: ChildNode };
18
+ children: ChildNode[];
19
+ });
20
+
21
+ /**
22
+ * The tree-sitter language object for this grammar.
23
+ *
24
+ * @see {@linkcode https://tree-sitter.github.io/node-tree-sitter/interfaces/Language.html Parser.Language}
25
+ *
26
+ * @example
27
+ * import Parser from "tree-sitter";
28
+ * import KDL from "tree-sitter-kdl";
29
+ *
30
+ * const parser = new Parser();
31
+ * parser.setLanguage(KDL);
32
+ */
33
+ declare const binding: {
34
+ /**
35
+ * The inner language object.
36
+ * @private
37
+ */
38
+ language: unknown;
39
+
40
+ /**
41
+ * The content of the `node-types.json` file for this grammar.
42
+ *
43
+ * @see {@linkplain https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types Static Node Types}
44
+ */
45
+ nodeTypeInfo: NodeInfo[];
46
+
47
+ /** The syntax highlighting query for this grammar. */
48
+ HIGHLIGHTS_QUERY?: string;
49
+
50
+ /** The language injection query for this grammar. */
51
+ INJECTIONS_QUERY?: string;
52
+
53
+ /** The local variable query for this grammar. */
54
+ LOCALS_QUERY?: string;
55
+
56
+ /** The symbol tagging query for this grammar. */
57
+ TAGS_QUERY?: string;
58
+ };
59
+
60
+ export default binding;
@@ -1,19 +1,37 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ const root = fileURLToPath(new URL("../..", import.meta.url));
5
+
6
+ const binding = typeof process.versions.bun === "string"
7
+ // Bun needs a static path to find the native module during `bun build --compile`.
8
+ ? await import(`${root}/prebuilds/${process.platform}-${process.arch}/tree-sitter-kdl.node`)
9
+ : (await import("node-gyp-build")).default(root);
10
+
1
11
  try {
2
- module.exports = require('../../build/Release/tree_sitter_kdl_binding');
3
- } catch (error1) {
4
- if (error1.code !== 'MODULE_NOT_FOUND') {
5
- throw error1;
6
- }
7
- try {
8
- module.exports = require('../../build/Debug/tree_sitter_kdl_binding');
9
- } catch (error2) {
10
- if (error2.code !== 'MODULE_NOT_FOUND') {
11
- throw error2;
12
+ const nodeTypes = await import(`${root}/src/node-types.json`, { with: { type: "json" } });
13
+ binding.nodeTypeInfo = nodeTypes.default;
14
+ } catch { }
15
+
16
+ const queries = [
17
+ ["HIGHLIGHTS_QUERY", `${root}/queries/highlights.scm`],
18
+ ["INJECTIONS_QUERY", `${root}/queries/injections.scm`],
19
+ ["LOCALS_QUERY", `${root}/queries/locals.scm`],
20
+ ["TAGS_QUERY", `${root}/queries/tags.scm`],
21
+ ];
22
+
23
+ for (const [prop, path] of queries) {
24
+ Object.defineProperty(binding, prop, {
25
+ configurable: true,
26
+ enumerable: true,
27
+ get() {
28
+ delete binding[prop];
29
+ try {
30
+ binding[prop] = readFileSync(path, "utf8");
31
+ } catch { }
32
+ return binding[prop];
12
33
  }
13
- throw error1;
14
- }
34
+ });
15
35
  }
16
36
 
17
- try {
18
- module.exports.nodeTypeInfo = require('../../src/node-types.json');
19
- } catch (_) {}
37
+ export default binding;