tree-sitter-batch 0.4.1 → 0.5.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 +11 -0
- package/grammar.js +10 -4
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/tree-sitter-batch.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-batch.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-batch.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-batch.node +0 -0
- package/prebuilds/win32-arm64/tree-sitter-batch.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-batch.node +0 -0
- package/queries/highlights.scm +4 -0
- package/src/grammar.json +72 -1
- package/src/node-types.json +47 -0
- package/src/parser.c +1860 -1715
- package/tree-sitter-batch.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,17 @@ pip install tree-sitter-batch
|
|
|
100
100
|
import tree_sitter_batch "github.com/wharflab/tree-sitter-batch/bindings/go"
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
The root package also exports the bundled `queries/highlights.scm` via `go:embed`:
|
|
104
|
+
|
|
105
|
+
```go
|
|
106
|
+
import batch "github.com/wharflab/tree-sitter-batch"
|
|
107
|
+
|
|
108
|
+
lang := batch.GetLanguage()
|
|
109
|
+
query, _ := batch.GetHighlightsQuery()
|
|
110
|
+
// or access the raw .scm source:
|
|
111
|
+
// raw := batch.HighlightsQuery
|
|
112
|
+
```
|
|
113
|
+
|
|
103
114
|
## Usage
|
|
104
115
|
|
|
105
116
|
### Node.js
|
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(
|
|
99
|
-
prec.left(1, seq(choice(
|
|
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
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/queries/highlights.scm
CHANGED
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
; Commands
|
|
30
30
|
(command_name) @function
|
|
31
31
|
|
|
32
|
+
; CMD pseudo/dynamic environment variables
|
|
33
|
+
((variable_reference) @variable.builtin
|
|
34
|
+
(#match? @variable.builtin "(?i)^[%!](CD|ERRORLEVEL|DATE|TIME|RANDOM|CMDCMDLINE|CMDEXTVERSION|HIGHESTNUMANODENUMBER|__APPDIR__|__CD__)[%!]$"))
|
|
35
|
+
|
|
32
36
|
; Variables
|
|
33
37
|
(variable_reference) @variable
|
|
34
38
|
|
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",
|
package/src/node-types.json
CHANGED
|
@@ -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
|