@konomanoasa/tree-sitter-diagnostic-sh 0.7.0 → 0.8.1

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 CHANGED
@@ -1,11 +1,11 @@
1
1
  [package]
2
2
  name = "konomanoasa-tree-sitter-diagnostic-sh"
3
- version = "0.7.0"
4
- edition = "2024"
3
+ version = "0.8.1"
5
4
  description = "Tree-sitter grammar for diagnostics of POSIX sh."
6
5
  readme = "README.md"
7
- repository = "https://github.com/konomanoasa/tree-sitter-diagnostic-sh"
8
6
  license = "MIT"
7
+ repository = "https://github.com/konomanoasa/tree-sitter-diagnostic-sh"
8
+ edition = "2024"
9
9
  build = "bindings/rust/build.rs"
10
10
  links = "tree-sitter-diagnostic-sh"
11
11
  include = [
@@ -14,10 +14,10 @@ include = [
14
14
  "/README.md",
15
15
  "/bindings/rust/*.rs",
16
16
  "/src/*.c",
17
+ "/src/*.h",
17
18
  "/src/node-types.json",
18
19
  "/src/tree_sitter/*.h",
19
20
  "/test/bindings.test.rs",
20
- "/test/support/parser-cases.json",
21
21
  ]
22
22
 
23
23
  [lib]
@@ -31,7 +31,6 @@ path = "test/bindings.test.rs"
31
31
  tree-sitter-language = "=0.1.9"
32
32
 
33
33
  [dev-dependencies]
34
- serde_json = "=1.0.154"
35
34
  tree-sitter = "=0.27.1"
36
35
 
37
36
  [build-dependencies]
package/PARSING_POLICY.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # Parsing Policy
2
2
 
3
- The parser supports the mandatory syntax of [POSIX.1-2024](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html). Optional syntax,
4
- optional features, and implementation-specific extensions are not supported.
5
- Where POSIX does not uniquely determine the syntax interpretation, the parser
6
- follows [dash 0.5.13.5](https://manpages.debian.org/experimental/dash/dash.1.en.html). Explicit POSIX requirements take precedence.
3
+ The parser follows [POSIX.1-2024](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html)
4
+ mandatory syntax, excluding optional features and extensions. Syntax not
5
+ determined by POSIX follows [dash 0.5.13.5](https://manpages.debian.org/experimental/dash/dash.1.en.html).
7
6
 
8
- The following commands can affect how subsequent source is parsed. The parser
9
- recognizes these commands but does not apply their effects.
7
+ These commands are parsed without changing how subsequent source is parsed.
10
8
 
11
- | Command | Effects not applied |
12
- | ------------------ | --------------------------------------------------- |
13
- | `alias`, `unalias` | Alias substitution or changes to alias definitions. |
9
+ | Command | Effects not applied |
10
+ | ------------------ | ----------------------------------- |
11
+ | `alias`, `unalias` | Alias substitution and definitions. |
@@ -0,0 +1,3 @@
1
+ from .binding import language
2
+
3
+ __all__ = ["language"]
@@ -0,0 +1,34 @@
1
+ #include <Python.h>
2
+
3
+ #include "tree_sitter/parser.h"
4
+
5
+ const TSLanguage *tree_sitter_diagnostic_sh(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_sh(),
12
+ "tree_sitter.Language",
13
+ NULL
14
+ );
15
+ }
16
+
17
+ static PyMethodDef methods[] = {
18
+ {"language",
19
+ language,
20
+ METH_NOARGS,
21
+ "Return the diagnostic_sh 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
+ }
@@ -0,0 +1,3 @@
1
+ from types import CapsuleType
2
+
3
+ def language() -> CapsuleType: ...
File without changes
package/grammar.js CHANGED
@@ -1,104 +1,32 @@
1
- const owners = [
2
- "list",
3
- "compound_list",
4
- "and_or",
5
- "pipeline",
6
- "simple_command",
7
- "word",
8
- "subshell",
9
- "brace_group",
10
- "if_clause",
11
- "else_part",
12
- "for_clause",
13
- "while_clause",
14
- "until_clause",
15
- "do_group",
16
- "case_clause",
17
- "case_item",
18
- "function_definition",
19
- "io_redirect",
20
- "here_document_body",
21
- "single_quoted",
22
- "double_quoted",
23
- "dollar_single_quoted",
24
- "escaped_character",
25
- "dollar_single_quote_escape",
26
- "parameter_expansion",
27
- "arithmetic_expansion",
28
- "command_substitution",
29
- "backquote_substitution",
30
- ];
1
+ import tokens from "./src/tokens.json" with { type: "json" };
31
2
 
32
- const faults = [
33
- "invalid_encoding",
34
- "nul_character",
35
- "unmatched_parenthesis",
36
- "unmatched_brace",
37
- "unexpected_then",
38
- "unexpected_elif",
39
- "unexpected_else",
40
- "unmatched_fi",
41
- "unexpected_do",
42
- "unmatched_done",
43
- "unmatched_esac",
44
- "unexpected_in",
45
- "unexpected_semicolon",
46
- "unexpected_ampersand",
47
- "unexpected_pipe",
48
- "unexpected_and_if",
49
- "unexpected_or_if",
50
- "unexpected_case_separator",
51
- "unexpected_case_fallthrough",
52
- "unexpected_negation",
53
- "command_gap",
54
- "separator_gap",
55
- "redirection_target_gap",
56
- "invalid_redirection_target",
57
- "here_document_delimiter_gap",
58
- "invalid_here_document_delimiter",
59
- "here_document_ending_gap",
60
- "for_name_gap",
61
- "invalid_for_name",
62
- "for_separator_gap",
63
- "invalid_for_header",
64
- "invalid_for_separator",
65
- "then_gap",
66
- "fi_gap",
67
- "do_gap",
68
- "invalid_do",
69
- "done_gap",
70
- "in_gap",
71
- "esac_gap",
72
- "case_word_gap",
73
- "invalid_case_word",
74
- "invalid_in",
75
- "case_pattern_gap",
76
- "invalid_case_pattern",
77
- "case_pattern_separator_error",
78
- "parenthesis_gap",
79
- "brace_gap",
80
- "special_builtin_function_name",
81
- "function_body_gap",
82
- "invalid_function_body",
83
- "function_parameter_error",
84
- "single_quote_gap",
85
- "double_quote_gap",
86
- "dollar_quote_gap",
87
- "incomplete_escape",
88
- "invalid_control_escape",
89
- "parameter_name_gap",
90
- "invalid_parameter_name",
91
- "parameter_operator_gap",
92
- "parameter_operator_error",
93
- "parameter_length_suffix_error",
94
- "parameter_word_gap",
95
- "parameter_ending_gap",
96
- "arithmetic_ending_gap",
97
- "substitution_ending_gap",
98
- "backquote_gap",
99
- "undefined_backquote_quote",
100
- "undefined_backquote_substitution",
101
- ];
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);
102
30
 
103
31
  function contents($) {
104
32
  return repeat(
@@ -121,19 +49,7 @@ function issue($) {
121
49
 
122
50
  export default grammar({
123
51
  name: "diagnostic_sh",
124
- externals: ($) => [
125
- $._start,
126
- $._finish,
127
- ...owners.map((kind) => $[`_begin_${kind}`]),
128
- $._end_owner,
129
- $._begin_issue,
130
- $._begin_unowned_issue,
131
- $.source,
132
- ...faults.map((kind) => $[kind]),
133
- $.recovery_fragment,
134
- $.recovery_resume,
135
- $.recovery_eof,
136
- ],
52
+ externals: ($) => tokens.map(({ name }) => $[name]),
137
53
  // Prevents lexer fallback from accepting EOF mid-input.
138
54
  extras: ($) => [$._unmatchable],
139
55
  rules: {
package/package.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "name": "@konomanoasa/tree-sitter-diagnostic-sh",
3
- "version": "0.7.0",
4
- "type": "module",
3
+ "version": "0.8.1",
5
4
  "description": "Tree-sitter grammar for diagnostics of POSIX sh.",
6
5
  "license": "MIT",
7
6
  "repository": "git+https://github.com/konomanoasa/tree-sitter-diagnostic-sh.git",
7
+ "type": "module",
8
8
  "files": [
9
9
  "Cargo.toml",
10
10
  "PARSING_POLICY.md",
11
+ "bindings/python/*.c",
12
+ "bindings/python/*.py",
13
+ "bindings/python/*.pyi",
14
+ "bindings/python/py.typed",
11
15
  "bindings/rust/*.rs",
12
16
  "grammar.js",
17
+ "pyproject.toml",
18
+ "setup.py",
13
19
  "src/*.c",
20
+ "src/*.h",
14
21
  "src/*.json",
15
22
  "src/tree_sitter/*.h",
16
23
  "test/bindings.test.rs",
17
- "test/support/parser-cases.json",
18
24
  "tree-sitter.json"
19
25
  ],
20
26
  "publishConfig": {
@@ -25,10 +31,9 @@
25
31
  "check": "biome check . && tsc",
26
32
  "format": "biome format --write .",
27
33
  "generate": "npm run tree-sitter -- generate-all",
28
- "test": "node --test --test-concurrency=1 test/cst.test.js test/parser.test.js",
34
+ "test": "node --test --test-concurrency=1 test/build.test.js test/cst.test.js test/incremental.test.js test/parser.test.js && node scripts/check-c.js --test",
29
35
  "test:performance": "node --test test/performance.test.js",
30
36
  "test:sanitize": "node scripts/check-c.js --sanitize",
31
- "test:scanner": "node scripts/check-c.js",
32
37
  "tree-sitter": "node scripts/tree-sitter.js"
33
38
  },
34
39
  "devDependencies": {
package/pyproject.toml ADDED
@@ -0,0 +1,58 @@
1
+ [project]
2
+ name = "konomanoasa-tree-sitter-diagnostic-sh"
3
+ version = "0.8.1"
4
+ description = "Tree-sitter grammar for diagnostics of POSIX sh."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+
9
+ [project.urls]
10
+ Repository = "https://github.com/konomanoasa/tree-sitter-diagnostic-sh"
11
+
12
+ [dependency-groups]
13
+ dev = [
14
+ "poethepoet==0.49.0",
15
+ "ruff==0.17.3",
16
+ "setuptools==84.2.1",
17
+ "tree-sitter==0.26.0",
18
+ "twine==7.0.0",
19
+ "ty==0.0.95",
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_sh"]
29
+
30
+ [tool.setuptools.package-dir]
31
+ tree_sitter_diagnostic_sh = "bindings/python"
32
+
33
+ [tool.setuptools.package-data]
34
+ tree_sitter_diagnostic_sh = ["*.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
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_sh.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
+ )
package/src/grammar.json CHANGED
@@ -1681,6 +1681,10 @@
1681
1681
  "type": "SYMBOL",
1682
1682
  "name": "invalid_here_document_delimiter"
1683
1683
  },
1684
+ {
1685
+ "type": "SYMBOL",
1686
+ "name": "here_document_delimiter_ending_gap"
1687
+ },
1684
1688
  {
1685
1689
  "type": "SYMBOL",
1686
1690
  "name": "here_document_ending_gap"
@@ -2009,6 +2013,10 @@
2009
2013
  "type": "SYMBOL",
2010
2014
  "name": "invalid_here_document_delimiter"
2011
2015
  },
2016
+ {
2017
+ "type": "SYMBOL",
2018
+ "name": "here_document_delimiter_ending_gap"
2019
+ },
2012
2020
  {
2013
2021
  "type": "SYMBOL",
2014
2022
  "name": "here_document_ending_gap"
@@ -2483,6 +2491,10 @@
2483
2491
  "type": "SYMBOL",
2484
2492
  "name": "invalid_here_document_delimiter"
2485
2493
  },
2494
+ {
2495
+ "type": "SYMBOL",
2496
+ "name": "here_document_delimiter_ending_gap"
2497
+ },
2486
2498
  {
2487
2499
  "type": "SYMBOL",
2488
2500
  "name": "here_document_ending_gap"
@@ -3928,6 +3928,10 @@
3928
3928
  "type": "function_parameter_error",
3929
3929
  "named": true
3930
3930
  },
3931
+ {
3932
+ "type": "here_document_delimiter_ending_gap",
3933
+ "named": true
3934
+ },
3931
3935
  {
3932
3936
  "type": "here_document_delimiter_gap",
3933
3937
  "named": true
@@ -4658,6 +4662,10 @@
4658
4662
  "type": "function_parameter_error",
4659
4663
  "named": true
4660
4664
  },
4665
+ {
4666
+ "type": "here_document_delimiter_ending_gap",
4667
+ "named": true
4668
+ },
4661
4669
  {
4662
4670
  "type": "here_document_delimiter_gap",
4663
4671
  "named": true