@willbooster/tree-sitter-bash 1.1.3 → 1.1.4

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
@@ -37,7 +37,10 @@ script/parse-examples
37
37
 
38
38
  `bun run test` runs:
39
39
 
40
- - the corpus in `test/corpus`;
40
+ - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
41
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case at random,
42
+ reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and
43
+ `TREE_SITTER_EDITS` run other or more edits;
41
44
  - the Node.js binding test;
42
45
  - a check that real-world scripts cloned into `examples/` fail to parse exactly as listed in
43
46
  `script/known-failures.txt`. The first run clones them, which takes a few minutes. The example repositories are
@@ -52,6 +55,9 @@ script/parse-examples
52
55
  - a performance check (`test/unit/performance.test.ts`) that a 240 KB line parses in linear time, since consumers
53
56
  parse untrusted scripts.
54
57
 
58
+ CI also runs these tests on every platform that gets a prebuild, and fuzzes the parser with libFuzzer and sanitizers
59
+ (`.github/workflows/robustness.yml`).
60
+
55
61
  ### References
56
62
 
57
63
  - [Bash man page](http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_GRAMMAR)
package/grammar.js CHANGED
@@ -78,6 +78,13 @@ module.exports = grammar({
78
78
  $._line_continuation,
79
79
  $._brace_substitution_start,
80
80
  $._bracket_substitution_start,
81
+ $._regex_start,
82
+ $._regex_concat,
83
+ $._closer_line_raw_string_start,
84
+ $._closer_line_ansi_c_string_start,
85
+ $._closer_line_raw_string_content,
86
+ $._closer_line_ansi_c_string_content,
87
+ $._joined_comment,
81
88
  $.__error_recovery,
82
89
  ],
83
90
 
@@ -350,12 +357,19 @@ module.exports = grammar({
350
357
  field('right', $._argument),
351
358
  )),
352
359
 
360
+ // Like bash, the right side is one word whose parenthesized groups may hold blanks and
361
+ // metacharacters; its quotes and expansions are parsed as in any other word.
353
362
  regex_test: $ => prec(PREC.COMPARE, seq(
354
363
  field('left', $._word),
355
364
  field('operator', '=~'),
356
- field('right', $.regex),
365
+ $._regex_start,
366
+ field('right', choice($._regex_part, alias($._regex_concatenation, $.concatenation))),
357
367
  )),
358
368
 
369
+ _regex_concatenation: $ => prec.right(seq($._regex_part, repeat1(seq($._regex_concat, $._regex_part)))),
370
+
371
+ _regex_part: $ => choice($.regex, $._quoted_or_expansion),
372
+
359
373
  _test_negation: $ => prec(PREC.UNARY, seq('!', $._test_expression)),
360
374
 
361
375
  _test_logical: $ => choice(
@@ -551,9 +565,23 @@ module.exports = grammar({
551
565
  '"',
552
566
  ),
553
567
 
554
- raw_string: _ => /'[^']*'/,
568
+ // Where a heredoc inside `$( )` ends on a line that holds the `)`, bash reads the rest of that line
569
+ // with its line continuations removed, even inside single quotes, and reads the bodies still queued
570
+ // before that line right after it, even where it ends inside quotes; the scanner then splits the
571
+ // quoted text around the continuations and the bodies.
572
+ raw_string: $ => choice(
573
+ /'[^']*'/,
574
+ seq($._closer_line_raw_string_start, repeat(alias($._closer_line_raw_string_content, $.string_content)), '\''),
575
+ ),
555
576
 
556
- ansi_c_string: _ => /\$'([^'\\]|\\(.|\n))*'/,
577
+ ansi_c_string: $ => choice(
578
+ /\$'([^'\\]|\\(.|\n))*'/,
579
+ seq(
580
+ $._closer_line_ansi_c_string_start,
581
+ repeat(alias($._closer_line_ansi_c_string_content, $.string_content)),
582
+ '\'',
583
+ ),
584
+ ),
557
585
 
