@willbooster/tree-sitter-bash 0.25.1 → 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 CHANGED
@@ -1,44 +1,51 @@
1
- # tree-sitter-bash
2
-
3
- [![CI][ci]](https://github.com/tree-sitter/tree-sitter-bash/actions/workflows/ci.yml)
4
- [![discord][discord]](https://discord.gg/w7nTvsVJhm)
5
- [![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org)
6
- [![crates][crates]](https://crates.io/crates/tree-sitter-bash)
7
- [![npm][npm]](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
8
- [![pypi][pypi]](https://pypi.org/project/tree-sitter-bash)
9
-
10
- Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
11
-
12
- ## Development
13
-
14
- Install the dependencies:
15
-
16
- ```sh
17
- npm install
1
+ # @willbooster/tree-sitter-bash
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@willbooster/tree-sitter-bash.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
4
+ [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-bash.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-bash)
5
+ [![Test](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-bash/actions/workflows/test.yml)
6
+ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
7
+ [![wbfy](https://img.shields.io/badge/wbfy-20.20.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+
9
+ Bash grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), rewritten from
10
+ [tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash). The syntax trees differ from the
11
+ original grammar's.
12
+
13
+ - Heredoc bodies are parsed wherever bash reads them: from the newline that ends the line holding the `<<` operator,
14
+ in operator order. Any statement may follow the operator on that line (`cat <<EOF; echo done`), and several heredocs
15
+ may share a line. A `heredoc_body` node appears as an extra next to the command that opened it. A heredoc whose
16
+ delimiter does not fit the parser's 1 KiB scanner state is an `ERROR` rather than a guessed body.
17
+ - Redirections stay inside the command they belong to, in source order (`npm > out run x`), and a command may
18
+ consist of assignments and redirections only.
19
+ - `$((…))` is always an arithmetic expansion, including inside heredoc bodies; escaped `\$` and `` \` `` are literal.
20
+ - A newline is a statement terminator only where one may end a statement; elsewhere it is whitespace.
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ const Parser = require('tree-sitter');
26
+ const Bash = require('@willbooster/tree-sitter-bash');
27
+
28
+ const parser = new Parser();
29
+ parser.setLanguage(Bash);
30
+ const tree = parser.parse('cat <<EOF; echo done\n$(date)\nEOF\n');
18
31
  ```
19
32
 
20
- Build and run the tests:
33
+ ## Development
21
34
 
22
35
  ```sh
23
- npm run build
24
- npm run test
36
+ mise install
37
+ bun install --frozen-lockfile
38
+ bun run tree-sitter generate
39
+ bun run test
40
+ script/parse-examples
25
41
  ```
26
42
 
27
- Run the build and tests in watch mode:
28
-
29
- ```sh
30
- npm run test:watch
31
- ```
43
+ `script/parse-examples` clones real-world scripts into `examples/`, parses them with the local
44
+ tree-sitter CLI, and rewrites `script/known-failures.txt`, the list of files that fail to parse; its diff shows
45
+ regressions.
32
46
 
33
47
  ### References
34
48
 
35
49
  - [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)
36
50
  - [Shell command language specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)
37
- - [mvdnan/sh - a shell parser in go](https://github.com/mvdan/sh)
38
-
39
- [ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-bash/ci.yml?logo=github&label=CI
40
- [discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord
41
- [matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix
42
- [npm]: https://img.shields.io/npm/v/%40willbooster%2Ftree-sitter-bash?logo=npm
43
- [crates]: https://img.shields.io/crates/v/tree-sitter-bash?logo=rust
44
- [pypi]: https://img.shields.io/pypi/v/tree-sitter-bash?logo=pypi&logoColor=ffd242
51
+ - [mvdan/sh - a shell parser in go](https://github.com/mvdan/sh)
package/grammar.js CHANGED
@@ -10,7 +10,14 @@
10
10
  // expansion. `#` only starts a comment at the beginning of a word, so it is handled separately.
11
11
  const WORD_BREAKS = ['\\s', '|', '&', ';', '(', ')', '<', '>', '"', '\'', '`', '$', '\\\\'];
12
12
 
13
- const EXTGLOB_GROUP = /[?*+@]\((?:[^()\s\\]|\\.)*\)/;
13
+ // Extglob groups nest (`@(a|+([0-9]))`); a regular expression expresses a fixed depth, and three levels
14
+ // cover every nested pattern in the example corpora.
15
+ // The depth must match EXTGLOB_LITERAL_DEPTH in src/scanner.c.
16
+ const EXTGLOB_GROUP = extglobGroup('[?*+@]', 3);
17
+ const EXTGLOB_NEGATION = extglobGroup('!', 3);
18
+
19
+ // Text inside `${…}` and subscripts stops before `<(`/`>(`, so a process substitution there is parsed.
20
+ const SUBSCRIPT_TEXT = /([^\[\]$`"'\\<>]|[<>]+[^(\[\]$`"'\\<>]|\\.)+/;
14
21
 
15
22
  const PREC = {
16
23
  COMMA: -1,
@@ -60,6 +67,14 @@ module.exports = grammar({
60
67
  $._backtick_open,
61
68
  $._backtick_close,
62
69
  $._newline,
70
+ $._substitution_start,
71
+ $._substitution_end,
72
+ $._brace_substitution_end,
73
+ $._bracket_substitution_end,
74
+ $._extglob_prefix,
75
+ $._line_continuation,
76
+ $._brace_substitution_start,
77
+ $._bracket_substitution_start,
63
78
  $.__error_recovery,
64
79
  ],
65
80
 
@@ -68,6 +83,7 @@ module.exports = grammar({
68
83
  $.heredoc_body,
69
84
  /\s/,
70
85
  /\\\r?\n/,
86
+ $._line_continuation,
71
87
  ],
72
88
 
73
89
  supertypes: $ => [
@@ -152,8 +168,12 @@ module.exports = grammar({
152
168
  'coproc',
153
169
  choice(
154
170
  $.command,
155
- seq(field('name', $.word), $._compound_command),
156
- $._compound_command,
171
+ // Like bash (`coproc [NAME] command [redirections]`), a compound body takes redirections.
172
+ seq(
173
+ optional(field('name', $.word)),
174
+ $._compound_command,
175
+ repeat(field('redirect', $._redirect)),
176
+ ),
157
177
  ),
158
178
  )),
159
179
 
@@ -168,7 +188,7 @@ module.exports = grammar({
168
188
  seq(
169
189
  repeat($._command_prefix),
170
190
  field('name', $.command_name),
171
- repeat(choice(field('argument', $._word), field('redirect', $._redirect))),
191
+ repeat(choice(field('argument', $._argument), field('redirect', $._redirect))),
172
192
  ),
173
193
  repeat1($._command_prefix),
174
194
  )),
@@ -181,7 +201,7 @@ module.exports = grammar({
181
201
  repeat($._command_prefix),
182
202
  field('name', alias(choice('declare', 'typeset', 'export', 'readonly', 'local'), $.command_name)),
183
203
  repeat(choice(
184
- field('argument', choice($.variable_assignment, $._word)),
204
+ field('argument', choice($.variable_assignment, $._argument)),
185
205
  field('redirect', $._redirect),
186
206
  )),
187
207
  )),
@@ -189,9 +209,21 @@ module.exports = grammar({
189
209
  variable_assignment: $ => seq(
190
210
  field('name', choice($.variable_name, $.subscript)),
191
211
  field('operator', token.immediate(choice('=', '+='))),
192
- field('value', choice($._word, $.array, $._empty_value)),
212
+ field('value', choice($._argument, $._hash_value, $.array, $._empty_value)),
193
213
  ),
194
214
 
215
+ // A value is not at the start of a word, so a leading `#` is literal (`color=#fff`).
216
+ _hash_value: $ => choice(alias($._hash_word, $.word), alias($._hash_concatenation, $.concatenation)),
217
+
218
+ _hash_concatenation: $ => prec.right(seq(
219
+ alias($._hash_word, $.word),
220
+ repeat1(seq($._concat, choice(
221
+ $._word_part,
222
+ alias($._hash_word, $.word),
223
+ alias($._negated_extglob_pattern, $.extglob_pattern),
224
+ ))),
225
+ )),
226
+
195
227
  subscript: $ => seq(
196
228
  field('name', $.variable_name),
197
229
  token.immediate('['),
@@ -199,11 +231,18 @@ module.exports = grammar({
199
231
  ']',
200
232
  ),
201
233
 
234
+ // Like bash, the index extends to the matching `]`, so it may hold bracketed groups at any depth
235
+ // (`A[x[1[2]]]`), blanks, and newlines.
202
236
  _subscript_index: $ => repeat1(choice(
203
- alias(token.immediate(prec(1, /([^\]$`"'\\]|\\.)+/)), $.word),
237
+ alias(token.immediate(prec(1, SUBSCRIPT_TEXT)), $.word),
238
+ alias(token(prec(1, SUBSCRIPT_TEXT)), $.word),
239
+ alias($._angle_text, $.word),
204
240
  $._quoted_or_expansion,
241
+ $._subscript_group,
205
242
  )),
206
243
 
244
+ _subscript_group: $ => seq('[', optional($._subscript_index), ']'),
245
+
207
246
  // Word parts that carry their own delimiters, usable where a bare word would overrun a closing
208
247
  // `]` or `}`.
209
248
  _quoted_or_expansion: $ => choice(
@@ -215,11 +254,12 @@ module.exports = grammar({
215
254
  $.expansion,
216
255
  $.command_substitution,
217
256
  $.arithmetic_expansion,
257
+ $.process_substitution,
218
258
  ),
219
259
 
220
260
  array: $ => seq(
221
261
  token.immediate('('),
222
- repeat($._word),
262
+ repeat($._argument),
223
263
  ')',
224
264
  ),
225
265
 
@@ -232,7 +272,7 @@ module.exports = grammar({
232
272
  choice(
233
273
  seq(
234
274
  field('operator', choice('<', '>', '>>', '>|', '<>', '&>', '&>>', '<&', '>&')),
235
- field('destination', $._word),
275
+ field('destination', $._argument),
236
276
  ),
237
277
  field('operator', choice('<&-', '>&-')),
238
278
  ),
@@ -241,7 +281,7 @@ module.exports = grammar({
241
281
  herestring_redirect: $ => seq(
242
282
  optional(field('descriptor', $.file_descriptor)),
243
283
  field('operator', '<<<'),
244
- field('value', $._word),
284
+ field('value', $._argument),
245
285
  ),
246
286
 
247
287
  heredoc_redirect: $ => seq(
@@ -272,7 +312,9 @@ module.exports = grammar({
272
312
 
273
313
  arithmetic_command: $ => seq(
274
314
  '((',
315
+ $._substitution_start,
275
316
  optional($._arithmetic_expression),
317
+ $._substitution_end,
276
318
  '))',
277
319
  ),
278
320
 
@@ -290,13 +332,14 @@ module.exports = grammar({
290
332
 
291
333
  unary_test: $ => prec(PREC.UNARY, seq(
292
334
  field('operator', alias(choice(...TEST_UNARY_OPERATORS), $.test_operator)),
293
- field('operand', $._word),
335
+ field('operand', $._argument),
294
336
  )),
295
337
 
338
+ // The right side of `==`/`!=` is a pattern matched as if extglob were enabled.
296
339
  binary_test: $ => prec(PREC.COMPARE, seq(
297
340
  field('left', $._word),
298
341
  field('operator', alias(choice(...TEST_BINARY_OPERATORS), $.test_operator)),
299
- field('right', $._word),
342
+ field('right', $._argument),
300
343
  )),
301
344
 
302
345
  regex_test: $ => prec(PREC.COMPARE, seq(
@@ -344,19 +387,24 @@ module.exports = grammar({
344
387
  for_statement: $ => seq(
345
388
  field('keyword', choice('for', 'select')),
346
389
  field('variable', alias($.word, $.variable_name)),
347
- optional(seq('in', repeat(field('value', $._word)))),
348
- $._terminator,
390
+ // Without a word list the separator is optional (`for i do …`); a newline may precede `in`.
391
+ choice(
392
+ seq(optional($._newline), 'in', repeat(field('value', $._argument)), $._terminator),
393
+ optional($._terminator),
394
+ ),
349
395
  field('body', choice($.do_group, $.compound_statement)),
350
396
  ),
351
397
 
352
398
  c_style_for_statement: $ => seq(
353
399
  'for',
354
400
  '((',
401
+ $._substitution_start,
355
402
  field('initializer', optional($._arithmetic_expression)),
356
403
  ';',
357
404
  field('condition', optional($._arithmetic_expression)),
358
405
  ';',
359
406
  field('update', optional($._arithmetic_expression)),
407
+ $._substitution_end,
360
408
  '))',
361
409
  optional($._terminator),
362
410
  field('body', choice($.do_group, $.compound_statement)),
@@ -364,7 +412,7 @@ module.exports = grammar({
364
412
 
365
413
  case_statement: $ => seq(
366
414
  'case',
367
- field('value', $._word),
415
+ field('value', $._argument),
368
416
  'in',
369
417
  repeat($.case_item),
370
418
  optional(alias($._last_case_item, $.case_item)),
@@ -382,8 +430,8 @@ module.exports = grammar({
382
430
 
383
431
  _case_patterns: $ => seq(
384
432
  optional('('),
385
- field('pattern', $._word),
386
- repeat(seq('|', field('pattern', $._word))),
433
+ field('pattern', $._argument),
434
+ repeat(seq('|', field('pattern', $._argument))),
387
435
  ')',
388
436
  ),
389
437
 
@@ -399,13 +447,44 @@ module.exports = grammar({
399
447
 
400
448
  _word: $ => choice($._word_part, $.concatenation),
401
449
 
450
+ // Outside command position a leading `!(` is a negated extglob group rather than `!` negating a
451
+ // subshell.
452
+ _argument: $ => choice(
453
+ $._word,
454
+ alias($._negated_extglob_word, $.word),
455
+ alias($._negated_extglob_pattern, $.extglob_pattern),
456
+ alias($._negated_extglob_concatenation, $.concatenation),
457
+ ),
458
+
459
+ // A word led by a negated group (`!($x)b`, `!(a)$x`).
460
+ _negated_extglob_concatenation: $ => prec.right(seq(
461
+ choice(alias($._negated_extglob_pattern, $.extglob_pattern), alias($._negated_extglob_word, $.word)),
462
+ repeat1(seq($._concat, choice(
463
+ $._word_part,
464
+ alias($._hash_word, $.word),
465
+ alias($._negated_extglob_pattern, $.extglob_pattern),
466
+ ))),
467
+ )),
468
+
469
+ _negated_extglob_word: _ => token(prec(1, seq(
470
+ EXTGLOB_NEGATION,
471
+ repeat(choice(noneOf(...WORD_BREAKS), /\\[^\r\n]/, EXTGLOB_GROUP, EXTGLOB_NEGATION)),
472
+ ))),
473
+
402
474
  concatenation: $ => prec.right(seq(
403
475
  $._word_part,
404
- repeat1(seq($._concat, choice($._word_part, alias($._hash_word, $.word)))),
476
+ repeat1(seq($._concat, choice(
477
+ $._word_part,
478
+ alias($._hash_word, $.word),
479
+ alias($._negated_extglob_pattern, $.extglob_pattern),
480
+ ))),
405
481
  )),
406
482
 
407
483
  _word_part: $ => choice(
408
484
  $.word,
485
+ // Literal text that the scanner ends before a structured extglob group (`foo@($x)`).
486
+ alias($._extglob_prefix, $.word),
487
+ $.extglob_pattern,
409
488
  $.string,
410
489
  $.raw_string,
411
490
  $.ansi_c_string,
@@ -422,11 +501,34 @@ module.exports = grammar({
422
501
  // before `(` negates a subshell.
423
502
  word: _ => token(seq(
424
503
  choice(noneOf('#', ...WORD_BREAKS), /\\[^\r\n]/, EXTGLOB_GROUP),
425
- repeat(choice(noneOf(...WORD_BREAKS), /\\[^\r\n]/, EXTGLOB_GROUP, /!\((?:[^()\s\\]|\\.)*\)/)),
504
+ repeat(choice(noneOf(...WORD_BREAKS), /\\[^\r\n]/, EXTGLOB_GROUP, EXTGLOB_NEGATION)),
426
505
  )),
427
506
 
428
507
  // A `#` inside a word (`a$b#c`) is literal; only a `#` that begins a word starts a comment.
429
- _hash_word: _ => token(prec(1, seq('#', repeat(choice(noneOf(...WORD_BREAKS), /\\[^\r\n]/))))),
508
+ // A group whose alternatives hold expansions (`@($(cmd)|b)`); a literal group stays inside a
509
+ // `word`, whose token is longer than the group's opening token.
510
+ extglob_pattern: $ => seq(
511
+ field('operator', choice('?(', '*(', '+(', '@(')),
512
+ optional($._extglob_alternative),
513
+ repeat(seq('|', optional($._extglob_alternative))),
514
+ ')',
515
+ ),
516
+
517
+ _negated_extglob_pattern: $ => seq(
518
+ field('operator', '!('),
519
+ optional($._extglob_alternative),
520
+ repeat(seq('|', optional($._extglob_alternative))),
521
+ ')',
522
+ ),
523
+
524
+ // An alternative may hold unquoted blanks, so each of its words is an `alternative` field; like
525
+ // an assignment value, a word there may start with `#` (`@($x #b)`).
526
+ _extglob_alternative: $ => repeat1(field('alternative', choice($._argument, $._hash_value))),
527
+
528
+ _hash_word: _ => token(prec(1, seq(
529
+ '#',
530
+ repeat(choice(noneOf(...WORD_BREAKS), /\\[^\r\n]/, EXTGLOB_GROUP, EXTGLOB_NEGATION)),
531
+ ))),
430
532
 
431
533
  string: $ => seq(
432
534
  '"',
@@ -471,20 +573,33 @@ module.exports = grammar({
471
573
  alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), $.variable_name),
472
574
  alias(token.immediate(/[0-9]+|[*@?$_-]/), $.special_variable_name),
473
575
  alias(token.immediate(choice('#', '!')), $.special_variable_name),
474
- $._expansion_subscript,
576
+ alias($._expansion_subscript, $.subscript),
577
+ // A blank directly after `${` opens a function substitution, so these only take effect
578
+ // after a prefix (`${# y}`), which bash parses and rejects only when expanding.
579
+ alias(/[A-Za-z_][A-Za-z0-9_]*/, $.variable_name),
580
+ alias(/[0-9]+|[*@?$_-]/, $.special_variable_name),
475
581
  )),
476
582
  optional($._expansion_operation),
477
583
  ),
478
584
  field('parameter', alias(token.immediate(choice('#', '!')), $.special_variable_name)),
585
+ // Bash rejects `${}` and a body without a parameter (`${=1}`, `${"x"}`) only when expanding. A
586
+ // `$name` expansion is left out, since its `$` would tie with the special parameter in `${$}`.
587
+ repeat(field('argument', choice(
588
+ alias($._expansion_text, $.word),
589
+ alias($._angle_text, $.word),
590
+ $.string,
591
+ $.raw_string,
592
+ $.ansi_c_string,
593
+ $.translated_string,
594
+ $.command_substitution,
595
+ ))),
479
596
  ),
480
597
  '}',
481
598
  ),
482
599
 
483
600
  _expansion_subscript: $ => seq(
484
601
  field('name', alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), $.variable_name)),
485
- token.immediate('['),
486
- field('index', $._subscript_index),
487
- ']',
602
+ repeat1(seq(token.immediate('['), field('index', $._subscript_index), ']')),
488
603
  ),
489
604
 
490
605
  _expansion_operation: $ => choice(
@@ -496,25 +611,55 @@ module.exports = grammar({
496
611
  )),
497
612
  $.operator,
498
613
  )),
499
- repeat(field('argument', choice(alias($._expansion_text, $.word), $._quoted_or_expansion))),
614
+ repeat(field('argument', choice(
615
+ alias($._expansion_text, $.word),
616
+ alias($._angle_text, $.word),
617
+ $._quoted_or_expansion,
618
+ alias($._bare_dollar, $.word),
619
+ ))),
500
620
  ),
501
621
  field('operator', alias(token.immediate(choice('*', '@')), $.operator)),
622
+ // Text without an operator (`${x y}`) is rejected by bash only when expanding.
623
+ repeat1(field('argument', choice(
624
+ alias($._expansion_text, $.word),
625
+ alias($._angle_text, $.word),
626
+ $._quoted_or_expansion,
627
+ ))),
502
628
  ),
503
629
 
504
- _expansion_text: _ => token(prec(-1, /([^}$`"'\\]|\\(.|\r?\n))+/)),
630
+ _expansion_text: _ => token(prec(-1, /([^}$`"'\\<>]|[<>]+[^(}$`"'\\<>]|\\(.|\r?\n))+/)),
505
631
 
632
+ // A `<` or `>` that the text above cannot end with, e.g. before `}`. A single character, so that a
633
+ // run before `(` leaves its last `<`/`>` to open a process substitution (`${x:-a<<(b)}`).
634
+ _angle_text: _ => token(prec(-1, /[<>]/)),
635
+
636
+ // The zero-width substitution markers let the scanner track nesting, since a heredoc opened
637
+ // inside a substitution has its body read before the substitution ends.
506
638
  command_substitution: $ => choice(
507
- seq('$(', optional($._statements), ')'),
639
+ seq('$(', $._substitution_start, optional($._statements), $._substitution_end, ')'),
508
640
  // bash 5.3 runs `${ list; }` and `${| list; }` in the current shell.
509
- seq(alias(token(/\$\{[\s|]/), '${'), optional($._terminated_statements), '}'),
641
+ seq(
642
+ alias(token(/\$\{[\s|]/), '${'),
643
+ $._brace_substitution_start,
644
+ optional($._terminated_statements),
645
+ $._brace_substitution_end,
646
+ '}',
647
+ ),
510
648
  seq(alias($._backtick_open, '`'), optional($._statements), alias($._backtick_close, '`')),
511
649
  ),
512
650
 
513
- process_substitution: $ => seq(choice('<(', '>('), optional($._statements), ')'),
651
+ process_substitution: $ => seq(
652
+ choice('<(', '>('),
653
+ $._substitution_start,
654
+ optional($._statements),
655
+ $._substitution_end,
656
+ ')',
657
+ ),
514
658
 
659
+ // Arithmetic may span lines, and a heredoc body starts only after it, so it counts as nesting.
515
660
  arithmetic_expansion: $ => choice(
516
- seq('$((', optional($._arithmetic_expression), '))'),
517
- seq('$[', optional($._arithmetic_expression), ']'),
661
+ seq('$((', $._substitution_start, optional($._arithmetic_expression), $._substitution_end, '))'),
662
+ seq('$[', $._bracket_substitution_start, optional($._arithmetic_expression), $._bracket_substitution_end, ']'),
518
663
  ),
519
664
 
520
665
  // Arithmetic
@@ -535,7 +680,11 @@ module.exports = grammar({
535
680
  alias($._arithmetic_parenthesized, $.parenthesized_expression),
536
681
  ),
537
682
 
538
- number: _ => /(0[xX][0-9a-fA-F]+|[0-9]+#[0-9a-zA-Z@_]+|[0-9]+)/,
683
+ number: $ => choice(
684
+ /(0[xX][0-9a-fA-F]+|[0-9]+#[0-9a-zA-Z@_]+|[0-9]+)/,
685
+ // The digits of a based number may come from an expansion (`10#${x}`).
686
+ seq(/[0-9]+#/, choice($.simple_expansion, $.expansion)),
687
+ ),
539
688
 
540
689
  _arithmetic_variable: _ => /[A-Za-z_][A-Za-z0-9_]*/,
541
690
 
@@ -602,3 +751,22 @@ module.exports = grammar({
602
751
  function noneOf(...characters) {
603
752
  return new RegExp(`[^${characters.join('')}]`);
604
753
  }
754
+
755
+ /**
756
+ * A regular expression matching a literal extglob group opened by `prefix`, whose body may contain
757
+ * groups nested up to `depth` levels.
758
+ *
759
+ * @param {string} prefix
760
+ * @param {number} depth
761
+ * @returns {RegExp}
762
+ */
763
+ function extglobGroup(prefix, depth) {
764
+ // Quotes and expansions are left to `extglob_pattern`, which parses them. Blanks and newlines are
765
+ // part of a group, as bash's extglob lexer keeps them in the word.
766
+ const literal = '[^()\\\\$`\'"]';
767
+ let body = `(?:${literal}|\\\\.)`;
768
+ for (let level = 1; level < depth; level++) {
769
+ body = `(?:${literal}|\\\\.|[?*+@!]\\(${body}*\\))`;
770
+ }
771
+ return new RegExp(`${prefix}\\(${body}*\\)`);
772
+ }
package/package.json CHANGED
@@ -1,28 +1,21 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-bash",
3
- "version": "0.25.1",
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,14 +26,38 @@
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
- "eslint": "^9.12.0",
42
- "eslint-config-treesitter": "^1.0.2",
52
+ "@semantic-release/exec": "7.1.0",
53
+ "@willbooster/wb": "22.7.1",
54
+ "conventional-changelog-conventionalcommits": "9.3.1",
55
+ "lefthook": "2.1.14",
56
+ "node-gyp": "13.0.2",
43
57
  "prebuildify": "^6.0.1",
58
+ "semantic-release": "25.0.5",
59
+ "sort-package-json": "4.0.0",
60
+ "tree-sitter": "^0.25.0",
44
61
  "tree-sitter-cli": "^0.27.0"
45
62
  },
46
63
  "peerDependencies": {
@@ -51,11 +68,8 @@
51
68
  "optional": true
52
69
  }
53
70
  },
54
- "scripts": {
55
- "install": "node-gyp-build",
56
- "lint": "eslint grammar.js",
57
- "prestart": "tree-sitter build --wasm",
58
- "start": "tree-sitter playground",
59
- "test": "node --test bindings/node/*_test.js"
71
+ "publishConfig": {
72
+ "access": "public",
73
+ "registry": "https://registry.npmjs.org/"
60
74
  }
61
75
  }