tree-sitter-batch 0.3.2 → 0.4.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
@@ -48,8 +48,10 @@ Parsed tree:
48
48
  (echo_off)
49
49
  (comment)
50
50
  (setlocal_stmt)
51
- (variable_assignment)
52
- (variable_assignment)
51
+ (variable_assignment
52
+ (set_keyword) (variable_name) (assignment_value))
53
+ (variable_assignment
54
+ (set_keyword) (set_option) (variable_name) (assignment_value))
53
55
  (if_stmt
54
56
  (string)
55
57
  (parenthesized
package/grammar.js CHANGED
@@ -20,12 +20,13 @@ export default grammar({
20
20
  seq('::', /[^\r\n]*/),
21
21
  ))),
22
22
  label: () => token(seq(':', /[a-zA-Z_][a-zA-Z0-9_-]*/)),
23
- variable_assignment: () => prec(8, seq(
24
- optional('@'), kw('set'),
25
- optional(seq(/[ \t]+/, /\/[aApP]/)), /[ \t]+/,
23
+ variable_assignment: ($) => prec(8, seq(
24
+ optional('@'), alias(kw('set'), $.set_keyword),
25
+ optional(seq(/[ \t]+/, alias(/\/[aApP]/, $.set_option))),
26
+ /[ \t]+/,
26
27
  choice(
27
- seq('"', /[a-zA-Z_][a-zA-Z0-9_]*/, '=', optional(/[^"\r\n]*/), '"'),
28
- seq(/[a-zA-Z_][a-zA-Z0-9_]*/, '=', optional(/[^\r\n]*/)),
28
+ seq('"', alias(/[a-zA-Z_][a-zA-Z0-9_]*/, $.variable_name), '=', optional(alias(/[^"\r\n]+/, $.assignment_value)), '"'),
29
+ seq(alias(/[a-zA-Z_][a-zA-Z0-9_]*/, $.variable_name), '=', optional(alias(/[^\r\n]+/, $.assignment_value))),
29
30
  ),
30
31
  )),
31
32
  if_stmt: ($) => prec.right(8, seq(
@@ -84,7 +85,7 @@ export default grammar({
84
85
  for_options: () => token(prec(10, choice(ci('/d'), seq(ci('/r'), optional(seq(/[ \t]+/, /[^\s]+/))), ci('/l'), seq(ci('/f'), optional(seq(/[ \t]+/, '"', /[^"]*/, '"')))))),
85
86
  for_variable: () => token(seq('%%', optional('~'), /[a-zA-Z]/)),
86
87
  for_set: () => /[^)\r\n]+/,
87
- parenthesized: ($) => seq('(', repeat(choice(seq($._stmt, /\r?\n/), /\r?\n/)), ')'),
88
+ parenthesized: ($) => seq('(', repeat(choice(seq($._stmt, /\r?\n/), /\r?\n/)), optional($._stmt), ')'),
88
89
  redirect_stmt: ($) => prec.right(4, seq(choice($.cmd, $.parenthesized), $.redirection)),
89
90
  redirection: ($) => prec.right(seq(
90
91
  optional(/[0-2]/), $.redirect_op, $.redirect_target,
@@ -94,8 +95,8 @@ export default grammar({
94
95
  redirect_target: () => token(choice(ci('nul'), ci('con'), /[^\s|&><\r\n]+/)),
95
96
  pipe_stmt: ($) => prec.left(3, seq(choice($.cmd, $.parenthesized), '|', choice($.cmd, $.parenthesized))),
96
97
  cond_exec: ($) => choice(
97
- prec.left(2, seq(choice($.cmd, $.parenthesized), '&&', choice($.cmd, $.parenthesized))),
98
- prec.left(1, seq(choice($.cmd, $.parenthesized), '||', choice($.cmd, $.parenthesized))),
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
100
  ),
100
101
  variable_reference: () => token(choice(
101
102
  seq('%', /[a-zA-Z_][a-zA-Z0-9_]*/, '%'),
@@ -109,9 +110,10 @@ export default grammar({
109
110
  cmd: ($) => prec.right(5, seq(optional('@'), $.command_name, optional($.argument_list))),
110
111
  command_name: () => /[a-zA-Z_][a-zA-Z0-9_.-]*/,
111
112
  argument_list: ($) => prec.right(repeat1($._arg)),
112
- _arg: ($) => choice($.string, $.variable_reference, $.command_option, $.argument_value),
113
+ _arg: ($) => choice($.string, $.variable_reference, $.command_option, $.paren_expression, $.argument_value),
113
114
  command_option: () => token(seq('/', /[a-zA-Z_?][a-zA-Z0-9_:]*/)),
114
- argument_value: () => /[^\s|&><"\r\n%!][^\s|&><"\r\n]*/,
115
+ paren_expression: ($) => seq('(', repeat($._arg), ')'),
116
+ argument_value: () => /[^\s|&><"\r\n%!()][^\s|&><"\r\n()]*/,
115
117
  integer: () => /[0-9]+/,
116
118
  },
117
119
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-batch",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "A Windows Batch/CMD grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
@@ -8,7 +8,10 @@
8
8
  (label) @label
9
9
 
10
10
  ; Variable assignment
11
- (variable_assignment) @variable
11
+ (set_keyword) @keyword
12
+ (variable_name) @variable
13
+ (set_option) @constant
14
+ (assignment_value) @string
12
15
 
13
16
  ; IF/FOR/GOTO/CALL statements
14
17
  (if_stmt) @keyword
package/src/grammar.json CHANGED
@@ -250,15 +250,20 @@
250
250
  ]
251
251
  },
252
252
  {
253
- "type": "TOKEN",
253
+ "type": "ALIAS",
254
254
  "content": {
255
- "type": "PREC",
256
- "value": 10,
255
+ "type": "TOKEN",
257
256
  "content": {
258
- "type": "PATTERN",
259
- "value": "[sS][eE][tT]"
257
+ "type": "PREC",
258
+ "value": 10,
259
+ "content": {
260
+ "type": "PATTERN",
261
+ "value": "[sS][eE][tT]"
262
+ }
260
263
  }
261
- }
264
+ },
265
+ "named": true,
266
+ "value": "set_keyword"
262
267
  },
263
268
  {
264
269
  "type": "CHOICE",
@@ -271,8 +276,13 @@
271
276
  "value": "[ \\t]+"
272
277
  },
273
278
  {
274
- "type": "PATTERN",
275
- "value": "\\/[aApP]"
279
+ "type": "ALIAS",
280
+ "content": {
281
+ "type": "PATTERN",
282
+ "value": "\\/[aApP]"
283
+ },
284
+ "named": true,
285
+ "value": "set_option"
276
286
  }
277
287
  ]
278
288
  },
@@ -296,8 +306,13 @@
296
306
  "value": "\""
297
307
  },
298
308
  {
299
- "type": "PATTERN",
300
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
309
+ "type": "ALIAS",
310
+ "content": {
311
+ "type": "PATTERN",
312
+ "value": "[a-zA-Z_][a-zA-Z0-9_]*"
313
+ },
314
+ "named": true,
315
+ "value": "variable_name"
301
316
  },
302
317
  {
303
318
  "type": "STRING",
@@ -307,8 +322,13 @@
307
322
  "type": "CHOICE",
308
323
  "members": [
309
324
  {
310
- "type": "PATTERN",
311
- "value": "[^\"\\r\\n]*"
325
+ "type": "ALIAS",
326
+ "content": {
327
+ "type": "PATTERN",
328
+ "value": "[^\"\\r\\n]+"
329
+ },
330
+ "named": true,
331
+ "value": "assignment_value"
312
332
  },
313
333
  {
314
334
  "type": "BLANK"
@@ -325,8 +345,13 @@
325
345
  "type": "SEQ",
326
346
  "members": [
327
347
  {
328
- "type": "PATTERN",
329
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
348
+ "type": "ALIAS",
349
+ "content": {
350
+ "type": "PATTERN",
351
+ "value": "[a-zA-Z_][a-zA-Z0-9_]*"
352
+ },
353
+ "named": true,
354
+ "value": "variable_name"
330
355
  },
331
356
  {
332
357
  "type": "STRING",
@@ -336,8 +361,13 @@
336
361
  "type": "CHOICE",
337
362
  "members": [
338
363
  {
339
- "type": "PATTERN",
340
- "value": "[^\\r\\n]*"
364
+ "type": "ALIAS",
365
+ "content": {
366
+ "type": "PATTERN",
367
+ "value": "[^\\r\\n]+"
368
+ },
369
+ "named": true,
370
+ "value": "assignment_value"
341
371
  },
342
372
  {
343
373
  "type": "BLANK"
@@ -1228,6 +1258,18 @@
1228
1258
  ]
1229
1259
  }
1230
1260
  },
1261
+ {
1262
+ "type": "CHOICE",
1263
+ "members": [
1264
+ {
1265
+ "type": "SYMBOL",
1266
+ "name": "_stmt"
1267
+ },
1268
+ {
1269
+ "type": "BLANK"
1270
+ }
1271
+ ]
1272
+ },
1231
1273
  {
1232
1274
  "type": "STRING",
1233
1275
  "value": ")"
@@ -1422,13 +1464,17 @@
1422
1464
  "members": [
1423
1465
  {
1424
1466
  "type": "PREC_LEFT",
1425
- "value": 2,
1467
+ "value": 1,
1426
1468
  "content": {
1427
1469
  "type": "SEQ",
1428
1470
  "members": [
1429
1471
  {
1430
1472
  "type": "CHOICE",
1431
1473
  "members": [
1474
+ {
1475
+ "type": "SYMBOL",
1476
+ "name": "cond_exec"
1477
+ },
1432
1478
  {
1433
1479
  "type": "SYMBOL",
1434
1480
  "name": "cmd"
@@ -1468,6 +1514,10 @@
1468
1514
  {
1469
1515
  "type": "CHOICE",
1470
1516
  "members": [
1517
+ {
1518
+ "type": "SYMBOL",
1519
+ "name": "cond_exec"
1520
+ },
1471
1521
  {
1472
1522
  "type": "SYMBOL",
1473
1523
  "name": "cmd"
@@ -1709,6 +1759,10 @@
1709
1759
  "type": "SYMBOL",
1710
1760
  "name": "command_option"
1711
1761
  },
1762
+ {
1763
+ "type": "SYMBOL",
1764
+ "name": "paren_expression"
1765
+ },
1712
1766
  {
1713
1767
  "type": "SYMBOL",
1714
1768
  "name": "argument_value"
@@ -1731,9 +1785,29 @@
1731
1785
  ]
1732
1786
  }
1733
1787
  },
1788
+ "paren_expression": {
1789
+ "type": "SEQ",
1790
+ "members": [
1791
+ {
1792
+ "type": "STRING",
1793
+ "value": "("
1794
+ },
1795
+ {
1796
+ "type": "REPEAT",
1797
+ "content": {
1798
+ "type": "SYMBOL",
1799
+ "name": "_arg"
1800
+ }
1801
+ },
1802
+ {
1803
+ "type": "STRING",
1804
+ "value": ")"
1805
+ }
1806
+ ]
1807
+ },
1734
1808
  "argument_value": {
1735
1809
  "type": "PATTERN",
1736
- "value": "[^\\s|&><\"\\r\\n%!][^\\s|&><\"\\r\\n]*"
1810
+ "value": "[^\\s|&><\"\\r\\n%!()][^\\s|&><\"\\r\\n()]*"
1737
1811
  },
1738
1812
  "integer": {
1739
1813
  "type": "PATTERN",
@@ -15,6 +15,10 @@
15
15
  "type": "command_option",
16
16
  "named": true
17
17
  },
18
+ {
19
+ "type": "paren_expression",
20
+ "named": true
21
+ },
18
22
  {
19
23
  "type": "string",
20
24
  "named": true
@@ -76,6 +80,10 @@
76
80
  "type": "cmd",
77
81
  "named": true
78
82
  },
83
+ {
84
+ "type": "cond_exec",
85
+ "named": true
86
+ },
79
87
  {
80
88
  "type": "parenthesized",
81
89
  "named": true
@@ -211,6 +219,37 @@
211
219
  "named": true,
212
220
  "fields": {}
213
221
  },
222
+ {
223
+ "type": "paren_expression",
224
+ "named": true,
225
+ "fields": {},
226
+ "children": {
227
+ "multiple": true,
228
+ "required": false,
229
+ "types": [
230
+ {
231
+ "type": "argument_value",
232
+ "named": true
233
+ },
234
+ {
235
+ "type": "command_option",
236
+ "named": true
237
+ },
238
+ {
239
+ "type": "paren_expression",
240
+ "named": true
241
+ },
242
+ {
243
+ "type": "string",
244
+ "named": true
245
+ },
246
+ {
247
+ "type": "variable_reference",
248
+ "named": true
249
+ }
250
+ ]
251
+ }
252
+ },
214
253
  {
215
254
  "type": "parenthesized",
216
255
  "named": true,
@@ -431,7 +470,29 @@
431
470
  {
432
471
  "type": "variable_assignment",
433
472
  "named": true,
434
- "fields": {}
473
+ "fields": {},
474
+ "children": {
475
+ "multiple": true,
476
+ "required": true,
477
+ "types": [
478
+ {
479
+ "type": "assignment_value",
480
+ "named": true
481
+ },
482
+ {
483
+ "type": "set_keyword",
484
+ "named": true
485
+ },
486
+ {
487
+ "type": "set_option",
488
+ "named": true
489
+ },
490
+ {
491
+ "type": "variable_name",
492
+ "named": true
493
+ }
494
+ ]
495
+ }
435
496
  },
436
497
  {
437
498
  "type": "\"",
@@ -461,6 +522,10 @@
461
522
  "type": "argument_value",
462
523
  "named": true
463
524
  },
525
+ {
526
+ "type": "assignment_value",
527
+ "named": true
528
+ },
464
529
  {
465
530
  "type": "command_name",
466
531
  "named": true
@@ -501,10 +566,22 @@
501
566
  "type": "redirect_target",
502
567
  "named": true
503
568
  },
569
+ {
570
+ "type": "set_keyword",
571
+ "named": true
572
+ },
573
+ {
574
+ "type": "set_option",
575
+ "named": true
576
+ },
504
577
  {
505
578
  "type": "string",
506
579
  "named": true
507
580
  },
581
+ {
582
+ "type": "variable_name",
583
+ "named": true
584
+ },
508
585
  {
509
586
  "type": "variable_reference",
510
587
  "named": true