558
586
  translated_string: $ => seq('$"', repeat(choice(
559
587
  $.string_content,
@@ -754,7 +782,8 @@ module.exports = grammar({
754
782
 
755
783
  _arithmetic_parenthesized: $ => seq('(', $._arithmetic_expression, ')'),
756
784
 
757
- comment: _ => token(prec(-10, /#.*/)),
785
+ // A comment on such a line also continues past each line continuation.
786
+ comment: $ => choice(token(prec(-10, /#.*/)), $._joined_comment),
758
787
  },
759
788
  });
760
789
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-bash",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Bash grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
package/src/grammar.json CHANGED
@@ -1602,17 +1602,77 @@
1602
1602
  "value": "=~"
1603
1603
  }
1604
1604
  },
1605
+ {
1606
+ "type": "SYMBOL",
1607
+ "name": "_regex_start"
1608
+ },
1605
1609
  {
1606
1610
  "type": "FIELD",
1607
1611
  "name": "right",
1608
1612
  "content": {
1609
- "type": "SYMBOL",
1610
- "name": "regex"
1613
+ "type": "CHOICE",
1614
+ "members": [
1615
+ {
1616
+ "type": "SYMBOL",
1617
+ "name": "_regex_part"
1618
+ },
1619
+ {
1620
+ "type": "ALIAS",
1621
+ "content": {
1622
+ "type": "SYMBOL",
1623
+ "name": "_regex_concatenation"
1624
+ },
1625
+ "named": true,
1626
+ "value": "concatenation"
1627
+ }
1628
+ ]
1629
+ }
1630
+ }
1631
+ ]
1632
+ }
1633
+ },
1634
+ "_regex_concatenation": {
1635
+ "type": "PREC_RIGHT",
1636
+ "value": 0,
1637
+ "content": {
1638
+ "type": "SEQ",
1639
+ "members": [
1640
+ {
1641
+ "type": "SYMBOL",
1642
+ "name": "_regex_part"
1643
+ },
1644
+ {
1645
+ "type": "REPEAT1",
1646
+ "content": {
1647
+ "type": "SEQ",
1648
+ "members": [
1649
+ {
1650
+ "type": "SYMBOL",
1651
+ "name": "_regex_concat"
1652
+ },
1653
+ {
1654
+ "type": "SYMBOL",
1655
+ "name": "_regex_part"
1656
+ }
1657
+ ]
1611
1658
  }
1612
1659
  }
1613
1660
  ]
1614
1661
  }
1615
1662
  },
1663
+ "_regex_part": {
1664
+ "type": "CHOICE",
1665
+ "members": [
1666
+ {
1667
+ "type": "SYMBOL",
1668
+ "name": "regex"
1669
+ },
1670
+ {
1671
+ "type": "SYMBOL",
1672
+ "name": "_quoted_or_expansion"
1673
+ }
1674
+ ]
1675
+ },
1616
1676
  "_test_negation": {
1617
1677
  "type": "PREC",
1618
1678
  "value": 14,
@@ -2881,12 +2941,72 @@
2881
2941
  ]
2882
2942
  },
2883
2943
  "raw_string": {
2884
- "type": "PATTERN",
2885
- "value": "'[^']*'"
2944
+ "type": "CHOICE",
2945
+ "members": [
2946
+ {
2947
+ "type": "PATTERN",
2948
+ "value": "'[^']*'"
2949
+ },
2950
+ {
2951
+ "type": "SEQ",
2952
+ "members": [
2953
+ {
2954
+ "type": "SYMBOL",
2955
+ "name": "_closer_line_raw_string_start"
2956
+ },
2957
+ {
2958
+ "type": "REPEAT",
2959
+ "content": {
2960
+ "type": "ALIAS",
2961
+ "content": {
2962
+ "type": "SYMBOL",
2963
+ "name": "_closer_line_raw_string_content"
2964
+ },
2965
+ "named": true,
2966
+ "value": "string_content"
2967
+ }
2968
+ },
2969
+ {
2970
+ "type": "STRING",
2971
+ "value": "'"
2972
+ }
2973
+ ]
2974
+ }
2975
+ ]
2886
2976
  },
2887
2977
  "ansi_c_string": {
2888
- "type": "PATTERN",
2889
- "value": "\\$'([^'\\\\]|\\\\(.|\\n))*'"
2978
+ "type": "CHOICE",
2979
+ "members": [
2980
+ {
2981
+ "type": "PATTERN",
2982
+ "value": "\\$'([^'\\\\]|\\\\(.|\\n))*'"
2983
+ },
2984
+ {
2985
+ "type": "SEQ",
2986
+ "members": [
2987
+ {
2988
+ "type": "SYMBOL",
2989
+ "name": "_closer_line_ansi_c_string_start"
2990
+ },
2991
+ {
2992
+ "type": "REPEAT",
2993
+ "content": {
2994
+ "type": "ALIAS",
2995
+ "content": {
2996
+ "type": "SYMBOL",
2997
+ "name": "_closer_line_ansi_c_string_content"
2998
+ },
2999
+ "named": true,
3000
+ "value": "string_content"
3001
+ }
3002
+ },
3003
+ {
3004
+ "type": "STRING",
3005
+ "value": "'"
3006
+ }
3007
+ ]
3008
+ }
3009
+ ]
2890
3010
  },
2891
3011
  "translated_string": {
2892
3012
  "type": "SEQ",
@@ -4689,15 +4809,24 @@
4689
4809
  ]
4690
4810
  },
