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.
- package/LICENSE +1 -1
- package/README.md +3 -2
- package/binding.gyp +22 -6
- package/bindings/node/binding.cc +12 -23
- package/bindings/node/index.d.ts +60 -0
- package/bindings/node/index.js +33 -15
- package/grammar.js +193 -170
- package/package.json +47 -32
- package/prebuilds/darwin-arm64/tree-sitter-kdl.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-kdl.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-kdl.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-kdl.node +0 -0
- package/prebuilds/win32-arm64/tree-sitter-kdl.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-kdl.node +0 -0
- package/queries/highlights.scm +37 -17
- package/queries/indents.scm +1 -1
- package/queries/injections.scm +10 -0
- package/queries/locals.scm +3 -3
- package/src/grammar.json +744 -761
- package/src/node-types.json +271 -238
- package/src/parser.c +12895 -11901
- package/src/scanner.c +162 -55
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +336 -0
- package/src/tree_sitter/parser.h +79 -17
- package/tree-sitter-kdl.wasm +0 -0
- package/tree-sitter.json +44 -0
- package/.eslintrc.js +0 -20
- package/.gitattributes +0 -7
- package/.github/workflows/ci.yml +0 -34
- package/.github/workflows/fuzz.yml +0 -21
- package/.github/workflows/lint.yml +0 -19
- package/.github/workflows/publish.yml +0 -81
- package/.github/workflows/release.yml +0 -35
- package/CHANGELOG.md +0 -14
- package/Cargo.toml +0 -27
- package/Package.swift +0 -38
- package/bindings/rust/README.md +0 -39
- package/bindings/rust/build.rs +0 -19
- package/bindings/rust/lib.rs +0 -68
- 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 <
|
|
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
|
[](https://github.com/amaanq/tree-sitter-kdl/actions/workflows/ci.yml)
|
|
4
4
|
[](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
|
-
|
|
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
|
-
"
|
|
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
|
-
"
|
|
15
|
-
"-
|
|
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
|
}
|
package/bindings/node/binding.cc
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
#include
|
|
2
|
-
#include "tree_sitter/parser.h"
|
|
3
|
-
#include <node.h>
|
|
1
|
+
#include <napi.h>
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
6
4
|
|
|
7
5
|
extern "C" TSLanguage *tree_sitter_kdl();
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
|
+
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
9
|
+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
10
|
+
};
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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;
|
package/bindings/node/index.js
CHANGED
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
}
|
|
34
|
+
});
|
|
15
35
|
}
|
|
16
36
|
|
|
17
|
-
|
|
18
|
-
module.exports.nodeTypeInfo = require('../../src/node-types.json');
|
|
19
|
-
} catch (_) {}
|
|
37
|
+
export default binding;
|