@willbooster/tree-sitter-bash 4.0.1 → 4.0.2

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/grammar.js CHANGED
@@ -3,9 +3,12 @@
3
3
  * @license MIT
4
4
  */
5
5
 
6
- /// <reference types="tree-sitter-cli/dsl" />
7
6
  // @ts-check
8
7
 
8
+ // The CLI injects the DSL before loading this CommonJS grammar.
9
+ const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token } =
10
+ /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
11
+
9
12
  // Characters that end an unquoted word part: metacharacters, quotes, and characters that begin an
10
13
  // expansion. `#` only starts a comment at the beginning of a word, so it is handled separately. Like
11
14
  // bash, only a space, a tab, and a newline separate words; any other whitespace (CR, a no-break space)
@@ -108,48 +111,48 @@ const TEST_BINARY_OPERATORS = [
108
111
  module.exports = grammar({
109
112
  name: 'bash',
110
113
 
111
- externals: ($) => [
112
- $.heredoc_start,
113
- $._heredoc_body_start,
114
- $.heredoc_content,
115
- $.heredoc_end,
116
- $._heredoc_arrow,
117
- $._heredoc_arrow_dash,
118
- $._concat,
119
- $.file_descriptor,
120
- $.variable_name,
121
- $._bare_dollar,
122
- $._empty_value,
123
- $.regex,
124
- $.string_content,
125
- $._backtick_open,
126
- $._backtick_close,
127
- $._newline,
128
- $._substitution_start,
129
- $._substitution_end,
130
- $._brace_substitution_end,
131
- $._bracket_substitution_end,
132
- $._extglob_prefix,
133
- $._line_continuation,
134
- $._brace_substitution_start,
135
- $._bracket_substitution_start,
136
- $._regex_start,
137
- $._regex_concat,
138
- $._closer_line_raw_string_start,
139
- $._closer_line_ansi_c_string_start,
140
- $._closer_line_raw_string_content,
141
- $._closer_line_ansi_c_string_content,
142
- $._joined_comment,
143
- $._backtick_comment,
144
- $._backtick_comment_boundary,
145
- $.__error_recovery,
146
- $._command_substitution_start,
147
- $._arithmetic_substitution_start,
148
- $._arithmetic_cache_reset,
149
- $._timing_keyword,
150
- $._timing_option,
151
- $._timing_terminator,
152
- $._backquote_escape,
114
+ externals: () => [
115
+ sym('heredoc_start'),
116
+ sym('_heredoc_body_start'),
117
+ sym('heredoc_content'),
118
+ sym('heredoc_end'),
119
+ sym('_heredoc_arrow'),
120
+ sym('_heredoc_arrow_dash'),
121
+ sym('_concat'),
122
+ sym('file_descriptor'),
123
+ sym('variable_name'),
124
+ sym('_bare_dollar'),
125
+ sym('_empty_value'),
126
+ sym('regex'),
127
+ sym('string_content'),
128
+ sym('_backtick_open'),
129
+ sym('_backtick_close'),
130
+ sym('_newline'),
131
+ sym('_substitution_start'),
132
+ sym('_substitution_end'),
133
+ sym('_brace_substitution_end'),
134
+ sym('_bracket_substitution_end'),
135
+ sym('_extglob_prefix'),
136
+ sym('_line_continuation'),
137
+ sym('_brace_substitution_start'),
138
+ sym('_bracket_substitution_start'),
139
+ sym('_regex_start'),
140
+ sym('_regex_concat'),
141
+ sym('_closer_line_raw_string_start'),
142
+ sym('_closer_line_ansi_c_string_start'),
143
+ sym('_closer_line_raw_string_content'),
144
+ sym('_closer_line_ansi_c_string_content'),
145
+ sym('_joined_comment'),
146
+ sym('_backtick_comment'),
147
+ sym('_backtick_comment_boundary'),
148
+ sym('__error_recovery'),
149
+ sym('_command_substitution_start'),
150
+ sym('_arithmetic_substitution_start'),
151
+ sym('_arithmetic_cache_reset'),
152
+ sym('_timing_keyword'),
153
+ sym('_timing_option'),
154
+ sym('_timing_terminator'),
155
+ sym('_backquote_escape'),
153
156
  ],
154
157
 
155
158
  // Bash removes the backslash before `$` (and before `"` where the backquotes are inside double quotes)
@@ -160,9 +163,9 @@ module.exports = grammar({
160
163
  $.heredoc_body,
161
164
  /[ \t\n]/,
162
165
  /\\\n/,
163
- $._line_continuation,
164
- $._arithmetic_cache_reset,
165
- $._backquote_escape,
166
+ sym('_line_continuation'),
167
+ sym('_arithmetic_cache_reset'),
168
+ sym('_backquote_escape'),
166
169
  ],
167
170
 
168
171
  supertypes: ($) => [$._statement, $._arithmetic_expression],
@@ -182,7 +185,7 @@ module.exports = grammar({
182
185
  _terminated_statements: ($) => repeat1(seq($._statement, $._terminator)),
183
186
 
184
187
  // A newline is significant only where it can end a statement; elsewhere it is whitespace.
185
- _terminator: ($) => choice(';', '&', $._newline),
188
+ _terminator: () => choice(';', '&', sym('_newline')),
186
189
 
187
190
  _statement: ($) =>
188
191
  choice($._command_statement, $.pipeline, $.list, $.negated_command, $.timed_command, $.coproc_command),
@@ -219,9 +222,9 @@ module.exports = grammar({
219
222
  prec.right(
220
223
  2,
221
224
  seq(
222
- choice('time', alias($._timing_keyword, 'time')),
223
- optional(field('option', alias(choice('-p', $._timing_option), $.word))),
224
- optional(alias($._timing_terminator, $.word)),
225
+ choice('time', alias(sym('_timing_keyword'), 'time')),
226
+ optional(field('option', alias(choice('-p', sym('_timing_option')), $.word))),
227
+ optional(alias(sym('_timing_terminator'), $.word)),
225
228
  optional(choice($._command_statement, $.pipeline, $.negated_command))
226
229
  )
227
230
  ),
@@ -251,7 +254,7 @@ module.exports = grammar({
251
254
  field('name', $.command_name),
252
255
  repeat(
253
256
  seq(
254
- optional($._backtick_comment_boundary),
257
+ optional(sym('_backtick_comment_boundary')),
255
258
  choice(field('argument', $._argument), field('redirect', $._redirect))
256
259
  )
257
260
  )
@@ -262,7 +265,7 @@ module.exports = grammar({
262
265
 
263
266
  _command_prefix: ($) => choice(field('assignment', $.variable_assignment), field('redirect', $._redirect)),
264
267
 
265
- command_name: ($) => seq(optional($._backtick_comment_boundary), $._word),
268
+ command_name: ($) => seq(optional(sym('_backtick_comment_boundary')), $._word),
266
269
 
267
270
  declaration_command: ($) =>
268
271
  prec.left(
@@ -271,7 +274,7 @@ module.exports = grammar({
271
274
  field('name', alias(choice('declare', 'typeset', 'export', 'readonly', 'local'), $.command_name)),
272
275
  repeat(
273
276
  seq(
274
- optional($._backtick_comment_boundary),
277
+ optional(sym('_backtick_comment_boundary')),
275
278
  choice(field('argument', choice($.variable_assignment, $._argument)), field('redirect', $._redirect))
276
279
  )
277
280
  )
@@ -280,9 +283,9 @@ module.exports = grammar({
280
283
 
281
284
  variable_assignment: ($) =>
282
285
  seq(
283
- field('name', choice($.variable_name, $.subscript)),
286
+ field('name', choice(sym('variable_name'), $.subscript)),
284
287
  field('operator', token.immediate(choice('=', '+='))),
285
- field('value', choice($._argument, $._hash_value, $.array, $._empty_value))
288
+ field('value', choice($._argument, $._hash_value, $.array, sym('_empty_value')))
286
289
  ),
287
290
 
288
291
  // A value is not at the start of a word, so a leading `#` is literal (`color=#fff`).
@@ -294,7 +297,7 @@ module.exports = grammar({
294
297
  alias($._hash_word, $.word),
295
298
  repeat1(
296
299
  seq(
297
- $._concat,
300
+ sym('_concat'),
298
301
  choice($._word_part, alias($._hash_word, $.word), alias($._negated_extglob_pattern, $.extglob_pattern))
299
302
  )
300
303
  )
@@ -302,7 +305,7 @@ module.exports = grammar({
302
305
  ),
303
306
 
304
307
  subscript: ($) =>
305
- seq(field('name', $.variable_name), token.immediate('['), field('index', $._subscript_index), ']'),
308
+ seq(field('name', sym('variable_name')), token.immediate('['), field('index', $._subscript_index), ']'),
306
309
 
307
310
  // Like bash, the index extends to the matching `]`, so it may hold bracketed groups at any depth
308
311
  // (`A[x[1[2]]]`), blanks, and newlines.
@@ -340,7 +343,7 @@ module.exports = grammar({
340
343
 
341
344
  file_redirect: ($) =>
342
345
  seq(
343
- optional(field('descriptor', $.file_descriptor)),
346
+ optional(field('descriptor', sym('file_descriptor'))),
344
347
  choice(
345
348
  seq(
346
349
  field('operator', choice('<', '>', '>>', '>|', '<>', '&>', '&>>', '<&', '>&')),
@@ -351,24 +354,30 @@ module.exports = grammar({
351
354
  ),
352
355
 
353
356
  herestring_redirect: ($) =>
354
- seq(optional(field('descriptor', $.file_descriptor)), field('operator', '<<<'), field('value', $._argument)),
357
+ seq(optional(field('descriptor', sym('file_descriptor'))), field('operator', '<<<'), field('value', $._argument)),
355
358
 
356
- heredoc_redirect: ($) =>
359
+ heredoc_redirect: () =>
357
360
  seq(
358
- optional(field('descriptor', $.file_descriptor)),
359
- field('operator', choice(alias($._heredoc_arrow, '<<'), alias($._heredoc_arrow_dash, '<<-'))),
360
- field('delimiter', $.heredoc_start)
361
+ optional(field('descriptor', sym('file_descriptor'))),
362
+ field('operator', choice(alias(sym('_heredoc_arrow'), '<<'), alias(sym('_heredoc_arrow_dash'), '<<-'))),
363
+ field('delimiter', sym('heredoc_start'))
361
364
  ),
362
365
 
363
366
  // The scanner opens a body at the newline that ends the line holding its `<<` operator, so bodies
364
367
  // appear, in operator order, wherever that newline falls.
365
368
  heredoc_body: ($) =>
366
369
  seq(
367
- $._heredoc_body_start,
370
+ sym('_heredoc_body_start'),
368
371
  repeat(
369
- choice($.heredoc_content, $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
372
+ choice(
373
+ sym('heredoc_content'),
374
+ $.simple_expansion,
375
+ $.expansion,
376
+ $.command_substitution,
377
+ $.arithmetic_expansion
378
+ )
370
379
  ),
371
- $.heredoc_end
380
+ sym('heredoc_end')
372
381
  ),
373
382
 
374
383
  compound_statement: ($) => seq('{', optional($._terminated_statements), '}'),
@@ -376,7 +385,7 @@ module.exports = grammar({
376
385
  subshell: ($) => seq('(', optional($._statements), ')'),
377
386
 
378
387
  arithmetic_command: ($) =>
379
- seq('((', $._substitution_start, optional($._arithmetic_expression), $._substitution_end, '))'),
388
+ seq('((', sym('_substitution_start'), optional($._arithmetic_expression), sym('_substitution_end'), '))'),
380
389
 
381
390
  test_command: ($) => seq('[[', $._test_expression, ']]'),
382
391
 
@@ -386,15 +395,18 @@ module.exports = grammar({
386
395
  $.unary_test,
387
396
  $.binary_test,
388
397
  $.regex_test,
389
- alias($._test_negation, $.negated_test),
390
- alias($._test_logical, $.logical_test),
391
- alias($._test_parenthesized, $.parenthesized_test)
398
+ alias($._test_negation, sym('negated_test')),
399
+ alias($._test_logical, sym('logical_test')),
400
+ alias($._test_parenthesized, sym('parenthesized_test'))
392
401
  ),
393
402
 
394
403
  unary_test: ($) =>
395
404
  prec(
396
405
  PREC.UNARY,
397
- seq(field('operator', alias(choice(...TEST_UNARY_OPERATORS), $.test_operator)), field('operand', $._argument))
406
+ seq(
407
+ field('operator', alias(choice(...TEST_UNARY_OPERATORS), sym('test_operator'))),
408
+ field('operand', $._argument)
409
+ )
398
410
  ),
399
411
 
400
412
  // The right side of `==`/`!=` is a pattern matched as if extglob were enabled.
@@ -403,7 +415,7 @@ module.exports = grammar({
403
415
  PREC.COMPARE,
404
416
  seq(
405
417
  field('left', $._word),
406
- field('operator', alias(choice(...TEST_BINARY_OPERATORS), $.test_operator)),
418
+ field('operator', alias(choice(...TEST_BINARY_OPERATORS), sym('test_operator'))),
407
419
  field('right', $._argument)
408
420
  )
409
421
  ),
@@ -416,14 +428,14 @@ module.exports = grammar({
416
428
  seq(
417
429
  field('left', $._word),
418
430
  field('operator', '=~'),
419
- $._regex_start,
431
+ sym('_regex_start'),
420
432
  field('right', choice($._regex_part, alias($._regex_concatenation, $.concatenation)))
421
433
  )
422
434
  ),
423
435
 
424
- _regex_concatenation: ($) => prec.right(seq($._regex_part, repeat1(seq($._regex_concat, $._regex_part)))),
436
+ _regex_concatenation: ($) => prec.right(seq($._regex_part, repeat1(seq(sym('_regex_concat'), $._regex_part)))),
425
437
 
426
- _regex_part: ($) => choice($.regex, $._quoted_or_expansion),
438
+ _regex_part: ($) => choice(sym('regex'), $._quoted_or_expansion),
427
439
 
428
440
  _test_negation: ($) => prec(PREC.UNARY, seq('!', $._test_expression)),
429
441
 
@@ -463,20 +475,20 @@ module.exports = grammar({
463
475
  field('body', $.do_group)
464
476
  ),
465
477
 
466
- do_group: ($) => seq(optional($._backtick_comment_boundary), 'do', optional($._terminated_statements), 'done'),
478
+ do_group: ($) => seq(optional(sym('_backtick_comment_boundary')), 'do', optional($._terminated_statements), 'done'),
467
479
 
468
480
  for_statement: ($) =>
469
481
  seq(
470
482
  field('keyword', choice('for', 'select')),
471
- field('variable', alias($.word, $.variable_name)),
483
+ field('variable', alias($.word, sym('variable_name'))),
472
484
  // Without a word list the separator is optional (`for i do …`); a newline may precede `in`.
473
485
  choice(
474
486
  seq(
475
- optional($._newline),
476
- optional($._backtick_comment_boundary),
487
+ optional(sym('_newline')),
488
+ optional(sym('_backtick_comment_boundary')),
477
489
  'in',
478
- repeat(seq(optional($._backtick_comment_boundary), field('value', $._argument))),
479
- optional($._backtick_comment_boundary),
490
+ repeat(seq(optional(sym('_backtick_comment_boundary')), field('value', $._argument))),
491
+ optional(sym('_backtick_comment_boundary')),
480
492
  $._terminator
481
493
  ),
482
494
  optional($._terminator)
@@ -488,13 +500,13 @@ module.exports = grammar({
488
500
  seq(
489
501
  'for',
490
502
  '((',
491
- $._substitution_start,
503
+ sym('_substitution_start'),
492
504
  field('initializer', optional($._arithmetic_expression)),
493
505
  ';',
494
506
  field('condition', optional($._arithmetic_expression)),
495
507
  ';',
496
508
  field('update', optional($._arithmetic_expression)),
497
- $._substitution_end,
509
+ sym('_substitution_end'),
498
510
  '))',
499
511
  optional($._terminator),
500
512
  field('body', choice($.do_group, $.compound_statement))
@@ -504,7 +516,7 @@ module.exports = grammar({
504
516
  seq(
505
517
  'case',
506
518
  field('value', $._argument),
507
- optional($._backtick_comment_boundary),
519
+ optional(sym('_backtick_comment_boundary')),
508
520
  'in',
509
521
  repeat($.case_item),
510
522
  optional(alias($._last_case_item, $.case_item)),
@@ -519,7 +531,7 @@ module.exports = grammar({
519
531
 
520
532
  _case_patterns: ($) =>
521
533
  seq(
522
- optional($._backtick_comment_boundary),
534
+ optional(sym('_backtick_comment_boundary')),
523
535
  optional('('),
524
536
  field('pattern', $._argument),
525
537
  repeat(seq('|', field('pattern', $._argument))),
@@ -529,7 +541,7 @@ module.exports = grammar({
529
541
  function_definition: ($) =>
530
542
  seq(
531
543
  choice(seq('function', field('name', $.word), optional(seq('(', ')'))), seq(field('name', $.word), '(', ')')),
532
- optional($._backtick_comment_boundary),
544
+ optional(sym('_backtick_comment_boundary')),
533
545
  field('body', $._compound_command)
534
546
  ),
535
547
 
@@ -552,7 +564,7 @@ module.exports = grammar({
552
564
  choice(alias($._negated_extglob_pattern, $.extglob_pattern), alias($._negated_extglob_word, $.word)),
553
565
  repeat1(
554
566
  seq(
555
- $._concat,
567
+ sym('_concat'),
556
568
  choice($._word_part, alias($._hash_word, $.word), alias($._negated_extglob_pattern, $.extglob_pattern))
557
569
  )
558
570
  )
@@ -573,7 +585,7 @@ module.exports = grammar({
573
585
  $._word_part,
574
586
  repeat1(
575
587
  seq(
576
- $._concat,
588
+ sym('_concat'),
577
589
  choice($._word_part, alias($._hash_word, $.word), alias($._negated_extglob_pattern, $.extglob_pattern))
578
590
  )
579
591
  )
@@ -584,7 +596,7 @@ module.exports = grammar({
584
596
  choice(
585
597
  $.word,
586
598
  // Literal text that the scanner ends before a structured extglob group (`foo@($x)`).
587
- alias($._extglob_prefix, $.word),
599
+ alias(sym('_extglob_prefix'), $.word),
588
600
  $.extglob_pattern,
589
601
  $.string,
590
602
  $.raw_string,
@@ -595,7 +607,7 @@ module.exports = grammar({
595
607
  $.command_substitution,
596
608
  $.arithmetic_expansion,
597
609
  $.process_substitution,
598
- alias($._bare_dollar, $.word)
610
+ alias(sym('_bare_dollar'), $.word)
599
611
  ),
600
612
 
601
613
  // An extglob group (`@(a|b)`) is part of the word; `!(` only inside a word, since a leading `!`
@@ -638,7 +650,7 @@ module.exports = grammar({
638
650
  seq(
639
651
  '"',
640
652
  repeat(
641
- choice($.string_content, $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
653
+ choice(sym('string_content'), $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
642
654
  ),
643
655
  '"'
644
656
  ),
@@ -647,18 +659,22 @@ module.exports = grammar({
647
659
  // with its line continuations removed, even inside single quotes, and reads the bodies still queued
648
660
  // before that line right after it, even where it ends inside quotes; the scanner then splits the
649
661
  // quoted text around the continuations and the bodies.
650
- raw_string: ($) =>
662
+ raw_string: () =>
651
663
  choice(
652
664
  /'[^']*'/,
653
- seq($._closer_line_raw_string_start, repeat(alias($._closer_line_raw_string_content, $.string_content)), "'")
665
+ seq(
666
+ sym('_closer_line_raw_string_start'),
667
+ repeat(alias(sym('_closer_line_raw_string_content'), sym('string_content'))),
668
+ "'"
669
+ )
654
670
  ),
655
671
 
656
- ansi_c_string: ($) =>
672
+ ansi_c_string: () =>
657
673
  choice(
658
674
  /\$'([^'\\]|\\(.|\n))*'/,
659
675
  seq(
660
- $._closer_line_ansi_c_string_start,
661
- repeat(alias($._closer_line_ansi_c_string_content, $.string_content)),
676
+ sym('_closer_line_ansi_c_string_start'),
677
+ repeat(alias(sym('_closer_line_ansi_c_string_content'), sym('string_content'))),
662
678
  "'"
663
679
  )
664
680
  ),
@@ -667,17 +683,17 @@ module.exports = grammar({
667
683
  seq(
668
684
  '$"',
669
685
  repeat(
670
- choice($.string_content, $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
686
+ choice(sym('string_content'), $.simple_expansion, $.expansion, $.command_substitution, $.arithmetic_expansion)
671
687
  ),
672
688
  '"'
673
689
  ),
674
690
 
675
- simple_expansion: ($) =>
691
+ simple_expansion: () =>
676
692
  seq(
677
693
  '$',
678
694
  choice(
679
- alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), $.variable_name),
680
- alias(token.immediate(/[0-9*@#?$!_-]/), $.special_variable_name)
695
+ alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), sym('variable_name')),
696
+ alias(token.immediate(/[0-9*@#?$!_-]/), sym('special_variable_name'))
681
697
  )
682
698
  ),
683
699
 
@@ -688,19 +704,19 @@ module.exports = grammar({
688
704
  '${',
689
705
  choice(
690
706
  seq(
691
- optional(field('prefix', alias(token.immediate(choice('#', '!')), $.operator))),
707
+ optional(field('prefix', alias(token.immediate(choice('#', '!')), sym('operator')))),
692
708
  field(
693
709
  'parameter',
694
710
  choice(
695
- alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), $.variable_name),
696
- alias(token.immediate(/[0-9]+|[*@?$_-]/), $.special_variable_name),
697
- alias(token.immediate(choice('#', '!')), $.special_variable_name),
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')),
698
714
  alias($._expansion_subscript, $.subscript)
699
715
  )
700
716
  ),
701
717
  optional($._expansion_operation)
702
718
  ),
703
- field('parameter', alias(token.immediate(choice('#', '!')), $.special_variable_name)),
719
+ field('parameter', alias(token.immediate(choice('#', '!')), sym('special_variable_name'))),
704
720
  // Bash rejects `${}` and a body without a parameter (`${=1}`, `${"x"}`) only when expanding. A
705
721
  // `$name` expansion is left out, since its `$` would tie with the special parameter in `${$}`.
706
722
  repeat(
@@ -724,7 +740,7 @@ module.exports = grammar({
724
740
 
725
741
  _expansion_subscript: ($) =>
726
742
  seq(
727
- field('name', alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), $.variable_name)),
743
+ field('name', alias(token.immediate(/[A-Za-z_][A-Za-z0-9_]*/), sym('variable_name'))),
728
744
  repeat1(seq(token.immediate('['), field('index', $._subscript_index), ']'))
729
745
  ),
730
746
 
@@ -762,7 +778,7 @@ module.exports = grammar({
762
778
  '@'
763
779
  )
764
780
  ),
765
- $.operator
781
+ sym('operator')
766
782
  )
767
783
  ),
768
784
  repeat(
@@ -773,12 +789,12 @@ module.exports = grammar({
773
789
  alias($._blank_expansion_text, $.word),
774
790
  alias($._angle_text, $.word),
775
791
  $._quoted_or_expansion,
776
- alias($._bare_dollar, $.word)
792
+ alias(sym('_bare_dollar'), $.word)
777
793
  )
778
794
  )
779
795
  )
780
796
  ),
781
- field('operator', alias(token.immediate(choice('*', '@')), $.operator)),
797
+ field('operator', alias(token.immediate(choice('*', '@')), sym('operator'))),
782
798
  // Text without an operator (`${x y}`) is rejected by bash only when expanding.
783
799
  repeat1(
784
800
  field(
@@ -821,49 +837,61 @@ module.exports = grammar({
821
837
  command_substitution: ($) =>
822
838
  choice(
823
839
  seq(
824
- $._command_substitution_start,
840
+ sym('_command_substitution_start'),
825
841
  '$(',
826
- $._substitution_start,
842
+ sym('_substitution_start'),
827
843
  optional($._statements),
828
- $._substitution_end,
844
+ sym('_substitution_end'),
829
845
  ')'
830
846
  ),
831
847
  // bash 5.3 runs `${ list; }` and `${| list; }` in the current shell.
832
848
  seq(
833
849
  alias(token(/\$\{[ \t\n|]/), '${'),
834
- $._brace_substitution_start,
850
+ sym('_brace_substitution_start'),
835
851
  optional($._terminated_statements),
836
- $._brace_substitution_end,
852
+ sym('_brace_substitution_end'),
837
853
  '}'
838
854
  ),
839
- seq(alias($._backtick_open, '`'), optional($._statements), alias($._backtick_close, '`'))
855
+ seq(alias(sym('_backtick_open'), '`'), optional($._statements), alias(sym('_backtick_close'), '`'))
840
856
  ),
841
857
 
842
858
  process_substitution: ($) =>
843
- seq(choice('<(', '>('), $._substitution_start, optional($._statements), $._substitution_end, ')'),
859
+ seq(choice('<(', '>('), sym('_substitution_start'), optional($._statements), sym('_substitution_end'), ')'),
844
860
 
845
861
  // Arithmetic may span lines, and a heredoc body starts only after it, so it counts as nesting.
846
862
  arithmetic_expansion: ($) =>
847
863
  choice(
848
- seq($._arithmetic_substitution_start, '$((', optional($._arithmetic_expression), $._substitution_end, '))'),
849
- seq('$[', $._bracket_substitution_start, optional($._arithmetic_expression), $._bracket_substitution_end, ']')
864
+ seq(
865
+ sym('_arithmetic_substitution_start'),
866
+ '$((',
867
+ optional($._arithmetic_expression),
868
+ sym('_substitution_end'),
869
+ '))'
870
+ ),
871
+ seq(
872
+ '$[',
873
+ sym('_bracket_substitution_start'),
874
+ optional($._arithmetic_expression),
875
+ sym('_bracket_substitution_end'),
876
+ ']'
877
+ )
850
878
  ),
851
879
 
852
880
  _arithmetic_expression: ($) =>
853
881
  choice(
854
882
  $.number,
855
- alias($._arithmetic_variable, $.variable_name),
883
+ alias($._arithmetic_variable, sym('variable_name')),
856
884
  alias($._arithmetic_subscript, $.subscript),
857
885
  $.simple_expansion,
858
886
  $.expansion,
859
887
  $.command_substitution,
860
888
  $.arithmetic_expansion,
861
889
  $.string,
862
- alias($._arithmetic_unary, $.unary_expression),
863
- alias($._arithmetic_postfix, $.postfix_expression),
864
- alias($._arithmetic_binary, $.binary_expression),
865
- alias($._arithmetic_ternary, $.ternary_expression),
866
- alias($._arithmetic_parenthesized, $.parenthesized_expression)
890
+ alias($._arithmetic_unary, sym('unary_expression')),
891
+ alias($._arithmetic_postfix, sym('postfix_expression')),
892
+ alias($._arithmetic_binary, sym('binary_expression')),
893
+ alias($._arithmetic_ternary, sym('ternary_expression')),
894
+ alias($._arithmetic_parenthesized, sym('parenthesized_expression'))
867
895
  ),
868
896
 
869
897
  number: ($) =>
@@ -877,7 +905,7 @@ module.exports = grammar({
877
905
 
878
906
  _arithmetic_subscript: ($) =>
879
907
  seq(
880
- field('name', alias($._arithmetic_variable, $.variable_name)),
908
+ field('name', alias($._arithmetic_variable, sym('variable_name'))),
881
909
  token.immediate('['),
882
910
  field('index', $._arithmetic_expression),
883
911
  ']'
@@ -893,6 +921,7 @@ module.exports = grammar({
893
921
  prec(PREC.POSTFIX, seq($._arithmetic_expression, field('operator', choice('++', '--')))),
894
922
 
895
923
  _arithmetic_binary: ($) => {
924
+ /** @type {[number, import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral][]} */
896
925
  const table = [
897
926
  [PREC.COMMA, ','],
898
927
  [PREC.ASSIGN, choice('=', '+=', '-=', '*=', '/=', '%=', '**=', '<<=', '>>=', '&=', '^=', '|=')],
@@ -912,12 +941,12 @@ module.exports = grammar({
912
941
  ...table.map(([precedence, operator]) => {
913
942
  const rule = seq(
914
943
  field('left', $._arithmetic_expression),
915
- field('operator', /** @type {RuleOrLiteral} */ (operator)),
944
+ field('operator', operator),
916
945
  field('right', $._arithmetic_expression)
917
946
  );
918
947
  return precedence === PREC.ASSIGN || precedence === PREC.EXPONENT
919
- ? prec.right(/** @type {number} */ (precedence), rule)
920
- : prec.left(/** @type {number} */ (precedence), rule);
948
+ ? prec.right(precedence, rule)
949
+ : prec.left(precedence, rule);
921
950
  })
922
951
  );
923
952
  },
@@ -936,7 +965,7 @@ module.exports = grammar({
936
965
 
937
966
  _arithmetic_parenthesized: ($) => seq('(', $._arithmetic_expression, ')'),
938
967
 
939
- comment: ($) => choice(token(prec(-10, /#.*/)), $._joined_comment, $._backtick_comment),
968
+ comment: () => choice(token(prec(-10, /#.*/)), sym('_joined_comment'), sym('_backtick_comment')),
940
969
  },
941
970
  });
942
971
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-bash",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Bash grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -55,7 +55,6 @@
55
55
  "playwright": "1.63.0",
56
56
  "semantic-release": "25.0.9",
57
57
  "sort-package-json": "4.0.0",
58
- "tree-sitter-cli": "0.27.0",
59
58
  "typescript": "7.0.2",
60
59
  "vite": "8.3.2",
61
60
  "vitest": "5.0.3",
Binary file
package/tree-sitter.json CHANGED
@@ -18,7 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "metadata": {
21
- "version": "4.0.1",
21
+ "version": "4.0.2",
22
22
  "license": "MIT",
23
23
  "description": "Bash grammar for tree-sitter",
24
24
  "authors": [