4691
4811
  "comment": {
4692
- "type": "TOKEN",
4693
- "content": {
4694
- "type": "PREC",
4695
- "value": -10,
4696
- "content": {
4697
- "type": "PATTERN",
4698
- "value": "#.*"
4812
+ "type": "CHOICE",
4813
+ "members": [
4814
+ {
4815
+ "type": "TOKEN",
4816
+ "content": {
4817
+ "type": "PREC",
4818
+ "value": -10,
4819
+ "content": {
4820
+ "type": "PATTERN",
4821
+ "value": "#.*"
4822
+ }
4823
+ }
4824
+ },
4825
+ {
4826
+ "type": "SYMBOL",
4827
+ "name": "_joined_comment"
4699
4828
  }
4700
- }
4829
+ ]
4701
4830
  }
4702
4831
  },
4703
4832
  "extras": [
@@ -4826,6 +4955,34 @@
4826
4955
  "type": "SYMBOL",
4827
4956
  "name": "_bracket_substitution_start"
4828
4957
  },
4958
+ {
4959
+ "type": "SYMBOL",
4960
+ "name": "_regex_start"
4961
+ },
4962
+ {
4963
+ "type": "SYMBOL",
4964
+ "name": "_regex_concat"
4965
+ },
4966
+ {
4967
+ "type": "SYMBOL",
4968
+ "name": "_closer_line_raw_string_start"
4969
+ },
4970
+ {
4971
+ "type": "SYMBOL",
4972
+ "name": "_closer_line_ansi_c_string_start"
4973
+ },
4974
+ {
4975
+ "type": "SYMBOL",
4976
+ "name": "_closer_line_raw_string_content"
4977
+ },
4978
+ {
4979
+ "type": "SYMBOL",
4980
+ "name": "_closer_line_ansi_c_string_content"
4981
+ },
4982
+ {
4983
+ "type": "SYMBOL",
4984
+ "name": "_joined_comment"
4985
+ },
4829
4986
  {
4830
4987
  "type": "SYMBOL",
4831
4988
  "name": "__error_recovery"
@@ -135,6 +135,21 @@
135
135
  }
136
136
  ]
137
137
  },
