@konomanoasa/tree-sitter-diagnostic-dash 0.0.0-stage → 0.2.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/Cargo.toml +37 -0
- package/LICENSE +21 -0
- package/PARSING_POLICY.md +11 -0
- package/README.md +35 -2
- package/binding.gyp +38 -0
- package/bindings/node/binding.cc +25 -0
- package/bindings/node/index.d.ts +5 -0
- package/bindings/node/index.js +10 -0
- package/bindings/python/__init__.py +3 -0
- package/bindings/python/binding.c +34 -0
- package/bindings/python/binding.pyi +3 -0
- package/bindings/python/py.typed +0 -0
- package/bindings/rust/build.rs +13 -0
- package/bindings/rust/lib.rs +9 -0
- package/grammar.js +71 -0
- package/package.json +68 -4
- package/pyproject.toml +58 -0
- package/scripts/tree-sitter.js +83 -0
- package/setup.py +32 -0
- package/src/grammar.json +1356 -0
- package/src/node-types.json +2541 -0
- package/src/parser.c +11814 -0
- package/src/scanner.c +1906 -0
- package/src/tokens.h +69 -0
- package/src/tokens.json +289 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +336 -0
- package/src/tree_sitter/parser.h +286 -0
- package/test/bindings.test.rs +18 -0
- package/tree-sitter.json +28 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "konomanoasa-tree-sitter-diagnostic-dash"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Tree-sitter grammar for diagnostics of dash."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
repository = "https://github.com/konomanoasa/tree-sitter-diagnostic-dash"
|
|
8
|
+
edition = "2024"
|
|
9
|
+
build = "bindings/rust/build.rs"
|
|
10
|
+
links = "tree-sitter-diagnostic-dash"
|
|
11
|
+
include = [
|
|
12
|
+
"/LICENSE",
|
|
13
|
+
"/PARSING_POLICY.md",
|
|
14
|
+
"/README.md",
|
|
15
|
+
"/bindings/rust/*.rs",
|
|
16
|
+
"/src/*.c",
|
|
17
|
+
"/src/*.h",
|
|
18
|
+
"/src/node-types.json",
|
|
19
|
+
"/src/tree_sitter/*.h",
|
|
20
|
+
"/test/bindings.test.rs",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[lib]
|
|
24
|
+
path = "bindings/rust/lib.rs"
|
|
25
|
+
|
|
26
|
+
[[test]]
|
|
27
|
+
name = "bindings"
|
|
28
|
+
path = "test/bindings.test.rs"
|
|
29
|
+
|
|
30
|
+
[dependencies]
|
|
31
|
+
tree-sitter-language = "=0.1.9"
|
|
32
|
+
|
|
33
|
+
[dev-dependencies]
|
|
34
|
+
tree-sitter = "=0.27.2"
|
|
35
|
+
|
|
36
|
+
[build-dependencies]
|
|
37
|
+
cc = "=1.12.0"
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 konomanoasa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Parsing Policy
|
|
2
|
+
|
|
3
|
+
`diagnostic_dash` parses source using [dash 0.5.13.5](https://manpages.debian.org/experimental/dash/dash.1.en.html)
|
|
4
|
+
default settings.
|
|
5
|
+
|
|
6
|
+
These commands are parsed without changing how subsequent source is parsed.
|
|
7
|
+
|
|
8
|
+
| Command | Effects not applied |
|
|
9
|
+
| ------------------ | ----------------------------------- |
|
|
10
|
+
| `alias`, `unalias` | Alias substitution and definitions. |
|
|
11
|
+
| `set` | Shell option changes. |
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tree-sitter-diagnostic-dash
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/konomanoasa/tree-sitter-diagnostic-dash/actions/workflows/ci.yaml)
|
|
4
|
+
[](https://crates.io/crates/konomanoasa-tree-sitter-diagnostic-dash)
|
|
5
|
+
[](https://www.npmjs.com/package/@konomanoasa/tree-sitter-diagnostic-dash)
|
|
6
|
+
[](https://pypi.org/project/konomanoasa-tree-sitter-diagnostic-dash/)
|
|
7
|
+
|
|
8
|
+
[Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for
|
|
9
|
+
diagnostics of the Debian Almquist Shell 0.5.13.5.
|
|
10
|
+
|
|
11
|
+
Guarantees cover fresh parsing only.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @konomanoasa/tree-sitter-diagnostic-dash
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Parsing Policy
|
|
20
|
+
|
|
21
|
+
[Parsing Policy](https://github.com/konomanoasa/tree-sitter-diagnostic-dash/blob/main/PARSING_POLICY.md)
|
|
22
|
+
|
|
23
|
+
## Development
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm ci
|
|
27
|
+
npm test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Specification
|
|
31
|
+
|
|
32
|
+
[dash(1) Manual, Version 0.5.13.5](https://manpages.debian.org/experimental/dash/dash.1.en.html)
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
[MIT](LICENSE)
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "tree_sitter_diagnostic_dash_binding",
|
|
5
|
+
"sources": [
|
|
6
|
+
"bindings/node/binding.cc",
|
|
7
|
+
"src/parser.c",
|
|
8
|
+
"src/scanner.c"
|
|
9
|
+
],
|
|
10
|
+
"include_dirs": ["src"],
|
|
11
|
+
"dependencies": [
|
|
12
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except"
|
|
13
|
+
],
|
|
14
|
+
"cflags_c": ["-std=c17"],
|
|
15
|
+
"cflags_cc": ["-std=c++17"],
|
|
16
|
+
"msvs_settings": {
|
|
17
|
+
"VCCLCompilerTool": {
|
|
18
|
+
"AdditionalOptions": ["/utf-8"],
|
|
19
|
+
"AdditionalOptions!": ["-std:c++20"],
|
|
20
|
+
"LanguageStandard": "stdcpp17",
|
|
21
|
+
"LanguageStandard_C": "stdc17"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"target_conditions": [
|
|
25
|
+
[
|
|
26
|
+
"OS==\"mac\"",
|
|
27
|
+
{
|
|
28
|
+
"xcode_settings": {
|
|
29
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
30
|
+
"GCC_C_LANGUAGE_STANDARD": "c17",
|
|
31
|
+
"MACOSX_DEPLOYMENT_TARGET": "14.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
|
|
3
|
+
struct TSLanguage;
|
|
4
|
+
extern "C" const TSLanguage *tree_sitter_diagnostic_dash();
|
|
5
|
+
|
|
6
|
+
namespace {
|
|
7
|
+
|
|
8
|
+
constexpr napi_type_tag language_type_tag = {
|
|
9
|
+
0x8AF2E5212AD58ABF,
|
|
10
|
+
0xD5006CAD83ABBA16
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
14
|
+
auto language = Napi::External<TSLanguage>::New(
|
|
15
|
+
env,
|
|
16
|
+
const_cast<TSLanguage *>(tree_sitter_diagnostic_dash())
|
|
17
|
+
);
|
|
18
|
+
language.TypeTag(&language_type_tag);
|
|
19
|
+
exports["language"] = language;
|
|
20
|
+
return exports;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
NODE_API_MODULE(tree_sitter_diagnostic_dash_binding, Init)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import load from "node-gyp-build";
|
|
4
|
+
|
|
5
|
+
const binding = load(fileURLToPath(new URL("../..", import.meta.url)));
|
|
6
|
+
binding.nodeTypeInfo = JSON.parse(
|
|
7
|
+
readFileSync(new URL("../../src/node-types.json", import.meta.url), "utf8"),
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export default binding;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#include <Python.h>
|
|
2
|
+
|
|
3
|
+
#include "../../src/tree_sitter/parser.h"
|
|
4
|
+
|
|
5
|
+
const TSLanguage *tree_sitter_diagnostic_dash(void);
|
|
6
|
+
|
|
7
|
+
static PyObject *language(PyObject *self, PyObject *args) {
|
|
8
|
+
(void)self;
|
|
9
|
+
(void)args;
|
|
10
|
+
return PyCapsule_New(
|
|
11
|
+
(void *)tree_sitter_diagnostic_dash(),
|
|
12
|
+
"tree_sitter.Language",
|
|
13
|
+
NULL
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static PyMethodDef methods[] = {
|
|
18
|
+
{"language",
|
|
19
|
+
language,
|
|
20
|
+
METH_NOARGS,
|
|
21
|
+
"Return the diagnostic_dash language capsule."},
|
|
22
|
+
{NULL, NULL, 0, NULL},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static struct PyModuleDef module = {
|
|
26
|
+
PyModuleDef_HEAD_INIT,
|
|
27
|
+
.m_name = "binding",
|
|
28
|
+
.m_size = -1,
|
|
29
|
+
.m_methods = methods,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
PyMODINIT_FUNC PyInit_binding(void) {
|
|
33
|
+
return PyModule_Create(&module);
|
|
34
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
fn main() {
|
|
2
|
+
let mut build = cc::Build::new();
|
|
3
|
+
build.std("c17");
|
|
4
|
+
if build.get_compiler().is_like_msvc() {
|
|
5
|
+
build.flag("-utf-8");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
println!("cargo::rerun-if-changed=src");
|
|
9
|
+
build
|
|
10
|
+
.include("src")
|
|
11
|
+
.files(["src/parser.c", "src/scanner.c"])
|
|
12
|
+
.compile("tree-sitter-diagnostic-dash");
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
use tree_sitter_language::LanguageFn;
|
|
2
|
+
|
|
3
|
+
unsafe extern "C" {
|
|
4
|
+
fn tree_sitter_diagnostic_dash() -> *const ();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
pub const LANGUAGE: LanguageFn =
|
|
8
|
+
unsafe { LanguageFn::from_raw(tree_sitter_diagnostic_dash) };
|
|
9
|
+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
package/grammar.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import tokens from "./src/tokens.json" with { type: "json" };
|
|
2
|
+
|
|
3
|
+
const tokenNames = new Set();
|
|
4
|
+
const scannerSymbols = new Set();
|
|
5
|
+
for (const { name, scanner, kind } of tokens) {
|
|
6
|
+
if (
|
|
7
|
+
typeof name !== "string" ||
|
|
8
|
+
!/^_?[a-z][a-z0-9_]*$/.test(name) ||
|
|
9
|
+
typeof scanner !== "string" ||
|
|
10
|
+
!/^[A-Z][A-Z0-9_]*$/.test(scanner) ||
|
|
11
|
+
scanner === "TOKEN_TYPE_COUNT" ||
|
|
12
|
+
tokenNames.has(name) ||
|
|
13
|
+
scannerSymbols.has(scanner) ||
|
|
14
|
+
(kind !== undefined && !["owner", "fault"].includes(kind)) ||
|
|
15
|
+
(kind === "owner" && !/^_begin_[a-z][a-z0-9_]*$/.test(name)) ||
|
|
16
|
+
(kind === "fault" && name.startsWith("_"))
|
|
17
|
+
) {
|
|
18
|
+
throw new Error(`Invalid or duplicate external token ${name}`);
|
|
19
|
+
}
|
|
20
|
+
tokenNames.add(name);
|
|
21
|
+
scannerSymbols.add(scanner);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const owners = tokens
|
|
25
|
+
.filter(({ kind }) => kind === "owner")
|
|
26
|
+
.map(({ name }) => name.slice("_begin_".length));
|
|
27
|
+
const faults = tokens
|
|
28
|
+
.filter(({ kind }) => kind === "fault")
|
|
29
|
+
.map(({ name }) => name);
|
|
30
|
+
|
|
31
|
+
export default grammar({
|
|
32
|
+
name: "diagnostic_dash",
|
|
33
|
+
externals: ($) => tokens.map(({ name }) => $[name]),
|
|
34
|
+
extras: ($) => [$._unmatchable],
|
|
35
|
+
rules: {
|
|
36
|
+
program: ($) =>
|
|
37
|
+
seq(
|
|
38
|
+
$._start,
|
|
39
|
+
repeat(choice($.source, $._owner, $._unowned_issue)),
|
|
40
|
+
$._finish,
|
|
41
|
+
),
|
|
42
|
+
_unowned_issue: ($) =>
|
|
43
|
+
seq($._unowned, field("unowned_issue", $.syntax_issue)),
|
|
44
|
+
_owner: ($) => choice(...owners.map((name) => $[name])),
|
|
45
|
+
...Object.fromEntries(
|
|
46
|
+
owners.map((name) => [
|
|
47
|
+
name,
|
|
48
|
+
($) =>
|
|
49
|
+
seq(
|
|
50
|
+
$[`_begin_${name}`],
|
|
51
|
+
repeat(
|
|
52
|
+
choice(
|
|
53
|
+
$.source,
|
|
54
|
+
$._owner,
|
|
55
|
+
field("issue", $.syntax_issue),
|
|
56
|
+
$._unowned_issue,
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
$._end_owner,
|
|
60
|
+
),
|
|
61
|
+
]),
|
|
62
|
+
),
|
|
63
|
+
syntax_issue: ($) =>
|
|
64
|
+
seq(
|
|
65
|
+
field("fault", choice(...faults.map((name) => $[name]))),
|
|
66
|
+
optional(field("fragment", $.recovery_fragment)),
|
|
67
|
+
field("boundary", choice($.recovery_resume, $.recovery_eof)),
|
|
68
|
+
),
|
|
69
|
+
_unmatchable: () => token(seq(/[\s\S]/, /[^\s\S]/)),
|
|
70
|
+
},
|
|
71
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konomanoasa/tree-sitter-diagnostic-dash",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Tree-sitter grammar for diagnostics of dash.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "git+https://github.com/konomanoasa/tree-sitter-diagnostic-dash.git",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./bindings/node/index.d.ts",
|
|
11
|
+
"default": "./bindings/node/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"Cargo.toml",
|
|
16
|
+
"PARSING_POLICY.md",
|
|
17
|
+
"binding.gyp",
|
|
18
|
+
"bindings/node/*.cc",
|
|
19
|
+
"bindings/node/*.js",
|
|
20
|
+
"bindings/node/*.ts",
|
|
21
|
+
"bindings/python/*.c",
|
|
22
|
+
"bindings/python/*.py",
|
|
23
|
+
"bindings/python/*.pyi",
|
|
24
|
+
"bindings/python/py.typed",
|
|
25
|
+
"bindings/rust/*.rs",
|
|
26
|
+
"grammar.js",
|
|
27
|
+
"pyproject.toml",
|
|
28
|
+
"scripts/tree-sitter.js",
|
|
29
|
+
"setup.py",
|
|
30
|
+
"src/*.c",
|
|
31
|
+
"src/*.h",
|
|
32
|
+
"src/*.json",
|
|
33
|
+
"src/tree_sitter/*.h",
|
|
34
|
+
"test/bindings.test.rs",
|
|
35
|
+
"tree-sitter.json"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node-gyp rebuild && node-gyp configure -- -f compile_commands_json",
|
|
42
|
+
"build:parser": "npm run tree-sitter -- build-all",
|
|
43
|
+
"check": "biome check . && tsc",
|
|
44
|
+
"format": "biome format --write .",
|
|
45
|
+
"generate": "npm run tree-sitter -- generate-all",
|
|
46
|
+
"install": "node-gyp-build",
|
|
47
|
+
"test": "node --test --test-concurrency=1 test/bindings.test.js test/build.test.js test/cst.test.js test/incremental.test.js test/parser.test.js && node scripts/check-c.js --test",
|
|
48
|
+
"test:performance": "node --test test/performance.test.js",
|
|
49
|
+
"test:sanitize": "node scripts/check-c.js --sanitize",
|
|
50
|
+
"tree-sitter": "node scripts/tree-sitter.js"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"node-addon-api": "8.9.2",
|
|
54
|
+
"node-gyp-build": "4.8.4"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"tree-sitter": "0.25.1"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@biomejs/biome": "2.6.9",
|
|
61
|
+
"@types/node": "26.6.11",
|
|
62
|
+
"node-gyp": "13.1.0",
|
|
63
|
+
"tree-sitter-cli": "0.27.2",
|
|
64
|
+
"typescript": "7.0.2"
|
|
65
|
+
},
|
|
66
|
+
"allowScripts": {
|
|
67
|
+
"tree-sitter": true,
|
|
68
|
+
"tree-sitter-cli": true
|
|
69
|
+
}
|
|
70
|
+
}
|
package/pyproject.toml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "konomanoasa-tree-sitter-diagnostic-dash"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Tree-sitter grammar for diagnostics of dash."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
|
|
9
|
+
[project.urls]
|
|
10
|
+
Repository = "https://github.com/konomanoasa/tree-sitter-diagnostic-dash"
|
|
11
|
+
|
|
12
|
+
[dependency-groups]
|
|
13
|
+
dev = [
|
|
14
|
+
"poethepoet==0.49.0",
|
|
15
|
+
"ruff==0.17.6",
|
|
16
|
+
"setuptools==84.2.1",
|
|
17
|
+
"tree-sitter==0.27.0",
|
|
18
|
+
"twine==7.0.0",
|
|
19
|
+
"ty==0.0.112",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["setuptools==84.2.1"]
|
|
24
|
+
build-backend = "setuptools.build_meta"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
include-package-data = false
|
|
28
|
+
packages = ["tree_sitter_diagnostic_dash"]
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.package-dir]
|
|
31
|
+
tree_sitter_diagnostic_dash = "bindings/python"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.package-data]
|
|
34
|
+
tree_sitter_diagnostic_dash = ["*.pyi", "py.typed"]
|
|
35
|
+
|
|
36
|
+
[tool.poe]
|
|
37
|
+
executor.type = "simple"
|
|
38
|
+
|
|
39
|
+
[tool.poe.tasks]
|
|
40
|
+
build = "uv build --no-sources"
|
|
41
|
+
check = [
|
|
42
|
+
{ cmd = "ruff check setup.py bindings/python test/bindings.test.py" },
|
|
43
|
+
{ cmd = "ty check setup.py bindings/python test/bindings.test.py" },
|
|
44
|
+
{ cmd = "ruff format --check setup.py bindings/python test/bindings.test.py" },
|
|
45
|
+
]
|
|
46
|
+
format = "ruff format setup.py bindings/python test/bindings.test.py"
|
|
47
|
+
test = "python test/bindings.test.py"
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
indent-width = 4
|
|
51
|
+
line-length = 80
|
|
52
|
+
|
|
53
|
+
[tool.ruff.format]
|
|
54
|
+
indent-style = "space"
|
|
55
|
+
skip-magic-trailing-comma = true
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint.isort]
|
|
58
|
+
split-on-trailing-comma = false
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
import tokens from "../src/tokens.json" with { type: "json" };
|
|
7
|
+
|
|
8
|
+
export const root = resolve(import.meta.dirname, "..");
|
|
9
|
+
export const cli = fileURLToPath(
|
|
10
|
+
new URL(
|
|
11
|
+
process.platform === "win32" ? "tree-sitter.exe" : "tree-sitter",
|
|
12
|
+
import.meta.resolve("tree-sitter-cli/package.json"),
|
|
13
|
+
),
|
|
14
|
+
);
|
|
15
|
+
export const libraryName =
|
|
16
|
+
process.platform === "win32" ? "diagnostic_dash.dll" : "diagnostic_dash.so";
|
|
17
|
+
|
|
18
|
+
export function runTreeSitter(args, options = {}) {
|
|
19
|
+
return spawnSync(cli, args, {
|
|
20
|
+
cwd: root,
|
|
21
|
+
encoding: "utf8",
|
|
22
|
+
env: {
|
|
23
|
+
...process.env,
|
|
24
|
+
...(process.platform === "darwin"
|
|
25
|
+
? { CC: process.env.CC ?? "/opt/homebrew/opt/llvm/bin/clang" }
|
|
26
|
+
: {}),
|
|
27
|
+
NO_COLOR: "1",
|
|
28
|
+
},
|
|
29
|
+
...options,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function buildParser(output) {
|
|
34
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
35
|
+
const result = runTreeSitter(["build", "--output", output, root]);
|
|
36
|
+
if (result.error) throw result.error;
|
|
37
|
+
if (result.status !== 0)
|
|
38
|
+
throw new Error(result.stderr || result.stdout || "Parser build failed.");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const tokenHeader = `/* Generated from tokens.json by npm run generate. */
|
|
42
|
+
|
|
43
|
+
#ifndef TREE_SITTER_DIAGNOSTIC_DASH_TOKENS_H_
|
|
44
|
+
#define TREE_SITTER_DIAGNOSTIC_DASH_TOKENS_H_
|
|
45
|
+
|
|
46
|
+
enum TokenType {
|
|
47
|
+
${tokens.map(({ scanner }) => ` ${scanner},`).join("\n")}
|
|
48
|
+
TOKEN_TYPE_COUNT,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
#endif
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
export function generateParsers(outputRoot = root) {
|
|
55
|
+
const src = join(outputRoot, "src");
|
|
56
|
+
mkdirSync(src, { recursive: true });
|
|
57
|
+
const result = runTreeSitter(
|
|
58
|
+
["generate", join(root, "grammar.js"), "--abi", "latest", "--output", src],
|
|
59
|
+
{
|
|
60
|
+
stdio: "inherit",
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
if (result.error) throw result.error;
|
|
64
|
+
if (result.status !== 0) throw new Error("Parser generation failed.");
|
|
65
|
+
|
|
66
|
+
writeFileSync(join(src, "tokens.h"), tokenHeader);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (import.meta.main) {
|
|
70
|
+
const args = process.argv.slice(2);
|
|
71
|
+
if (["generate-all", "build-all"].includes(args[0]) && args.length !== 1)
|
|
72
|
+
throw new Error(`Usage: node scripts/tree-sitter.js ${args[0]}`);
|
|
73
|
+
if (args[0] === "build-all") buildParser(join(root, "parsers", libraryName));
|
|
74
|
+
else if (args[0] === "generate-all") generateParsers();
|
|
75
|
+
else {
|
|
76
|
+
const result = runTreeSitter(args, {
|
|
77
|
+
stdio: "inherit",
|
|
78
|
+
cwd: process.cwd(),
|
|
79
|
+
});
|
|
80
|
+
if (result.error) throw result.error;
|
|
81
|
+
process.exitCode = result.status ?? 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
package/setup.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from setuptools import Extension, setup
|
|
5
|
+
|
|
6
|
+
Path("dist/metadata").mkdir(parents=True, exist_ok=True)
|
|
7
|
+
|
|
8
|
+
setup(
|
|
9
|
+
options={
|
|
10
|
+
"build": {"build_base": "dist/build"},
|
|
11
|
+
"egg_info": {"egg_base": "dist/metadata"},
|
|
12
|
+
},
|
|
13
|
+
ext_modules=[
|
|
14
|
+
Extension(
|
|
15
|
+
"tree_sitter_diagnostic_dash.binding",
|
|
16
|
+
sources=[
|
|
17
|
+
"bindings/python/binding.c",
|
|
18
|
+
"src/parser.c",
|
|
19
|
+
"src/scanner.c",
|
|
20
|
+
],
|
|
21
|
+
include_dirs=["src"],
|
|
22
|
+
depends=[
|
|
23
|
+
"src/tokens.h",
|
|
24
|
+
"src/tree_sitter/alloc.h",
|
|
25
|
+
"src/tree_sitter/parser.h",
|
|
26
|
+
],
|
|
27
|
+
extra_compile_args=["/std:c17", "/utf-8"]
|
|
28
|
+
if sys.platform == "win32"
|
|
29
|
+
else ["-std=c17"],
|
|
30
|
+
)
|
|
31
|
+
],
|
|
32
|
+
)
|