tree-sitter-batch 0.6.0 → 0.7.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/grammar.js CHANGED
@@ -23,13 +23,43 @@ export default grammar({
23
23
  label: () => token(seq(':', /[a-zA-Z_][a-zA-Z0-9_-]*/)),
24
24
  variable_assignment: ($) => prec(8, seq(
25
25
  optional('@'), alias(kw('set'), $.set_keyword),
26
- optional(seq(/[ \t]+/, alias(/\/[aApP]/, $.set_option))),
27
- /[ \t]+/,
28
26
  choice(
29
- seq('"', alias(/[a-zA-Z_][a-zA-Z0-9_]*/, $.variable_name), '=', optional(alias(/[^"\r\n]+/, $.assignment_value)), '"'),
30
- seq(alias(/[a-zA-Z_][a-zA-Z0-9_]*/, $.variable_name), '=', optional(alias(/[^\r\n]+/, $.assignment_value))),
27
+ $.arithmetic_assignment,
28
+ $.prompt_assignment,
29
+ seq(
30
+ /[ \t]+/,
31
+ choice(
32
+ seq('"', alias(/[a-zA-Z_][a-zA-Z0-9_()\[\]]*/, $.variable_name), '=', optional($.quoted_assignment_value), '"'),
33
+ seq(alias(/[a-zA-Z_][a-zA-Z0-9_()\[\]]*/, $.variable_name), '=', optional($.assignment_value)),
34
+ ),
35
+ ),
31
36
  ),
32
37
  )),
38
+ arithmetic_assignment: ($) => seq(
39
+ optional(/[ \t]+/), alias(token(prec(10, ci('/a'))), $.set_option),
40
+ optional(/[ \t]+/), $.arithmetic_expression,
41
+ ),
42
+ prompt_assignment: ($) => seq(
43
+ optional(/[ \t]+/), alias(token(prec(10, ci('/p'))), $.set_option),
44
+ optional(/[ \t]+/),
45
+ alias(/[a-zA-Z_][a-zA-Z0-9_()\[\]]*/, $.variable_name), '=', optional($.assignment_value),
46
+ ),
47
+ arithmetic_expression: () => token(choice(
48
+ seq('"', /[^"\r\n]*/, '"'),
49
+ /[^\r\n"]+/,
50
+ )),
51
+ assignment_value: ($) => prec.right(repeat1(choice(
52
+ $.variable_reference,
53
+ alias(/[^%!\r\n]+/, $.assignment_literal),
54
+ alias('%', $.assignment_literal),
55
+ alias('!', $.assignment_literal),
56
+ ))),
57
+ quoted_assignment_value: ($) => prec.right(repeat1(choice(
58
+ $.variable_reference,
59
+ alias(/[^%!"\r\n]+/, $.assignment_literal),
60
+ alias('%', $.assignment_literal),
61
+ alias('!', $.assignment_literal),
62
+ ))),
33
63
  if_stmt: ($) => prec.right(8, seq(
34
64
  optional('@'), kw('if'),
35
65
  optional(kw('not')),
@@ -85,7 +115,12 @@ export default grammar({
85
115
  )),
86
116
  for_options: () => token(prec(10, choice(ci('/d'), seq(ci('/r'), optional(seq(/[ \t]+/, /(%[^\s%]|[^\s%])+%?/))), ci('/l'), seq(ci('/f'), optional(seq(/[ \t]+/, '"', /[^"]*/, '"')))))),
87
117
  for_variable: () => token(seq('%%', optional('~'), /[a-zA-Z]/)),
88
- for_set: () => /[^)\r\n]+/,
118
+ for_set: ($) => prec.right(repeat1(choice(
119
+ $.variable_reference,
120
+ alias(/[^%!)\r\n]+/, $.for_set_literal),
121
+ alias('%', $.for_set_literal),
122
+ alias('!', $.for_set_literal),
123
+ ))),
89
124
  parenthesized: ($) => seq('(', repeat(choice(seq($._stmt, /\r?\n/), /\r?\n/)), optional($._stmt), ')'),
90
125
  redirect_stmt: ($) => prec.right(4, seq(choice($.call_stmt, $.cmd, $.parenthesized), $.redirection)),
91
126
  redirection: ($) => {
@@ -107,12 +142,12 @@ export default grammar({
107
142
  choice(...operand($)),
108
143
  )),
109
144
  variable_reference: () => token(choice(
110
- seq('%', /[a-zA-Z_][a-zA-Z0-9_]*/, '%'),
145
+ seq('%', /[a-zA-Z_][a-zA-Z0-9_()\[\]]*/, '%'),
111
146
  seq('%~', /[a-zA-Z]*/, /[0-9]/),
112
147
  seq('%', /[0-9]/),
113
148
  seq('%%', optional('~'), /[a-zA-Z]/),
114
149
  seq('!', /[a-zA-Z_][a-zA-Z0-9_]*/, '!'),
115
- seq('%', /[a-zA-Z_][a-zA-Z0-9_]*/, ':', /[^%]+/, '%'),
150
+ seq('%', /[a-zA-Z_][a-zA-Z0-9_()\[\]]*/, ':', /[^%]+/, '%'),
116
151
  )),
117
152
  string: () => token(seq('"', /[^"\r\n]*/, '"')),
118
153
  cmd: ($) => prec.right(5, seq(optional('@'), $.command_name, optional($.argument_list))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-batch",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A Windows Batch/CMD grammar for tree-sitter",
5
5
  "type": "module",
6
6
  "repository": {
@@ -11,7 +11,8 @@
11
11
  (set_keyword) @keyword
12
12
  (variable_name) @variable
13
13
  (set_option) @constant
14
- (assignment_value) @string
14
+ (assignment_literal) @string
15
+ (arithmetic_expression) @string
15
16
 
16
17
  ; IF/FOR/GOTO/CALL statements
17
18
  (if_stmt) @keyword
@@ -37,6 +38,9 @@
37
38
  ; Variables
38
39
  (variable_reference) @variable
39
40
 
41
+ ; FOR set literal content
42
+ (for_set_literal) @string
43
+
40
44
  ; FOR loop variables
41
45
  (for_variable) @variable.parameter
42
46
 
package/src/grammar.json CHANGED
@@ -273,118 +273,334 @@
273
273
  "type": "CHOICE",
274
274
  "members": [
275
275
  {
276
- "type": "SEQ",
277
- "members": [
278
- {
279
- "type": "PATTERN",
280
- "value": "[ \\t]+"
281
- },
282
- {
283
- "type": "ALIAS",
284
- "content": {
285
- "type": "PATTERN",
286
- "value": "\\/[aApP]"
287
- },
288
- "named": true,
289
- "value": "set_option"
290
- }
291
- ]
276
+ "type": "SYMBOL",
277
+ "name": "arithmetic_assignment"
292
278
  },
293
279
  {
294
- "type": "BLANK"
295
- }
296
- ]
297
- },
298
- {
299
- "type": "PATTERN",
300
- "value": "[ \\t]+"
301
- },
302
- {
303
- "type": "CHOICE",
304
- "members": [
280
+ "type": "SYMBOL",
281
+ "name": "prompt_assignment"
282
+ },
305
283
  {
306
284
  "type": "SEQ",
307
285
  "members": [
308
286
  {
309
- "type": "STRING",
310
- "value": "\""
311
- },
312
- {
313
- "type": "ALIAS",
314
- "content": {
315
- "type": "PATTERN",
316
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
317
- },
318
- "named": true,
319
- "value": "variable_name"
320
- },
321
- {
322
- "type": "STRING",
323
- "value": "="
287
+ "type": "PATTERN",
288
+ "value": "[ \\t]+"
324
289
  },
325
290
  {
326
291
  "type": "CHOICE",
327
292
  "members": [
328
293
  {
329
- "type": "ALIAS",
330
- "content": {
331
- "type": "PATTERN",
332
- "value": "[^\"\\r\\n]+"
333
- },
334
- "named": true,
335
- "value": "assignment_value"
294
+ "type": "SEQ",
295
+ "members": [
296
+ {
297
+ "type": "STRING",
298
+ "value": "\""
299
+ },
300
+ {
301
+ "type": "ALIAS",
302
+ "content": {
303
+ "type": "PATTERN",
304
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
305
+ },
306
+ "named": true,
307
+ "value": "variable_name"
308
+ },
309
+ {
310
+ "type": "STRING",
311
+ "value": "="
312
+ },
313
+ {
314
+ "type": "CHOICE",
315
+ "members": [
316
+ {
317
+ "type": "SYMBOL",
318
+ "name": "quoted_assignment_value"
319
+ },
320
+ {
321
+ "type": "BLANK"
322
+ }
323
+ ]
324
+ },
325
+ {
326
+ "type": "STRING",
327
+ "value": "\""
328
+ }
329
+ ]
336
330
  },
337
331
  {
338
- "type": "BLANK"
332
+ "type": "SEQ",
333
+ "members": [
334
+ {
335
+ "type": "ALIAS",
336
+ "content": {
337
+ "type": "PATTERN",
338
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
339
+ },
340
+ "named": true,
341
+ "value": "variable_name"
342
+ },
343
+ {
344
+ "type": "STRING",
345
+ "value": "="
346
+ },
347
+ {
348
+ "type": "CHOICE",
349
+ "members": [
350
+ {
351
+ "type": "SYMBOL",
352
+ "name": "assignment_value"
353
+ },
354
+ {
355
+ "type": "BLANK"
356
+ }
357
+ ]
358
+ }
359
+ ]
339
360
  }
340
361
  ]
341
- },
342
- {
343
- "type": "STRING",
344
- "value": "\""
345
362
  }
346
363
  ]
364
+ }
365
+ ]
366
+ }
367
+ ]
368
+ }
369
+ },
370
+ "arithmetic_assignment": {
371
+ "type": "SEQ",
372
+ "members": [
373
+ {
374
+ "type": "CHOICE",
375
+ "members": [
376
+ {
377
+ "type": "PATTERN",
378
+ "value": "[ \\t]+"
379
+ },
380
+ {
381
+ "type": "BLANK"
382
+ }
383
+ ]
384
+ },
385
+ {
386
+ "type": "ALIAS",
387
+ "content": {
388
+ "type": "TOKEN",
389
+ "content": {
390
+ "type": "PREC",
391
+ "value": 10,
392
+ "content": {
393
+ "type": "PATTERN",
394
+ "value": "\\/[aA]"
395
+ }
396
+ }
397
+ },
398
+ "named": true,
399
+ "value": "set_option"
400
+ },
401
+ {
402
+ "type": "CHOICE",
403
+ "members": [
404
+ {
405
+ "type": "PATTERN",
406
+ "value": "[ \\t]+"
407
+ },
408
+ {
409
+ "type": "BLANK"
410
+ }
411
+ ]
412
+ },
413
+ {
414
+ "type": "SYMBOL",
415
+ "name": "arithmetic_expression"
416
+ }
417
+ ]
418
+ },
419
+ "prompt_assignment": {
420
+ "type": "SEQ",
421
+ "members": [
422
+ {
423
+ "type": "CHOICE",
424
+ "members": [
425
+ {
426
+ "type": "PATTERN",
427
+ "value": "[ \\t]+"
428
+ },
429
+ {
430
+ "type": "BLANK"
431
+ }
432
+ ]
433
+ },
434
+ {
435
+ "type": "ALIAS",
436
+ "content": {
437
+ "type": "TOKEN",
438
+ "content": {
439
+ "type": "PREC",
440
+ "value": 10,
441
+ "content": {
442
+ "type": "PATTERN",
443
+ "value": "\\/[pP]"
444
+ }
445
+ }
446
+ },
447
+ "named": true,
448
+ "value": "set_option"
449
+ },
450
+ {
451
+ "type": "CHOICE",
452
+ "members": [
453
+ {
454
+ "type": "PATTERN",
455
+ "value": "[ \\t]+"
456
+ },
457
+ {
458
+ "type": "BLANK"
459
+ }
460
+ ]
461
+ },
462
+ {
463
+ "type": "ALIAS",
464
+ "content": {
465
+ "type": "PATTERN",
466
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
467
+ },
468
+ "named": true,
469
+ "value": "variable_name"
470
+ },
471
+ {
472
+ "type": "STRING",
473
+ "value": "="
474
+ },
475
+ {
476
+ "type": "CHOICE",
477
+ "members": [
478
+ {
479
+ "type": "SYMBOL",
480
+ "name": "assignment_value"
481
+ },
482
+ {
483
+ "type": "BLANK"
484
+ }
485
+ ]
486
+ }
487
+ ]
488
+ },
489
+ "arithmetic_expression": {
490
+ "type": "TOKEN",
491
+ "content": {
492
+ "type": "CHOICE",
493
+ "members": [
494
+ {
495
+ "type": "SEQ",
496
+ "members": [
497
+ {
498
+ "type": "STRING",
499
+ "value": "\""
347
500
  },
348
501
  {
349
- "type": "SEQ",
350
- "members": [
351
- {
352
- "type": "ALIAS",
353
- "content": {
354
- "type": "PATTERN",
355
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
356
- },
357
- "named": true,
358
- "value": "variable_name"
359
- },
360
- {
361
- "type": "STRING",
362
- "value": "="
363
- },
364
- {
365
- "type": "CHOICE",
366
- "members": [
367
- {
368
- "type": "ALIAS",
369
- "content": {
370
- "type": "PATTERN",
371
- "value": "[^\\r\\n]+"
372
- },
373
- "named": true,
374
- "value": "assignment_value"
375
- },
376
- {
377
- "type": "BLANK"
378
- }
379
- ]
380
- }
381
- ]
502
+ "type": "PATTERN",
503
+ "value": "[^\"\\r\\n]*"
504
+ },
505
+ {
506
+ "type": "STRING",
507
+ "value": "\""
382
508
  }
383
509
  ]
510
+ },
511
+ {
512
+ "type": "PATTERN",
513
+ "value": "[^\\r\\n\"]+"
384
514
  }
385
515
  ]
386
516
  }
387
517
  },
518
+ "assignment_value": {
519
+ "type": "PREC_RIGHT",
520
+ "value": 0,
521
+ "content": {
522
+ "type": "REPEAT1",
523
+ "content": {
524
+ "type": "CHOICE",
525
+ "members": [
526
+ {
527
+ "type": "SYMBOL",
528
+ "name": "variable_reference"
529
+ },
530
+ {
531
+ "type": "ALIAS",
532
+ "content": {
533
+ "type": "PATTERN",
534
+ "value": "[^%!\\r\\n]+"
535
+ },
536
+ "named": true,
537
+ "value": "assignment_literal"
538
+ },
539
+ {
540
+ "type": "ALIAS",
541
+ "content": {
542
+ "type": "STRING",
543
+ "value": "%"
544
+ },
545
+ "named": true,
546
+ "value": "assignment_literal"
547
+ },
548
+ {
549
+ "type": "ALIAS",
550
+ "content": {
551
+ "type": "STRING",
552
+ "value": "!"
553
+ },
554
+ "named": true,
555
+ "value": "assignment_literal"
556
+ }
557
+ ]
558
+ }
559
+ }
560
+ },
561
+ "quoted_assignment_value": {
562
+ "type": "PREC_RIGHT",
563
+ "value": 0,
564
+ "content": {
565
+ "type": "REPEAT1",
566
+ "content": {
567
+ "type": "CHOICE",
568
+ "members": [
569
+ {
570
+ "type": "SYMBOL",
571
+ "name": "variable_reference"
572
+ },
573
+ {
574
+ "type": "ALIAS",
575
+ "content": {
576
+ "type": "PATTERN",
577
+ "value": "[^%!\"\\r\\n]+"
578
+ },
579
+ "named": true,
580
+ "value": "assignment_literal"
581
+ },
582
+ {
583
+ "type": "ALIAS",
584
+ "content": {
585
+ "type": "STRING",
586
+ "value": "%"
587
+ },
588
+ "named": true,
589
+ "value": "assignment_literal"
590
+ },
591
+ {
592
+ "type": "ALIAS",
593
+ "content": {
594
+ "type": "STRING",
595
+ "value": "!"
596
+ },
597
+ "named": true,
598
+ "value": "assignment_literal"
599
+ }
600
+ ]
601
+ }
602
+ }
603
+ },
388
604
  "if_stmt": {
389
605
  "type": "PREC_RIGHT",
390
606
  "value": 8,
@@ -1227,8 +1443,47 @@
1227
1443
  }
1228
1444
  },
1229
1445
  "for_set": {
1230
- "type": "PATTERN",
1231
- "value": "[^)\\r\\n]+"
1446
+ "type": "PREC_RIGHT",
1447
+ "value": 0,
1448
+ "content": {
1449
+ "type": "REPEAT1",
1450
+ "content": {
1451
+ "type": "CHOICE",
1452
+ "members": [
1453
+ {
1454
+ "type": "SYMBOL",
1455
+ "name": "variable_reference"
1456
+ },
1457
+ {
1458
+ "type": "ALIAS",
1459
+ "content": {
1460
+ "type": "PATTERN",
1461
+ "value": "[^%!)\\r\\n]+"
1462
+ },
1463
+ "named": true,
1464
+ "value": "for_set_literal"
1465
+ },
1466
+ {
1467
+ "type": "ALIAS",
1468
+ "content": {
1469
+ "type": "STRING",
1470
+ "value": "%"
1471
+ },
1472
+ "named": true,
1473
+ "value": "for_set_literal"
1474
+ },
1475
+ {
1476
+ "type": "ALIAS",
1477
+ "content": {
1478
+ "type": "STRING",
1479
+ "value": "!"
1480
+ },
1481
+ "named": true,
1482
+ "value": "for_set_literal"
1483
+ }
1484
+ ]
1485
+ }
1486
+ }
1232
1487
  },
1233
1488
  "parenthesized": {
1234
1489
  "type": "SEQ",
@@ -1702,7 +1957,7 @@
1702
1957
  },
1703
1958
  {
1704
1959
  "type": "PATTERN",
1705
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
1960
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
1706
1961
  },
1707
1962
  {
1708
1963
  "type": "STRING",
@@ -1791,7 +2046,7 @@
1791
2046
  },
1792
2047
  {
1793
2048
  "type": "PATTERN",
1794
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
2049
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
1795
2050
  },
1796
2051
  {
1797
2052
  "type": "STRING",
@@ -1962,6 +2217,5 @@
1962
2217
  "precedences": [],
1963
2218
  "externals": [],
1964
2219
  "inline": [],
1965
- "supertypes": [],
1966
- "reserved": {}
1967
- }
2220
+ "supertypes": []
2221
+ }