@konomanoasa/tree-sitter-diagnostic-sh 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 ADDED
@@ -0,0 +1,37 @@
1
+ [package]
2
+ name = "konomanoasa-tree-sitter-diagnostic-sh"
3
+ version = "0.2.0"
4
+ edition = "2024"
5
+ description = "Tree-sitter grammar for diagnostics of POSIX sh."
6
+ readme = "README.md"
7
+ repository = "https://github.com/konomanoasa/tree-sitter-diagnostic-sh"
8
+ license = "MIT"
9
+ build = "bindings/rust/build.rs"
10
+ links = "tree-sitter-diagnostic-sh"
11
+ include = [
12
+ "/LICENSE",
13
+ "/README.md",
14
+ "/bindings/rust/*.rs",
15
+ "/src/*.c",
16
+ "/src/node-types.json",
17
+ "/src/tree_sitter/*.h",
18
+ "/test/bindings.test.rs",
19
+ "/test/support/parser-cases.json",
20
+ ]
21
+
22
+ [lib]
23
+ path = "bindings/rust/lib.rs"
24
+
25
+ [[test]]
26
+ name = "bindings"
27
+ path = "test/bindings.test.rs"
28
+
29
+ [dependencies]
30
+ tree-sitter-language = "0.1.8"
31
+
32
+ [dev-dependencies]
33
+ serde_json = "1"
34
+ tree-sitter = "0.27.1"
35
+
36
+ [build-dependencies]
37
+ cc = "1.4"
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.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # tree-sitter-diagnostic-sh
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/konomanoasa/tree-sitter-diagnostic-sh/actions/workflows/ci.yaml/badge.svg)](https://github.com/konomanoasa/tree-sitter-diagnostic-sh/actions/workflows/ci.yaml)
4
+ [![crates.io](https://img.shields.io/crates/v/konomanoasa-tree-sitter-diagnostic-sh)](https://crates.io/crates/konomanoasa-tree-sitter-diagnostic-sh)
5
+ [![npm](https://img.shields.io/npm/v/@konomanoasa/tree-sitter-diagnostic-sh)](https://www.npmjs.com/package/@konomanoasa/tree-sitter-diagnostic-sh)
6
+
7
+ [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for
8
+ diagnostics of the POSIX.1-2024 Shell Command Language.
9
+
10
+ Guarantees cover fresh parsing only.
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ npm install @konomanoasa/tree-sitter-diagnostic-sh
16
+ ```
17
+
18
+ ## Development
19
+
20
+ Development uses Node.js 24.21.0 or later.
21
+
22
+ ```sh
23
+ npm install
24
+ npm run build
25
+ npm test
26
+ ```
27
+
28
+ ## Specification
29
+
30
+ [POSIX.1-2024 Shell Command Language](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html)
31
+
32
+ ## License
33
+
34
+ [MIT](LICENSE)
@@ -0,0 +1,12 @@
1
+ fn main() {
2
+ println!("cargo::rerun-if-changed=src");
3
+ let mut build = cc::Build::new();
4
+ build.std("c17");
5
+ if build.get_compiler().is_like_msvc() {
6
+ build.flag("-utf-8");
7
+ }
8
+ build
9
+ .include("src")
10
+ .files(["src/parser.c", "src/scanner.c"])
11
+ .compile("tree-sitter-diagnostic-sh");
12
+ }
@@ -0,0 +1,10 @@
1
+ use tree_sitter_language::LanguageFn;
2
+
3
+ unsafe extern "C" {
4
+ fn tree_sitter_diagnostic_sh() -> *const ();
5
+ }
6
+
7
+ pub const LANGUAGE: LanguageFn =
8
+ unsafe { LanguageFn::from_raw(tree_sitter_diagnostic_sh) };
9
+
10
+ pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
package/grammar.js ADDED
@@ -0,0 +1,174 @@
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
+ ];
31
+
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
+ "unspecified_negation_spacing",
56
+ "reserved_colon_word",
57
+ "redirection_target_gap",
58
+ "invalid_redirection_target",
59
+ "here_document_delimiter_gap",
60
+ "invalid_here_document_delimiter",
61
+ "here_document_ending_gap",
62
+ "unspecified_here_document_start",
63
+ "unspecified_here_document_newline",
64
+ "for_name_gap",
65
+ "invalid_for_name",
66
+ "for_separator_gap",
67
+ "invalid_for_header",
68
+ "invalid_for_separator",
69
+ "then_gap",
70
+ "fi_gap",
71
+ "do_gap",
72
+ "invalid_do",
73
+ "done_gap",
74
+ "in_gap",
75
+ "esac_gap",
76
+ "case_word_gap",
77
+ "invalid_case_word",
78
+ "invalid_in",
79
+ "case_pattern_gap",
80
+ "invalid_case_pattern",
81
+ "case_pattern_separator_error",
82
+ "parenthesis_gap",
83
+ "brace_gap",
84
+ "function_body_gap",
85
+ "invalid_function_body",
86
+ "function_parameter_error",
87
+ "single_quote_gap",
88
+ "double_quote_gap",
89
+ "dollar_quote_gap",
90
+ "incomplete_escape",
91
+ "unspecified_dollar_quote_escape",
92
+ "unspecified_empty_hex_escape",
93
+ "unspecified_control_escape",
94
+ "unspecified_hex_escape",
95
+ "unspecified_octal_escape",
96
+ "parameter_name_gap",
97
+ "invalid_parameter_name",
98
+ "parameter_operator_gap",
99
+ "parameter_operator_error",
100
+ "parameter_length_suffix_error",
101
+ "parameter_word_gap",
102
+ "parameter_ending_gap",
103
+ "unspecified_parameter_quote",
104
+ "unspecified_expansion_start",
105
+ "arithmetic_ending_gap",
106
+ "substitution_ending_gap",
107
+ "backquote_gap",
108
+ "undefined_backquote_quote",
109
+ "undefined_backquote_comment",
110
+ "undefined_backquote_here_document",
111
+ "undefined_backquote_substitution",
112
+ ];
113
+
114
+ function contents($) {
115
+ return repeat(
116
+ choice(
117
+ $.source,
118
+ field("issue", $.syntax_issue),
119
+ field("unowned_issue", alias($._unowned_issue, $.syntax_issue)),
120
+ $._owner,
121
+ ),
122
+ );
123
+ }
124
+
125
+ function issue($) {
126
+ return seq(
127
+ field("fault", choice(...faults.map((kind) => $[kind]))),
128
+ optional(field("fragment", $.recovery_fragment)),
129
+ field("boundary", choice($.recovery_resume, $.recovery_eof)),
130
+ );
131
+ }
132
+
133
+ export default grammar({
134
+ name: "diagnostic_sh",
135
+ externals: ($) => [
136
+ $._start,
137
+ $._finish,
138
+ ...owners.map((kind) => $[`_begin_${kind}`]),
139
+ $._end_owner,
140
+ $._begin_issue,
141
+ $._begin_unowned_issue,
142
+ $.source,
143
+ ...faults.map((kind) => $[kind]),
144
+ $.recovery_fragment,
145
+ $.recovery_resume,
146
+ $.recovery_eof,
147
+ ],
148
+ // Prevents lexer fallback from accepting EOF mid-input.
149
+ extras: ($) => [$._unmatchable],
150
+ rules: {
151
+ program: ($) =>
152
+ seq(
153
+ $._start,
154
+ repeat(
155
+ choice(
156
+ $.source,
157
+ field("unowned_issue", alias($._unowned_issue, $.syntax_issue)),
158
+ $._owner,
159
+ ),
160
+ ),
161
+ $._finish,
162
+ ),
163
+ _owner: ($) => choice(...owners.map((kind) => $[kind])),
164
+ ...Object.fromEntries(
165
+ owners.map((kind) => [
166
+ kind,
167
+ ($) => seq($[`_begin_${kind}`], contents($), $._end_owner),
168
+ ]),
169
+ ),
170
+ syntax_issue: ($) => seq($._begin_issue, issue($)),
171
+ _unowned_issue: ($) => seq($._begin_unowned_issue, issue($)),
172
+ _unmatchable: () => token(seq(/[\s\S]/, /[^\s\S]/)),
173
+ },
174
+ });
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@konomanoasa/tree-sitter-diagnostic-sh",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Tree-sitter grammar for diagnostics of POSIX sh.",
6
+ "license": "MIT",
7
+ "repository": "git+https://github.com/konomanoasa/tree-sitter-diagnostic-sh.git",
8
+ "files": [
9
+ "Cargo.toml",
10
+ "bindings/rust/*.rs",
11
+ "grammar.js",
12
+ "src/*.c",
13
+ "src/*.json",
14
+ "src/tree_sitter/*.h",
15
+ "test/bindings.test.rs",
16
+ "test/support/parser-cases.json",
17
+ "tree-sitter.json"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "npm run tree-sitter -- build-all",
24
+ "check": "biome check . && tsc --noEmit",
25
+ "format": "biome format --write .",
26
+ "generate": "npm run tree-sitter -- generate-all",
27
+ "test": "node --test --test-concurrency=1 \"test/*.test.js\"",
28
+ "test:sanitize": "node scripts/check-c.js --sanitize",
29
+ "test:scanner": "node scripts/check-c.js",
30
+ "tree-sitter": "node scripts/tree-sitter.js"
31
+ },
32
+ "devDependencies": {
33
+ "@biomejs/biome": "2.5.15",
34
+ "@types/node": "26.6.5",
35
+ "tree-sitter-cli": "0.27.1",
36
+ "typescript": "7.0.2"
37
+ },
38
+ "allowScripts": {
39
+ "tree-sitter-cli": true
40
+ }
41
+ }