138
+ {
139
+ "type": "ansi_c_string",
140
+ "named": true,
141
+ "fields": {},
142
+ "children": {
143
+ "multiple": true,
144
+ "required": false,
145
+ "types": [
146
+ {
147
+ "type": "string_content",
148
+ "named": true
149
+ }
150
+ ]
151
+ }
152
+ },
138
153
  {
139
154
  "type": "arithmetic_command",
140
155
  "named": true,
@@ -888,6 +903,12 @@
888
903
  ]
889
904
  }
890
905
  },
906
+ {
907
+ "type": "comment",
908
+ "named": true,
909
+ "extra": true,
910
+ "fields": {}
911
+ },
891
912
  {
892
913
  "type": "compound_statement",
893
914
  "named": true,
@@ -939,6 +960,10 @@
939
960
  "type": "raw_string",
940
961
  "named": true
941
962
  },
963
+ {
964
+ "type": "regex",
965
+ "named": true
966
+ },
942
967
  {
943
968
  "type": "simple_expansion",
944
969
  "named": true
@@ -2398,6 +2423,21 @@
2398
2423
  ]
2399
2424
  }
2400
2425
  },
2426
+ {
2427
+ "type": "raw_string",
2428
+ "named": true,
2429
+ "fields": {},
2430
+ "children": {
2431
+ "multiple": true,
2432
+ "required": false,
2433
+ "types": [
2434
+ {
2435
+ "type": "string_content",
2436
+ "named": true
2437
+ }
2438
+ ]
2439
+ }
2440
+ },
2401
2441
  {
2402
2442
  "type": "redirected_statement",
2403
2443
  "named": true,
@@ -2540,9 +2580,49 @@
2540
2580
  "multiple": false,
2541
2581
  "required": true,
2542
2582
  "types": [
2583
+ {
2584
+ "type": "ansi_c_string",
2585
+ "named": true
2586
+ },
2587
+ {
2588
+ "type": "arithmetic_expansion",
2589
+ "named": true
2590
+ },
2591
+ {
2592
+ "type": "command_substitution",
2593
+ "named": true
2594
+ },
2595
+ {
2596
+ "type": "concatenation",
2597
+ "named": true
2598
+ },
2599
+ {
2600
+ "type": "expansion",
2601
+ "named": true
2602
+ },
2603
+ {
2604
+ "type": "process_substitution",
2605
+ "named": true
2606
+ },
2607
+ {
2608
+ "type": "raw_string",
2609
+ "named": true
2610
+ },
2543
2611
  {
2544
2612
  "type": "regex",
2545
2613
  "named": true
2614
+ },
2615
+ {
2616
+ "type": "simple_expansion",
2617
+ "named": true
2618
+ },
2619
+ {
2620
+ "type": "string",
2621
+ "named": true
2622
+ },
2623
+ {
2624
+ "type": "translated_string",
2625
+ "named": true
2546
2626
  }
2547
2627
  ]
2548
2628
  }
@@ -3209,6 +3289,10 @@
3209
3289
  "type": "&>>",
3210
3290
  "named": false
3211
3291
  },
3292
+ {
3293
+ "type": "'",
3294
+ "named": false
3295
+ },
3212
3296
  {
3213
3297
  "type": "(",
3214
3298
  "named": false
@@ -3429,19 +3513,10 @@
3429
3513
  "type": "`",
3430
3514
  "named": false
3431
3515
  },
3432
- {
3433
- "type": "ansi_c_string",
3434
- "named": true
3435
- },
3436
3516
  {
3437
3517
  "type": "case",
3438
3518
  "named": false
3439
3519
  },
3440
- {
3441
- "type": "comment",
3442
- "named": true,
3443
- "extra": true
3444
- },
3445
3520
  {
3446
3521
  "type": "coproc",
3447
3522
  "named": false
@@ -3506,10 +3581,6 @@
3506
3581
  "type": "operator",
3507
3582
  "named": true
3508
3583
  },
3509
- {
3510
- "type": "raw_string",
3511
- "named": true
3512
- },
3513
3584
  {
3514
3585
  "type": "regex",
3515
3586
  "named": true