@willbooster/tree-sitter-bash 1.0.0 → 1.0.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/README.md +8 -9
- package/package.json +32 -35
- package/prebuilds/darwin-arm64/tree-sitter-bash.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-bash.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-bash.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-bash.node +0 -0
- package/src/parser.c +1 -1
- package/src/scanner.c +42 -17
- package/tree-sitter.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# @willbooster/tree-sitter-bash
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
|
|
4
|
+
[](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
|
|
5
|
+
[](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml)
|
|
6
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
7
|
+
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
5
8
|
|
|
6
9
|
Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), rewritten from
|
|
7
10
|
[tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash). The syntax trees differ from the
|
|
@@ -32,21 +35,17 @@ const tree = parser.parse('cat <<EOF; echo done\n$(date)\nEOF\n');
|
|
|
32
35
|
```sh
|
|
33
36
|
mise install
|
|
34
37
|
bun install --frozen-lockfile
|
|
35
|
-
bun run lint
|
|
36
|
-
bun run test
|
|
37
38
|
bun run tree-sitter generate
|
|
38
|
-
bun run
|
|
39
|
+
bun run test
|
|
39
40
|
script/parse-examples
|
|
40
41
|
```
|
|
41
42
|
|
|
42
43
|
`script/parse-examples` clones real-world scripts into `examples/`, parses them with the local
|
|
43
|
-
tree-sitter CLI, and rewrites `script/known-failures.txt`, the list of files that
|
|
44
|
+
tree-sitter CLI, and rewrites `script/known-failures.txt`, the list of files that fail to parse; its diff shows
|
|
45
|
+
regressions.
|
|
44
46
|
|
|
45
47
|
### References
|
|
46
48
|
|
|
47
49
|
- [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)
|
|
48
50
|
- [Shell command language specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
|
|
49
51
|
- [mvdan/sh - a shell parser in go](https://github.com/mvdan/sh)
|
|
50
|
-
|
|
51
|
-
[ci]: https://img.shields.io/github/actions/workflow/status/WillBooster/tree-sitter-bash/ci.yml?logo=github&label=CI
|
|
52
|
-
[npm]: https://img.shields.io/npm/v/%40willbooster%2Ftree-sitter-bash?logo=npm
|
package/package.json
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-bash",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Bash grammar for tree-sitter",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"incremental",
|
|
7
|
+
"parsing",
|
|
8
|
+
"tree-sitter",
|
|
9
|
+
"bash"
|
|
10
|
+
],
|
|
5
11
|
"repository": {
|
|
6
12
|
"type": "git",
|
|
7
13
|
"url": "git+https://github.com/WillBooster/tree-sitter-bash.git"
|
|
8
14
|
},
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public",
|
|
11
|
-
"registry": "https://registry.npmjs.org/"
|
|
12
|
-
},
|
|
13
15
|
"license": "MIT",
|
|
14
|
-
"author":
|
|
15
|
-
"name": "Max Brunsfeld",
|
|
16
|
-
"email": "maxbrunsfeld@gmail.com"
|
|
17
|
-
},
|
|
16
|
+
"author": "WillBooster Inc.",
|
|
18
17
|
"main": "bindings/node",
|
|
19
18
|
"types": "bindings/node",
|
|
20
|
-
"keywords": [
|
|
21
|
-
"incremental",
|
|
22
|
-
"parsing",
|
|
23
|
-
"tree-sitter",
|
|
24
|
-
"bash"
|
|
25
|
-
],
|
|
26
19
|
"files": [
|
|
27
20
|
"grammar.js",
|
|
28
21
|
"tree-sitter.json",
|
|
@@ -33,19 +26,37 @@
|
|
|
33
26
|
"src/**",
|
|
34
27
|
"*.wasm"
|
|
35
28
|
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build-prebuilds": "prebuildify --napi --strip --name tree-sitter-bash",
|
|
31
|
+
"build/ci": "tree-sitter generate",
|
|
32
|
+
"cleanup": "bun wb lint --fix --format",
|
|
33
|
+
"format": "bun wb lint --format",
|
|
34
|
+
"install": "node-gyp-build",
|
|
35
|
+
"lint": "bun wb lint",
|
|
36
|
+
"lint-fix": "bun wb lint --fix",
|
|
37
|
+
"prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
|
|
38
|
+
"release": "wb release",
|
|
39
|
+
"release-test": "node node_modules/semantic-release/bin/semantic-release.js --dry-run --plugins @semantic-release/commit-analyzer @semantic-release/release-notes-generator",
|
|
40
|
+
"prestart": "tree-sitter build --wasm",
|
|
41
|
+
"start": "tree-sitter playground",
|
|
42
|
+
"test": "tree-sitter test && node --test bindings/node/*_test.js",
|
|
43
|
+
"test/ci": "bun wb test-on-ci",
|
|
44
|
+
"verify": "bun wb verify",
|
|
45
|
+
"verify-full": "bun wb verify --full"
|
|
46
|
+
},
|
|
36
47
|
"dependencies": {
|
|
37
48
|
"node-addon-api": "^8.2.1",
|
|
38
49
|
"node-gyp-build": "^4.8.2"
|
|
39
50
|
},
|
|
40
51
|
"devDependencies": {
|
|
41
52
|
"@semantic-release/exec": "7.1.0",
|
|
42
|
-
"@willbooster/wb": "22.7.
|
|
53
|
+
"@willbooster/wb": "22.7.1",
|
|
43
54
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
44
|
-
"
|
|
45
|
-
"eslint-config-treesitter": "^1.0.2",
|
|
55
|
+
"lefthook": "2.1.14",
|
|
46
56
|
"node-gyp": "13.0.2",
|
|
47
57
|
"prebuildify": "^6.0.1",
|
|
48
58
|
"semantic-release": "25.0.5",
|
|
59
|
+
"sort-package-json": "4.0.0",
|
|
49
60
|
"tree-sitter": "^0.25.0",
|
|
50
61
|
"tree-sitter-cli": "^0.27.0"
|
|
51
62
|
},
|
|
@@ -57,22 +68,8 @@
|
|
|
57
68
|
"optional": true
|
|
58
69
|
}
|
|
59
70
|
},
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
"trustedDependencies": [
|
|
64
|
-
"tree-sitter",
|
|
65
|
-
"tree-sitter-cli"
|
|
66
|
-
],
|
|
67
|
-
"scripts": {
|
|
68
|
-
"install": "node-gyp-build",
|
|
69
|
-
"lint": "eslint grammar.js",
|
|
70
|
-
"prestart": "tree-sitter build --wasm",
|
|
71
|
-
"release": "wb release",
|
|
72
|
-
"release-test": "node node_modules/semantic-release/bin/semantic-release.js --dry-run --plugins @semantic-release/commit-analyzer @semantic-release/release-notes-generator",
|
|
73
|
-
"start": "tree-sitter playground",
|
|
74
|
-
"test": "node --test bindings/node/*_test.js",
|
|
75
|
-
"build-prebuilds": "prebuildify --napi --strip --name tree-sitter-bash",
|
|
76
|
-
"build/ci": "tree-sitter generate"
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public",
|
|
73
|
+
"registry": "https://registry.npmjs.org/"
|
|
77
74
|
}
|
|
78
75
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/parser.c
CHANGED
|
@@ -259897,7 +259897,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_bash(void) {
|
|
|
259897
259897
|
.metadata = {
|
|
259898
259898
|
.major_version = 1,
|
|
259899
259899
|
.minor_version = 0,
|
|
259900
|
-
.patch_version =
|
|
259900
|
+
.patch_version = 1,
|
|
259901
259901
|
},
|
|
259902
259902
|
};
|
|
259903
259903
|
return &language;
|
package/src/scanner.c
CHANGED
|
@@ -216,21 +216,43 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, uint32_t inde
|
|
|
216
216
|
if (at_line_start) {
|
|
217
217
|
at_line_start = false;
|
|
218
218
|
lexer->mark_end(lexer);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
}
|
|
219
|
+
// Like bash, compare the delimiter with the line after joining backslash-newlines and
|
|
220
|
+
// then stripping the leading tabs of `<<-`. As elsewhere in the grammar, CRLF counts as a
|
|
221
|
+
// newline.
|
|
222
|
+
bool consumed = false;
|
|
223
|
+
bool escaped = false;
|
|
226
224
|
uint32_t matched = 0;
|
|
227
225
|
// At the end of input the lookahead is 0, which a delimiter holding NUL would otherwise match.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
for (;;) {
|
|
227
|
+
if (matched == 0 && heredoc->allows_indent && lexer->lookahead == '\t') {
|
|
228
|
+
advance(lexer);
|
|
229
|
+
consumed = true;
|
|
230
|
+
} else if (lexer->lookahead == '\\' && !heredoc->is_raw) {
|
|
231
|
+
advance(lexer);
|
|
232
|
+
consumed = true;
|
|
233
|
+
bool escaped_cr = lexer->lookahead == '\r';
|
|
234
|
+
if (escaped_cr) {
|
|
235
|
+
advance(lexer);
|
|
236
|
+
}
|
|
237
|
+
if (lexer->lookahead != '\n' || lexer->eof(lexer)) {
|
|
238
|
+
// An escape rather than a line continuation: the escaped character, which is
|
|
239
|
+
// the CR itself when no LF follows it, is content.
|
|
240
|
+
if (!escaped_cr && !lexer->eof(lexer)) {
|
|
241
|
+
advance(lexer);
|
|
242
|
+
}
|
|
243
|
+
escaped = true;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
advance(lexer);
|
|
247
|
+
} else if (matched < heredoc->delimiter.size && !lexer->eof(lexer) &&
|
|
248
|
+
lexer->lookahead == *array_get(&heredoc->delimiter, matched)) {
|
|
249
|
+
advance(lexer);
|
|
250
|
+
matched++;
|
|
251
|
+
} else {
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
232
254
|
}
|
|
233
|
-
if (lexer->lookahead == '\r') {
|
|
255
|
+
if (!escaped && lexer->lookahead == '\r') {
|
|
234
256
|
advance(lexer);
|
|
235
257
|
}
|
|
236
258
|
// Inside a substitution, bash also ends the body at a delimiter directly followed by the
|
|
@@ -238,7 +260,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, uint32_t inde
|
|
|
238
260
|
bool ends_line = lexer->lookahead == '\n' || lexer->eof(lexer) ||
|
|
239
261
|
(scanner->closers.size > 0 && lexer->lookahead == *array_back(&scanner->closers)) ||
|
|
240
262
|
(lexer->lookahead == '`' && scanner->backtick_depth > 0);
|
|
241
|
-
if (matched == heredoc->delimiter.size && ends_line) {
|
|
263
|
+
if (!escaped && matched == heredoc->delimiter.size && ends_line) {
|
|
242
264
|
if (did_advance) {
|
|
243
265
|
lexer->result_symbol = HEREDOC_CONTENT;
|
|
244
266
|
return true;
|
|
@@ -251,7 +273,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, uint32_t inde
|
|
|
251
273
|
}
|
|
252
274
|
// The characters read while trying the delimiter are content; an empty attempt must not
|
|
253
275
|
// count, or a zero-width content token would repeat forever.
|
|
254
|
-
did_advance = did_advance ||
|
|
276
|
+
did_advance = did_advance || consumed || matched > 0;
|
|
255
277
|
continue;
|
|
256
278
|
}
|
|
257
279
|
|
|
@@ -274,11 +296,14 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer, uint32_t inde
|
|
|
274
296
|
advance(lexer);
|
|
275
297
|
did_advance = true;
|
|
276
298
|
if (!heredoc->is_raw && !lexer->eof(lexer)) {
|
|
277
|
-
// A backslash-newline joins lines before the delimiter comparison.
|
|
299
|
+
// A backslash-newline joins lines before the delimiter comparison. A CR without an
|
|
300
|
+
// LF after it is the escaped character itself.
|
|
278
301
|
if (lexer->lookahead == '\r') {
|
|
279
302
|
advance(lexer);
|
|
280
|
-
|
|
281
|
-
|
|
303
|
+
if (lexer->lookahead == '\n') {
|
|
304
|
+
advance(lexer);
|
|
305
|
+
}
|
|
306
|
+
} else if (!lexer->eof(lexer)) {
|
|
282
307
|
advance(lexer);
|
|
283
308
|
}
|
|
284
309
|
}
|
package/tree-sitter.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
],
|
|
20
20
|
"metadata": {
|
|
21
|
-
"version": "1.0.
|
|
21
|
+
"version": "1.0.1",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"description": "Bash grammar for tree-sitter",
|
|
24
24
|
"authors": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"go": true,
|
|
41
41
|
"node": true,
|
|
42
42
|
"python": true,
|
|
43
|
-
"rust":
|
|
43
|
+
"rust": false,
|
|
44
44
|
"swift": true
|
|
45
45
|
}
|
|
46
46
|
}
|