tree-sitter-batch 0.4.1 → 0.4.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
@@ -1,5 +1,6 @@
1
1
  const ci = (word) => new RegExp(word.split('').map((c) => /[a-zA-Z]/.test(c) ? `[${c.toLowerCase()}${c.toUpperCase()}]` : c).join(''));
2
2
  const kw = (word) => token(prec(10, ci(word)));
3
+ const operand = ($) => [$.cond_exec, $.pipe_stmt, $.cmd, $.parenthesized];
3
4
 
4
5
  export default grammar({
5
6
  name: 'batch',
@@ -11,7 +12,7 @@ export default grammar({
11
12
  $.echo_off, $.comment, $.label, $.variable_assignment,
12
13
  $.if_stmt, $.goto_stmt, $.call_stmt, $.exit_stmt,
13
14
  $.setlocal_stmt, $.endlocal_stmt, $.for_stmt,
14
- $.redirect_stmt, $.pipe_stmt, $.cond_exec,
15
+ $.redirect_stmt, $.pipe_stmt, $.cond_exec, $.command_sep,
15
16
  $.parenthesized, $.cmd,
16
17
  ),
17
18
  echo_off: () => prec(10, seq('@', kw('echo'), choice(kw('off'), kw('on')))),
@@ -95,9 +96,14 @@ export default grammar({
95
96
  redirect_target: () => token(choice(ci('nul'), ci('con'), /[^\s|&><\r\n]+/)),
96
97
  pipe_stmt: ($) => prec.left(3, seq(choice($.cmd, $.parenthesized), '|', choice($.cmd, $.parenthesized))),
97
98
  cond_exec: ($) => choice(
98
- prec.left(1, seq(choice($.cond_exec, $.cmd, $.parenthesized), '&&', choice($.cmd, $.parenthesized))),
99
- prec.left(1, seq(choice($.cond_exec, $.cmd, $.parenthesized), '||', choice($.cmd, $.parenthesized))),
99
+ prec.left(1, seq(choice(...operand($)), '&&', choice($.cmd, $.parenthesized))),
100
+ prec.left(1, seq(choice(...operand($)), '||', choice($.cmd, $.parenthesized))),
100
101
  ),
102
+ command_sep: ($) => prec.left(0, seq(
103
+ choice($.command_sep, ...operand($)),
104
+ '&',
105
+ choice(...operand($)),
106
+ )),
101
107
  variable_reference: () => token(choice(
102
108
  seq('%', /[a-zA-Z_][a-zA-Z0-9_]*/, '%'),
103
109
  seq('%~', /[a-zA-Z]*/, /[0-9]/),
@@ -113,7 +119,7 @@ export default grammar({
113
119
  _arg: ($) => choice($.string, $.variable_reference, $.command_option, $.paren_expression, $.argument_value),
114
120
  command_option: () => token(seq('/', /[a-zA-Z_?][a-zA-Z0-9_:]*/)),
115
121
  paren_expression: ($) => seq('(', repeat($._arg), ')'),
116
- argument_value: () => /[^\s|&><"\r\n%!()][^\s|&><"\r\n()]*/,
122
+ argument_value: () => /(?:\^[&|<>^()]|[^\s|&><"\r\n%!()])(?:\^[&|<>^()]|[^\s|&><"\r\n()])*/,
117
123
  integer: () => /[0-9]+/,
118
124
  },
119
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-batch",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A Windows Batch/CMD grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
package/src/grammar.json CHANGED
@@ -87,6 +87,10 @@
87
87
  "type": "SYMBOL",
88
88
  "name": "cond_exec"
89
89
  },
90
+ {
91
+ "type": "SYMBOL",
92
+ "name": "command_sep"
93
+ },
90
94
  {
91
95
  "type": "SYMBOL",
92
96
  "name": "parenthesized"
@@ -1475,6 +1479,10 @@
1475
1479
  "type": "SYMBOL",
1476
1480
  "name": "cond_exec"
1477
1481
  },
1482
+ {
1483
+ "type": "SYMBOL",
1484
+ "name": "pipe_stmt"
1485
+ },
1478
1486
  {
1479
1487
  "type": "SYMBOL",
1480
1488
  "name": "cmd"
@@ -1518,6 +1526,10 @@
1518
1526
  "type": "SYMBOL",
1519
1527
  "name": "cond_exec"
1520
1528
  },
1529
+ {
1530
+ "type": "SYMBOL",
1531
+ "name": "pipe_stmt"
1532
+ },
1521
1533
  {
1522
1534
  "type": "SYMBOL",
1523
1535
  "name": "cmd"
@@ -1550,6 +1562,65 @@
1550
1562
  }
1551
1563
  ]
1552
1564
  },
1565
+ "command_sep": {
1566
+ "type": "PREC_LEFT",
1567
+ "value": 0,
1568
+ "content": {
1569
+ "type": "SEQ",
1570
+ "members": [
1571
+ {
1572
+ "type": "CHOICE",
1573
+ "members": [
1574
+ {
1575
+ "type": "SYMBOL",
1576
+ "name": "command_sep"
1577
+ },
1578
+ {
1579
+ "type": "SYMBOL",
1580
+ "name": "cond_exec"
1581
+ },
1582
+ {
1583
+ "type": "SYMBOL",
1584
+ "name": "pipe_stmt"
1585
+ },
1586
+ {
1587
+ "type": "SYMBOL",
1588
+ "name": "cmd"
1589
+ },
1590
+ {
1591
+ "type": "SYMBOL",
1592
+ "name": "parenthesized"
1593
+ }
1594
+ ]
1595
+ },
1596
+ {
1597
+ "type": "STRING",
1598
+ "value": "&"
1599
+ },
1600
+ {
1601
+ "type": "CHOICE",
1602
+ "members": [
1603
+ {
1604
+ "type": "SYMBOL",
1605
+ "name": "cond_exec"
1606
+ },
1607
+ {
1608
+ "type": "SYMBOL",
1609
+ "name": "pipe_stmt"
1610
+ },
1611
+ {
1612
+ "type": "SYMBOL",
1613
+ "name": "cmd"
1614
+ },
1615
+ {
1616
+ "type": "SYMBOL",
1617
+ "name": "parenthesized"
1618
+ }
1619
+ ]
1620
+ }
1621
+ ]
1622
+ }
1623
+ },
1553
1624
  "variable_reference": {
1554
1625
  "type": "TOKEN",
1555
1626
  "content": {
@@ -1807,7 +1878,7 @@
1807
1878
  },
1808
1879
  "argument_value": {
1809
1880
  "type": "PATTERN",
1810
- "value": "[^\\s|&><\"\\r\\n%!()][^\\s|&><\"\\r\\n()]*"
1881
+ "value": "(?:\\^[&|<>^()]|[^\\s|&><\"\\r\\n%!()])(?:\\^[&|<>^()]|[^\\s|&><\"\\r\\n()])*"
1811
1882
  },
1812
1883
  "integer": {
1813
1884
  "type": "PATTERN",
@@ -68,6 +68,37 @@
68
68
  ]
69
69
  }
70
70
  },
71
+ {
72
+ "type": "command_sep",
73
+ "named": true,
74
+ "fields": {},
75
+ "children": {
76
+ "multiple": true,
77
+ "required": true,
78
+ "types": [
79
+ {
80
+ "type": "cmd",
81
+ "named": true
82
+ },
83
+ {
84
+ "type": "command_sep",
85
+ "named": true
86
+ },
87
+ {
88
+ "type": "cond_exec",
89
+ "named": true
90
+ },
91
+ {
92
+ "type": "parenthesized",
93
+ "named": true
94
+ },
95
+ {
96
+ "type": "pipe_stmt",
97
+ "named": true
98
+ }
99
+ ]
100
+ }
101
+ },
71
102
  {
72
103
  "type": "cond_exec",
73
104
  "named": true,
@@ -87,6 +118,10 @@
87
118
  {
88
119
  "type": "parenthesized",
89
120
  "named": true
121
+ },
122
+ {
123
+ "type": "pipe_stmt",
124
+ "named": true
90
125
  }
91
126
  ]
92
127
  }
@@ -266,6 +301,10 @@
266
301
  "type": "cmd",
267
302
  "named": true
268
303
  },
304
+ {
305
+ "type": "command_sep",
306
+ "named": true
307
+ },
269
308
  {
270
309
  "type": "comment",
271
310
  "named": true
@@ -361,6 +400,10 @@
361
400
  "type": "cmd",
362
401
  "named": true
363
402
  },
403
+ {
404
+ "type": "command_sep",
405
+ "named": true
406
+ },
364
407
  {
365
408
  "type": "comment",
366
409
  "named": true
@@ -498,6 +541,10 @@
498
541
  "type": "\"",
499
542
  "named": false
500
543
  },
544
+ {
545
+ "type": "&",
546
+ "named": false
547
+ },
501
548
  {
502
549
  "type": "&&",
503
550
  "named": false