@willbooster/tree-sitter-bash 4.0.3 → 5.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/README.md +16 -52
- package/grammar.js +207 -114
- package/package.json +3 -3
- package/tree-sitter-bash.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -17,12 +17,13 @@ As a result, its syntax trees differ from the original grammar's; review your qu
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
The npm package ships `tree-sitter-bash.wasm` for
|
|
20
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter)
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) 7.0.17 or later in the 7.x series,
|
|
21
|
+
a peer dependency.
|
|
22
|
+
The parser carries the ABI number of WillBooster/tree-sitter (`0x57420006`), so only that runtime loads it; the
|
|
23
|
+
original tree-sitter runtime rejects it, and earlier WillBooster runtime ABIs do too:
|
|
23
24
|
|
|
24
25
|
```sh
|
|
25
|
-
npm install @willbooster/tree-sitter-bash @willbooster/web-tree-sitter@^
|
|
26
|
+
npm install @willbooster/tree-sitter-bash @willbooster/web-tree-sitter@^7.0.17
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
In Node.js and Bun, load the grammar from its path:
|
|
@@ -66,15 +67,18 @@ parser.setLanguage(await Language.load(bash));
|
|
|
66
67
|
|
|
67
68
|
The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
shape of
|
|
70
|
+
Upgrade `@willbooster/web-tree-sitter` to 7.0.17 or later in the 7.x series when upgrading this package. Recovery trees
|
|
71
|
+
for malformed scripts can differ across runtime versions, so review consumers that depend on the exact shape of
|
|
72
|
+
`ERROR` nodes.
|
|
71
73
|
|
|
72
74
|
Inside backquotes, the text of a node is the source text: consumers that read the value of a word or a string there
|
|
73
75
|
remove a backslash before `$`, a backquote, or a backslash (and before `"` when the backquotes are inside double quotes)
|
|
74
76
|
before they remove quotes and escapes as usual. Ordinary word and double-quoted string scanning account for those
|
|
75
77
|
removals when recognizing expansions, quotes, blanks, and shell operators. Backquotes that delimit the substitution
|
|
76
|
-
retain their source escape parity.
|
|
77
|
-
|
|
78
|
+
retain their source escape parity. Source continuations inside ordinary words and double-quoted strings are removed
|
|
79
|
+
before the resulting command text is parsed. Continuations around deferred heredoc bodies, heredoc text, parameter
|
|
80
|
+
expansions, regexes, nested backquotes, and PID expansions split by a removed escape retain their existing parsing
|
|
81
|
+
limitations.
|
|
78
82
|
|
|
79
83
|
## Development
|
|
80
84
|
|
|
@@ -83,53 +87,13 @@ mise install
|
|
|
83
87
|
bun install --frozen-lockfile
|
|
84
88
|
bun playwright install chromium
|
|
85
89
|
bun run build/ci
|
|
90
|
+
bun run verify
|
|
86
91
|
bun run test
|
|
87
|
-
script/parse-examples
|
|
88
92
|
```
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
runtime's GitHub Release, or builds it with `cargo` (whose build runs the CMake that `mise.toml` pins) when the download fails or the release has no
|
|
94
|
-
binary that runs here. Run other CLI commands through it as well (e.g. `script/tree-sitter parse script.sh`).
|
|
95
|
-
|
|
96
|
-
`bun run generate` records a fresh generation profile from the applicable `test/corpus` cases and Git-tracked
|
|
97
|
-
files in `examples/`, then generates compact parser tables. The parser also embeds metadata from `tree-sitter.json`. After changing a grammar,
|
|
98
|
-
`tree-sitter.json`, a corpus case, or a tracked example,
|
|
99
|
-
regenerate and commit `src/`. Stage added or removed examples with `git add -A examples` before generation so the profile uses the intended file list.
|
|
100
|
-
Profiles in `.tmp/generation-profiles/` are temporary and must not be committed. `bun run build-wasm`, `bun run build/ci`,
|
|
101
|
-
and the release build regenerate the parsers before compiling them.
|
|
102
|
-
|
|
103
|
-
`bun run test` runs:
|
|
104
|
-
|
|
105
|
-
- the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
|
|
106
|
-
- an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
|
|
107
|
-
edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
|
|
108
|
-
`TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits. It also applies edits that random ones
|
|
109
|
-
rarely reach and compares each incremental reparse with a fresh parse;
|
|
110
|
-
- a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
|
|
111
|
-
`script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
|
|
112
|
-
pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
|
|
113
|
-
`script/parse-examples` rewrites it; review its diff before committing;
|
|
114
|
-
- a differential test (`test/unit/differential.test.ts`, with helpers in `test/helpers/differential`) that generates
|
|
115
|
-
scripts and runs them with the bash that `mise.toml` pins. It checks that the syntax tree shows exactly the commands
|
|
116
|
-
bash runs, with as many words and the same value for each word without expansions, and that the tree has no
|
|
117
|
-
`ERROR` or `MISSING` node for a script bash accepts. A failure prints the seed; `DIFFERENTIAL_SEED` and
|
|
118
|
-
`DIFFERENTIAL_CASES` run other or more scripts. It loads the Wasm build through @willbooster/web-tree-sitter, which
|
|
119
|
-
`bun run build/ci` rebuilds after regenerating the parser;
|
|
120
|
-
- a performance check (`test/unit/performance.test.ts`) that a long line parses in linear time, since consumers
|
|
121
|
-
parse untrusted scripts;
|
|
122
|
-
- checks that the Wasm build parses in Chromium (`test/unit/web.browser.test.ts`) and in Cloudflare Workers with and
|
|
123
|
-
without Node.js compatibility (`test/unit/workers.test.ts`, with the Worker in `test/fixtures/worker`), loading it as
|
|
124
|
-
the Usage section shows.
|
|
125
|
-
|
|
126
|
-
The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
|
|
127
|
-
by every checkout; `script/fuzz-corpus` and the targeted edits of the incremental check build a parser of their own
|
|
128
|
-
for each run and delete it afterwards.
|
|
129
|
-
|
|
130
|
-
CI also fuzzes the parser with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
|
|
131
|
-
|
|
132
|
-
### References
|
|
94
|
+
- [Parser generation and validation](docs/development.md): read before changing grammar inputs, refreshing examples, or reproducing a fuzz or differential failure.
|
|
95
|
+
|
|
96
|
+
## References
|
|
133
97
|
|
|
134
98
|
- [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)
|
|
135
99
|
- [Shell command language specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
|
package/grammar.js
CHANGED
|
@@ -185,7 +185,7 @@ module.exports = grammar({
|
|
|
185
185
|
_terminated_statements: ($) => repeat1(seq($._statement, $._terminator)),
|
|
186
186
|
|
|
187
187
|
// A newline is significant only where it can end a statement; elsewhere it is whitespace.
|
|
188
|
-
_terminator: () => choice(';', '&', sym('_newline')),
|
|
188
|
+
_terminator: () => choice(token.nonkeyword(';'), token.nonkeyword('&'), sym('_newline')),
|
|
189
189
|
|
|
190
190
|
_statement: ($) =>
|
|
191
191
|
choice($._command_statement, $.pipeline, $.list, $.negated_command, $.timed_command, $.coproc_command),
|
|
@@ -209,21 +209,33 @@ module.exports = grammar({
|
|
|
209
209
|
list: ($) =>
|
|
210
210
|
prec.left(
|
|
211
211
|
1,
|
|
212
|
-
seq(
|
|
212
|
+
seq(
|
|
213
|
+
field('left', $._statement),
|
|
214
|
+
field('operator', choice(token.nonkeyword('&&'), token.nonkeyword('||'))),
|
|
215
|
+
field('right', $._statement)
|
|
216
|
+
)
|
|
213
217
|
),
|
|
214
218
|
|
|
215
|
-
pipeline: ($) =>
|
|
219
|
+
pipeline: ($) =>
|
|
220
|
+
prec.left(
|
|
221
|
+
3,
|
|
222
|
+
seq(
|
|
223
|
+
$._pipeline_element,
|
|
224
|
+
repeat1(seq(choice(token.nonkeyword('|'), token.nonkeyword('|&')), $._pipeline_element))
|
|
225
|
+
)
|
|
226
|
+
),
|
|
216
227
|
|
|
217
228
|
_pipeline_element: ($) => choice($._command_statement, $.coproc_command),
|
|
218
229
|
|
|
219
|
-
negated_command: ($) =>
|
|
230
|
+
negated_command: ($) =>
|
|
231
|
+
prec.right(2, seq(token.nonkeyword('!'), choice($._command_statement, $.pipeline, $.timed_command))),
|
|
220
232
|
|
|
221
233
|
timed_command: ($) =>
|
|
222
234
|
prec.right(
|
|
223
235
|
2,
|
|
224
236
|
seq(
|
|
225
237
|
choice('time', alias(sym('_timing_keyword'), 'time')),
|
|
226
|
-
optional(field('option', alias(choice('-p', sym('_timing_option')), $.word))),
|
|
238
|
+
optional(field('option', alias(choice(token.nonkeyword('-p'), sym('_timing_option')), $.word))),
|
|
227
239
|
optional(alias(sym('_timing_terminator'), $.word)),
|
|
228
240
|
optional(choice($._command_statement, $.pipeline, $.negated_command))
|
|
229
241
|
)
|
|
@@ -284,7 +296,7 @@ module.exports = grammar({
|
|
|
284
296
|
variable_assignment: ($) =>
|
|
285
297
|
seq(
|
|
286
298
|
field('name', choice(sym('variable_name'), $.subscript)),
|
|
287
|
-
field('operator', token.immediate(choice('=', '+='))),
|
|
299
|
+
field('operator', token.nonkeyword(token.immediate(choice('=', '+=')))),
|
|
288
300
|
field('value', choice($._argument, $._hash_value, $.array, sym('_empty_value')))
|
|
289
301
|
),
|
|
290
302
|
|
|
@@ -305,7 +317,12 @@ module.exports = grammar({
|
|
|
305
317
|
),
|
|
306
318
|
|
|
307
319
|
subscript: ($) =>
|
|
308
|
-
seq(
|
|
320
|
+
seq(
|
|
321
|
+
field('name', sym('variable_name')),
|
|
322
|
+
token.nonkeyword(token.immediate('[')),
|
|
323
|
+
field('index', $._subscript_index),
|
|
324
|
+
token.nonkeyword(']')
|
|
325
|
+
),
|
|
309
326
|
|
|
310
327
|
// Like bash, the index extends to the matching `]`, so it may hold bracketed groups at any depth
|
|
311
328
|
// (`A[x[1[2]]]`), blanks, and newlines.
|
|
@@ -320,7 +337,7 @@ module.exports = grammar({
|
|
|
320
337
|
)
|
|
321
338
|
),
|
|
322
339
|
|
|
323
|
-
_subscript_group: ($) => seq('[', optional($._subscript_index), ']'),
|
|
340
|
+
_subscript_group: ($) => seq(token.nonkeyword('['), optional($._subscript_index), token.nonkeyword(']')),
|
|
324
341
|
|
|
325
342
|
// Word parts that carry their own delimiters, usable where a bare word would overrun a closing
|
|
326
343
|
// `]` or `}`.
|
|
@@ -337,7 +354,7 @@ module.exports = grammar({
|
|
|
337
354
|
$.process_substitution
|
|
338
355
|
),
|
|
339
356
|
|
|
340
|
-
array: ($) => seq(token.immediate('('), repeat($._argument), ')'),
|
|
357
|
+
array: ($) => seq(token.nonkeyword(token.immediate('(')), repeat($._argument), token.nonkeyword(')')),
|
|
341
358
|
|
|
342
359
|
_redirect: ($) => choice($.file_redirect, $.heredoc_redirect, $.herestring_redirect),
|
|
343
360
|
|
|
@@ -346,15 +363,32 @@ module.exports = grammar({
|
|
|
346
363
|
optional(field('descriptor', sym('file_descriptor'))),
|
|
347
364
|
choice(
|
|
348
365
|
seq(
|
|
349
|
-
field(
|
|
366
|
+
field(
|
|
367
|
+
'operator',
|
|
368
|
+
choice(
|
|
369
|
+
token.nonkeyword('<'),
|
|
370
|
+
token.nonkeyword('>'),
|
|
371
|
+
token.nonkeyword('>>'),
|
|
372
|
+
token.nonkeyword('>|'),
|
|
373
|
+
token.nonkeyword('<>'),
|
|
374
|
+
token.nonkeyword('&>'),
|
|
375
|
+
token.nonkeyword('&>>'),
|
|
376
|
+
token.nonkeyword('<&'),
|
|
377
|
+
token.nonkeyword('>&')
|
|
378
|
+
)
|
|
379
|
+
),
|
|
350
380
|
field('destination', $._argument)
|
|
351
381
|
),
|
|
352
|
-
field('operator', choice('<&-', '>&-'))
|
|
382
|
+
field('operator', choice(token.nonkeyword('<&-'), token.nonkeyword('>&-')))
|
|
353
383
|
)
|
|
354
384
|
),
|
|
355
385
|
|
|
356
386
|
herestring_redirect: ($) =>
|
|
357
|
-
seq(
|
|
387
|
+
seq(
|
|
388
|
+
optional(field('descriptor', sym('file_descriptor'))),
|
|
389
|
+
field('operator', token.nonkeyword('<<<')),
|
|
390
|
+
field('value', $._argument)
|
|
391
|
+
),
|
|
358
392
|
|
|
359
393
|
heredoc_redirect: () =>
|
|
360
394
|
seq(
|
|
@@ -380,14 +414,20 @@ module.exports = grammar({
|
|
|
380
414
|
sym('heredoc_end')
|
|
381
415
|
),
|
|
382
416
|
|
|
383
|
-
compound_statement: ($) => seq('{', optional($._terminated_statements), '}'),
|
|
417
|
+
compound_statement: ($) => seq(token.nonkeyword('{'), optional($._terminated_statements), token.nonkeyword('}')),
|
|
384
418
|
|
|
385
|
-
subshell: ($) => seq('(', optional($._statements), ')'),
|
|
419
|
+
subshell: ($) => seq(token.nonkeyword('('), optional($._statements), token.nonkeyword(')')),
|
|
386
420
|
|
|
387
421
|
arithmetic_command: ($) =>
|
|
388
|
-
seq(
|
|
422
|
+
seq(
|
|
423
|
+
token.nonkeyword('(('),
|
|
424
|
+
sym('_substitution_start'),
|
|
425
|
+
optional($._arithmetic_expression),
|
|
426
|
+
sym('_substitution_end'),
|
|
427
|
+
token.nonkeyword('))')
|
|
428
|
+
),
|
|
389
429
|
|
|
390
|
-
test_command: ($) => seq('[[', $._test_expression, ']]'),
|
|
430
|
+
test_command: ($) => seq(token.nonkeyword('[['), $._test_expression, token.nonkeyword(']]')),
|
|
391
431
|
|
|
392
432
|
_test_expression: ($) =>
|
|
393
433
|
choice(
|
|
@@ -404,7 +444,7 @@ module.exports = grammar({
|
|
|
404
444
|
prec(
|
|
405
445
|
PREC.UNARY,
|
|
406
446
|
seq(
|
|
407
|
-
field('operator', alias(choice(...TEST_UNARY_OPERATORS), sym('test_operator'))),
|
|
447
|
+
field('operator', alias(token.nonkeyword(choice(...TEST_UNARY_OPERATORS)), sym('test_operator'))),
|
|
408
448
|
field('operand', $._argument)
|
|
409
449
|
)
|
|
410
450
|
),
|
|
@@ -415,7 +455,7 @@ module.exports = grammar({
|
|
|
415
455
|
PREC.COMPARE,
|
|
416
456
|
seq(
|
|
417
457
|
field('left', $._word),
|
|
418
|
-
field('operator', alias(choice(...TEST_BINARY_OPERATORS), sym('test_operator'))),
|
|
458
|
+
field('operator', alias(token.nonkeyword(choice(...TEST_BINARY_OPERATORS)), sym('test_operator'))),
|
|
419
459
|
field('right', $._argument)
|
|
420
460
|
)
|
|
421
461
|
),
|
|
@@ -427,7 +467,7 @@ module.exports = grammar({
|
|
|
427
467
|
PREC.COMPARE,
|
|
428
468
|
seq(
|
|
429
469
|
field('left', $._word),
|
|
430
|
-
field('operator', '=~'),
|
|
470
|
+
field('operator', token.nonkeyword('=~')),
|
|
431
471
|
sym('_regex_start'),
|
|
432
472
|
field('right', choice($._regex_part, alias($._regex_concatenation, $.concatenation)))
|
|
433
473
|
)
|
|
@@ -437,15 +477,15 @@ module.exports = grammar({
|
|
|
437
477
|
|
|
438
478
|
_regex_part: ($) => choice(sym('regex'), $._quoted_or_expansion),
|
|
439
479
|
|
|
440
|
-
_test_negation: ($) => prec(PREC.UNARY, seq('!', $._test_expression)),
|
|
480
|
+
_test_negation: ($) => prec(PREC.UNARY, seq(token.nonkeyword('!'), $._test_expression)),
|
|
441
481
|
|
|
442
482
|
_test_logical: ($) =>
|
|
443
483
|
choice(
|
|
444
|
-
prec.left(PREC.LOGICAL_AND, seq($._test_expression, '&&', $._test_expression)),
|
|
445
|
-
prec.left(PREC.LOGICAL_OR, seq($._test_expression, '||', $._test_expression))
|
|
484
|
+
prec.left(PREC.LOGICAL_AND, seq($._test_expression, token.nonkeyword('&&'), $._test_expression)),
|
|
485
|
+
prec.left(PREC.LOGICAL_OR, seq($._test_expression, token.nonkeyword('||'), $._test_expression))
|
|
446
486
|
),
|
|
447
487
|
|
|
448
|
-
_test_parenthesized: ($) => seq('(', $._test_expression, ')'),
|
|
488
|
+
_test_parenthesized: ($) => seq(token.nonkeyword('('), $._test_expression, token.nonkeyword(')')),
|
|
449
489
|
|
|
450
490
|
if_statement: ($) =>
|
|
451
491
|
seq(
|
|
@@ -499,15 +539,15 @@ module.exports = grammar({
|
|
|
499
539
|
c_style_for_statement: ($) =>
|
|
500
540
|
seq(
|
|
501
541
|
'for',
|
|
502
|
-
'((',
|
|
542
|
+
token.nonkeyword('(('),
|
|
503
543
|
sym('_substitution_start'),
|
|
504
544
|
field('initializer', optional($._arithmetic_expression)),
|
|
505
|
-
';',
|
|
545
|
+
token.nonkeyword(';'),
|
|
506
546
|
field('condition', optional($._arithmetic_expression)),
|
|
507
|
-
';',
|
|
547
|
+
token.nonkeyword(';'),
|
|
508
548
|
field('update', optional($._arithmetic_expression)),
|
|
509
549
|
sym('_substitution_end'),
|
|
510
|
-
'))',
|
|
550
|
+
token.nonkeyword('))'),
|
|
511
551
|
optional($._terminator),
|
|
512
552
|
field('body', choice($.do_group, $.compound_statement))
|
|
513
553
|
),
|
|
@@ -523,7 +563,12 @@ module.exports = grammar({
|
|
|
523
563
|
'esac'
|
|
524
564
|
),
|
|
525
565
|
|
|
526
|
-
case_item: ($) =>
|
|
566
|
+
case_item: ($) =>
|
|
567
|
+
seq(
|
|
568
|
+
$._case_patterns,
|
|
569
|
+
optional($._statements),
|
|
570
|
+
field('terminator', choice(token.nonkeyword(';;'), token.nonkeyword(';&'), token.nonkeyword(';;&')))
|
|
571
|
+
),
|
|
527
572
|
|
|
528
573
|
// Only the last item may omit its terminator, but its statements still end before `esac`, which is
|
|
529
574
|
// otherwise an argument (`a) echo esac`).
|
|
@@ -532,15 +577,18 @@ module.exports = grammar({
|
|
|
532
577
|
_case_patterns: ($) =>
|
|
533
578
|
seq(
|
|
534
579
|
optional(sym('_backtick_comment_boundary')),
|
|
535
|
-
optional('('),
|
|
580
|
+
optional(token.nonkeyword('(')),
|
|
536
581
|
field('pattern', $._argument),
|
|
537
|
-
repeat(seq('|', field('pattern', $._argument))),
|
|
538
|
-
')'
|
|
582
|
+
repeat(seq(token.nonkeyword('|'), field('pattern', $._argument))),
|
|
583
|
+
token.nonkeyword(')')
|
|
539
584
|
),
|
|
540
585
|
|
|
541
586
|
function_definition: ($) =>
|
|
542
587
|
seq(
|
|
543
|
-
choice(
|
|
588
|
+
choice(
|
|
589
|
+
seq('function', field('name', $.word), optional(seq(token.nonkeyword('('), token.nonkeyword(')')))),
|
|
590
|
+
seq(field('name', $.word), token.nonkeyword('('), token.nonkeyword(')'))
|
|
591
|
+
),
|
|
544
592
|
optional(sym('_backtick_comment_boundary')),
|
|
545
593
|
field('body', $._compound_command)
|
|
546
594
|
),
|
|
@@ -625,18 +673,21 @@ module.exports = grammar({
|
|
|
625
673
|
// `word`, whose token is longer than the group's opening token.
|
|
626
674
|
extglob_pattern: ($) =>
|
|
627
675
|
seq(
|
|
628
|
-
field(
|
|
676
|
+
field(
|
|
677
|
+
'operator',
|
|
678
|
+
choice(token.nonkeyword('?('), token.nonkeyword('*('), token.nonkeyword('+('), token.nonkeyword('@('))
|
|
679
|
+
),
|
|
629
680
|
optional($._extglob_alternative),
|
|
630
|
-
repeat(seq('|', optional($._extglob_alternative))),
|
|
631
|
-
')'
|
|
681
|
+
repeat(seq(token.nonkeyword('|'), optional($._extglob_alternative))),
|
|
682
|
+
token.nonkeyword(')')
|
|
632
683
|
),
|
|
633
684
|
|
|
634
685
|
_negated_extglob_pattern: ($) =>
|
|
635
686
|
seq(
|
|
636
|
-
field('operator', '!('),
|
|
687
|
+
field('operator', token.nonkeyword('!(')),
|
|
637
688
|
optional($._extglob_alternative),
|
|
638
|
-
repeat(seq('|', optional($._extglob_alternative))),
|
|
639
|
-
')'
|
|
689
|
+
repeat(seq(token.nonkeyword('|'), optional($._extglob_alternative))),
|
|
690
|
+
token.nonkeyword(')')
|
|
640
691
|
),
|
|
641
692
|
|
|
642
693
|
// An alternative may hold unquoted blanks, so each of its words is an `alternative` field; like
|
|
@@ -648,11 +699,11 @@ module.exports = grammar({
|
|
|
648
699
|
|
|
649
700
|
string: ($) =>
|
|
650
701
|
seq(
|
|
651
|
-
'"',
|
|
702
|
+
token.nonkeyword('"'),
|
|
652
703
|
repeat(
|
|
653
704
|
choice(sym('string_content'), $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
|
|
654
705
|
),
|
|
655
|
-
'"'
|
|
706
|
+
token.nonkeyword('"')
|
|
656
707
|
),
|
|
657
708
|
|
|
658
709
|
// Where a heredoc inside `$( )` ends on a line that holds the `)`, bash reads the rest of that line
|
|
@@ -665,7 +716,7 @@ module.exports = grammar({
|
|
|
665
716
|
seq(
|
|
666
717
|
sym('_closer_line_raw_string_start'),
|
|
667
718
|
repeat(alias(sym('_closer_line_raw_string_content'), sym('string_content'))),
|
|
668
|
-
"'"
|
|
719
|
+
token.nonkeyword("'")
|
|
669
720
|
)
|
|
670
721
|
),
|
|
671
722
|
|
|
@@ -675,25 +726,25 @@ module.exports = grammar({
|
|
|
675
726
|
seq(
|
|
676
727
|
sym('_closer_line_ansi_c_string_start'),
|
|
677
728
|
repeat(alias(sym('_closer_line_ansi_c_string_content'), sym('string_content'))),
|
|
678
|
-
"'"
|
|
729
|
+
token.nonkeyword("'")
|
|
679
730
|
)
|
|
680
731
|
),
|
|
681
732
|
|
|
682
733
|
translated_string: ($) =>
|
|
683
734
|
seq(
|
|
684
|
-
'$"',
|
|
735
|
+
token.nonkeyword('$"'),
|
|
685
736
|
repeat(
|
|
686
737
|
choice(sym('string_content'), $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
|
|
687
738
|
),
|
|
688
|
-
'"'
|
|
739
|
+
token.nonkeyword('"')
|
|
689
740
|
),
|
|
690
741
|
|
|
691
742
|
simple_expansion: () =>
|
|
692
743
|
seq(
|
|
693
|
-
'$',
|
|
744
|
+
token.nonkeyword('$'),
|
|
694
745
|
choice(
|
|
695
|
-
alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), sym('variable_name')),
|
|
696
|
-
alias(token.immediate(/[0-9*@#?$!_-]/), sym('special_variable_name'))
|
|
746
|
+
alias(token.nonkeyword(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/)), sym('variable_name')),
|
|
747
|
+
alias(token.nonkeyword(token.immediate(/[0-9*@#?$!_-]/)), sym('special_variable_name'))
|
|
697
748
|
)
|
|
698
749
|
),
|
|
699
750
|
|
|
@@ -701,22 +752,22 @@ module.exports = grammar({
|
|
|
701
752
|
// length and indirection prefixes.
|
|
702
753
|
expansion: ($) =>
|
|
703
754
|
seq(
|
|
704
|
-
'${',
|
|
755
|
+
token.nonkeyword('${'),
|
|
705
756
|
choice(
|
|
706
757
|
seq(
|
|
707
|
-
optional(field('prefix', alias(token.immediate(choice('#', '!')), sym('operator')))),
|
|
758
|
+
optional(field('prefix', alias(token.nonkeyword(token.immediate(choice('#', '!'))), sym('operator')))),
|
|
708
759
|
field(
|
|
709
760
|
'parameter',
|
|
710
761
|
choice(
|
|
711
|
-
alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), sym('variable_name')),
|
|
712
|
-
alias(token.immediate(/[0-9]+|[*@?$_-]/), sym('special_variable_name')),
|
|
713
|
-
alias(token.immediate(choice('#', '!')), sym('special_variable_name')),
|
|
762
|
+
alias(token.nonkeyword(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/)), sym('variable_name')),
|
|
763
|
+
alias(token.nonkeyword(token.immediate(/[0-9]+|[*@?$_-]/)), sym('special_variable_name')),
|
|
764
|
+
alias(token.nonkeyword(token.immediate(choice('#', '!'))), sym('special_variable_name')),
|
|
714
765
|
alias($._expansion_subscript, $.subscript)
|
|
715
766
|
)
|
|
716
767
|
),
|
|
717
768
|
optional($._expansion_operation)
|
|
718
769
|
),
|
|
719
|
-
field('parameter', alias(token.immediate(choice('#', '!')), sym('special_variable_name'))),
|
|
770
|
+
field('parameter', alias(token.nonkeyword(token.immediate(choice('#', '!'))), sym('special_variable_name'))),
|
|
720
771
|
// Bash rejects `${}` and a body without a parameter (`${=1}`, `${"x"}`) only when expanding. A
|
|
721
772
|
// `$name` expansion is left out, since its `$` would tie with the special parameter in `${$}`.
|
|
722
773
|
repeat(
|
|
@@ -735,13 +786,13 @@ module.exports = grammar({
|
|
|
735
786
|
)
|
|
736
787
|
)
|
|
737
788
|
),
|
|
738
|
-
'}'
|
|
789
|
+
token.nonkeyword('}')
|
|
739
790
|
),
|
|
740
791
|
|
|
741
792
|
_expansion_subscript: ($) =>
|
|
742
793
|
seq(
|
|
743
|
-
field('name', alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), sym('variable_name'))),
|
|
744
|
-
repeat1(seq(token.immediate('['), field('index', $._subscript_index), ']'))
|
|
794
|
+
field('name', alias(token.nonkeyword(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/)), sym('variable_name'))),
|
|
795
|
+
repeat1(seq(token.nonkeyword(token.immediate('[')), field('index', $._subscript_index), token.nonkeyword(']')))
|
|
745
796
|
),
|
|
746
797
|
|
|
747
798
|
_expansion_operation: ($) =>
|
|
@@ -750,32 +801,34 @@ module.exports = grammar({
|
|
|
750
801
|
field(
|
|
751
802
|
'operator',
|
|
752
803
|
alias(
|
|
753
|
-
token.
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
804
|
+
token.nonkeyword(
|
|
805
|
+
token.immediate(
|
|
806
|
+
choice(
|
|
807
|
+
':-',
|
|
808
|
+
'-',
|
|
809
|
+
':=',
|
|
810
|
+
'=',
|
|
811
|
+
':?',
|
|
812
|
+
'?',
|
|
813
|
+
':+',
|
|
814
|
+
'+',
|
|
815
|
+
'#',
|
|
816
|
+
'##',
|
|
817
|
+
'%',
|
|
818
|
+
'%%',
|
|
819
|
+
'^',
|
|
820
|
+
'^^',
|
|
821
|
+
',',
|
|
822
|
+
',,',
|
|
823
|
+
'~',
|
|
824
|
+
'~~',
|
|
825
|
+
'/',
|
|
826
|
+
'//',
|
|
827
|
+
'/#',
|
|
828
|
+
'/%',
|
|
829
|
+
':',
|
|
830
|
+
'@'
|
|
831
|
+
)
|
|
779
832
|
)
|
|
780
833
|
),
|
|
781
834
|
sym('operator')
|
|
@@ -794,7 +847,7 @@ module.exports = grammar({
|
|
|
794
847
|
)
|
|
795
848
|
)
|
|
796
849
|
),
|
|
797
|
-
field('operator', alias(token.immediate(choice('*', '@')), sym('operator'))),
|
|
850
|
+
field('operator', alias(token.nonkeyword(token.immediate(choice('*', '@'))), sym('operator'))),
|
|
798
851
|
// Text without an operator (`${x y}`) is rejected by bash only when expanding.
|
|
799
852
|
repeat1(
|
|
800
853
|
field(
|
|
@@ -838,11 +891,11 @@ module.exports = grammar({
|
|
|
838
891
|
choice(
|
|
839
892
|
seq(
|
|
840
893
|
sym('_command_substitution_start'),
|
|
841
|
-
'$(',
|
|
894
|
+
token.nonkeyword('$('),
|
|
842
895
|
sym('_substitution_start'),
|
|
843
896
|
optional($._statements),
|
|
844
897
|
sym('_substitution_end'),
|
|
845
|
-
')'
|
|
898
|
+
token.nonkeyword(')')
|
|
846
899
|
),
|
|
847
900
|
// bash 5.3 runs `${ list; }` and `${| list; }` in the current shell.
|
|
848
901
|
seq(
|
|
@@ -850,30 +903,36 @@ module.exports = grammar({
|
|
|
850
903
|
sym('_brace_substitution_start'),
|
|
851
904
|
optional($._terminated_statements),
|
|
852
905
|
sym('_brace_substitution_end'),
|
|
853
|
-
'}'
|
|
906
|
+
token.nonkeyword('}')
|
|
854
907
|
),
|
|
855
908
|
seq(alias(sym('_backtick_open'), '`'), optional($._statements), alias(sym('_backtick_close'), '`'))
|
|
856
909
|
),
|
|
857
910
|
|
|
858
911
|
process_substitution: ($) =>
|
|
859
|
-
seq(
|
|
912
|
+
seq(
|
|
913
|
+
choice(token.nonkeyword('<('), token.nonkeyword('>(')),
|
|
914
|
+
sym('_substitution_start'),
|
|
915
|
+
optional($._statements),
|
|
916
|
+
sym('_substitution_end'),
|
|
917
|
+
token.nonkeyword(')')
|
|
918
|
+
),
|
|
860
919
|
|
|
861
920
|
// Arithmetic may span lines, and a heredoc body starts only after it, so it counts as nesting.
|
|
862
921
|
arithmetic_expansion: ($) =>
|
|
863
922
|
choice(
|
|
864
923
|
seq(
|
|
865
924
|
sym('_arithmetic_substitution_start'),
|
|
866
|
-
'$((',
|
|
925
|
+
token.nonkeyword('$(('),
|
|
867
926
|
optional($._arithmetic_expression),
|
|
868
927
|
sym('_substitution_end'),
|
|
869
|
-
'))'
|
|
928
|
+
token.nonkeyword('))')
|
|
870
929
|
),
|
|
871
930
|
seq(
|
|
872
|
-
'$[',
|
|
931
|
+
token.nonkeyword('$['),
|
|
873
932
|
sym('_bracket_substitution_start'),
|
|
874
933
|
optional($._arithmetic_expression),
|
|
875
934
|
sym('_bracket_substitution_end'),
|
|
876
|
-
']'
|
|
935
|
+
token.nonkeyword(']')
|
|
877
936
|
)
|
|
878
937
|
),
|
|
879
938
|
|
|
@@ -896,9 +955,9 @@ module.exports = grammar({
|
|
|
896
955
|
|
|
897
956
|
number: ($) =>
|
|
898
957
|
choice(
|
|
899
|
-
/(0[xX][0-9a-fA-F]+|[0-9]+#[0-9a-zA-Z@_]+|[0-9]+)
|
|
958
|
+
token.nonkeyword(/(0[xX][0-9a-fA-F]+|[0-9]+#[0-9a-zA-Z@_]+|[0-9]+)/),
|
|
900
959
|
// The digits of a based number may come from an expansion (`10#${x}`).
|
|
901
|
-
seq(/[0-9]
|
|
960
|
+
seq(token.nonkeyword(/[0-9]+#/), choice($.simple_expansion, $.expansion))
|
|
902
961
|
),
|
|
903
962
|
|
|
904
963
|
_arithmetic_variable: () => /[A-Za-z_][A-Za-z0-9_]*/,
|
|
@@ -906,36 +965,70 @@ module.exports = grammar({
|
|
|
906
965
|
_arithmetic_subscript: ($) =>
|
|
907
966
|
seq(
|
|
908
967
|
field('name', alias($._arithmetic_variable, sym('variable_name'))),
|
|
909
|
-
token.immediate('['),
|
|
968
|
+
token.nonkeyword(token.immediate('[')),
|
|
910
969
|
field('index', $._arithmetic_expression),
|
|
911
|
-
']'
|
|
970
|
+
token.nonkeyword(']')
|
|
912
971
|
),
|
|
913
972
|
|
|
914
973
|
_arithmetic_unary: ($) =>
|
|
915
974
|
choice(
|
|
916
|
-
prec(
|
|
917
|
-
|
|
975
|
+
prec(
|
|
976
|
+
PREC.PREFIX,
|
|
977
|
+
seq(field('operator', choice(token.nonkeyword('++'), token.nonkeyword('--'))), $._arithmetic_expression)
|
|
978
|
+
),
|
|
979
|
+
prec(
|
|
980
|
+
PREC.UNARY,
|
|
981
|
+
seq(
|
|
982
|
+
field(
|
|
983
|
+
'operator',
|
|
984
|
+
choice(token.nonkeyword('-'), token.nonkeyword('+'), token.nonkeyword('!'), token.nonkeyword('~'))
|
|
985
|
+
),
|
|
986
|
+
$._arithmetic_expression
|
|
987
|
+
)
|
|
988
|
+
)
|
|
918
989
|
),
|
|
919
990
|
|
|
920
991
|
_arithmetic_postfix: ($) =>
|
|
921
|
-
prec(
|
|
992
|
+
prec(
|
|
993
|
+
PREC.POSTFIX,
|
|
994
|
+
seq($._arithmetic_expression, field('operator', choice(token.nonkeyword('++'), token.nonkeyword('--'))))
|
|
995
|
+
),
|
|
922
996
|
|
|
923
997
|
_arithmetic_binary: ($) => {
|
|
924
998
|
/** @type {[number, import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral][]} */
|
|
925
999
|
const table = [
|
|
926
|
-
[PREC.COMMA, ','],
|
|
927
|
-
[
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1000
|
+
[PREC.COMMA, token.nonkeyword(',')],
|
|
1001
|
+
[
|
|
1002
|
+
PREC.ASSIGN,
|
|
1003
|
+
choice(
|
|
1004
|
+
token.nonkeyword('='),
|
|
1005
|
+
token.nonkeyword('+='),
|
|
1006
|
+
token.nonkeyword('-='),
|
|
1007
|
+
token.nonkeyword('*='),
|
|
1008
|
+
token.nonkeyword('/='),
|
|
1009
|
+
token.nonkeyword('%='),
|
|
1010
|
+
token.nonkeyword('**='),
|
|
1011
|
+
token.nonkeyword('<<='),
|
|
1012
|
+
token.nonkeyword('>>='),
|
|
1013
|
+
token.nonkeyword('&='),
|
|
1014
|
+
token.nonkeyword('^='),
|
|
1015
|
+
token.nonkeyword('|=')
|
|
1016
|
+
),
|
|
1017
|
+
],
|
|
1018
|
+
[PREC.LOGICAL_OR, token.nonkeyword('||')],
|
|
1019
|
+
[PREC.LOGICAL_AND, token.nonkeyword('&&')],
|
|
1020
|
+
[PREC.BITWISE_OR, token.nonkeyword('|')],
|
|
1021
|
+
[PREC.BITWISE_XOR, token.nonkeyword('^')],
|
|
1022
|
+
[PREC.BITWISE_AND, token.nonkeyword('&')],
|
|
1023
|
+
[PREC.EQUALITY, choice(token.nonkeyword('=='), token.nonkeyword('!='))],
|
|
1024
|
+
[
|
|
1025
|
+
PREC.COMPARE,
|
|
1026
|
+
choice(token.nonkeyword('<'), token.nonkeyword('>'), token.nonkeyword('<='), token.nonkeyword('>=')),
|
|
1027
|
+
],
|
|
1028
|
+
[PREC.SHIFT, choice(token.nonkeyword('<<'), token.nonkeyword('>>'))],
|
|
1029
|
+
[PREC.ADD, choice(token.nonkeyword('+'), token.nonkeyword('-'))],
|
|
1030
|
+
[PREC.MULTIPLY, choice(token.nonkeyword('*'), token.nonkeyword('/'), token.nonkeyword('%'))],
|
|
1031
|
+
[PREC.EXPONENT, token.nonkeyword('**')],
|
|
939
1032
|
];
|
|
940
1033
|
return choice(
|
|
941
1034
|
...table.map(([precedence, operator]) => {
|
|
@@ -956,14 +1049,14 @@ module.exports = grammar({
|
|
|
956
1049
|
PREC.TERNARY,
|
|
957
1050
|
seq(
|
|
958
1051
|
field('condition', $._arithmetic_expression),
|
|
959
|
-
'?',
|
|
1052
|
+
token.nonkeyword('?'),
|
|
960
1053
|
field('consequence', $._arithmetic_expression),
|
|
961
|
-
':',
|
|
1054
|
+
token.nonkeyword(':'),
|
|
962
1055
|
field('alternative', $._arithmetic_expression)
|
|
963
1056
|
)
|
|
964
1057
|
),
|
|
965
1058
|
|
|
966
|
-
_arithmetic_parenthesized: ($) => seq('(', $._arithmetic_expression, ')'),
|
|
1059
|
+
_arithmetic_parenthesized: ($) => seq(token.nonkeyword('('), $._arithmetic_expression, token.nonkeyword(')')),
|
|
967
1060
|
|
|
968
1061
|
comment: () => choice(token(prec(-10, /#.*/)), sym('_joined_comment'), sym('_backtick_comment')),
|
|
969
1062
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-bash",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Bash grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
47
47
|
"@willbooster/oxlint-config": "1.4.8",
|
|
48
48
|
"@willbooster/wb": "22.26.1",
|
|
49
|
-
"@willbooster/web-tree-sitter": "
|
|
49
|
+
"@willbooster/web-tree-sitter": "7.0.17",
|
|
50
50
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
51
51
|
"lefthook": "2.2.1",
|
|
52
52
|
"oxfmt": "0.72.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"wrangler": "4.149.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@willbooster/web-tree-sitter": "^
|
|
63
|
+
"@willbooster/web-tree-sitter": "^7.0.17"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"@willbooster/web-tree-sitter": {
|
package/tree-sitter-bash.wasm
CHANGED
|
Binary file
|