tree-sitter-batch 0.6.0 → 0.7.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
@@ -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(ci('/a'), $.set_option),
40
+ optional(/[ \t]+/), $.arithmetic_expression,
41
+ ),
42
+ prompt_assignment: ($) => seq(
43
+ optional(/[ \t]+/), alias(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.2",
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,320 @@
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": "PATTERN",
389
+ "value": "\\/[aA]"
390
+ },
391
+ "named": true,
392
+ "value": "set_option"
393
+ },
394
+ {
395
+ "type": "CHOICE",
396
+ "members": [
397
+ {
398
+ "type": "PATTERN",
399
+ "value": "[ \\t]+"
400
+ },
401
+ {
402
+ "type": "BLANK"
403
+ }
404
+ ]
405
+ },
406
+ {
407
+ "type": "SYMBOL",
408
+ "name": "arithmetic_expression"
409
+ }
410
+ ]
411
+ },
412
+ "prompt_assignment": {
413
+ "type": "SEQ",
414
+ "members": [
415
+ {
416
+ "type": "CHOICE",
417
+ "members": [
418
+ {
419
+ "type": "PATTERN",
420
+ "value": "[ \\t]+"
421
+ },
422
+ {
423
+ "type": "BLANK"
424
+ }
425
+ ]
426
+ },
427
+ {
428
+ "type": "ALIAS",
429
+ "content": {
430
+ "type": "PATTERN",
431
+ "value": "\\/[pP]"
432
+ },
433
+ "named": true,
434
+ "value": "set_option"
435
+ },
436
+ {
437
+ "type": "CHOICE",
438
+ "members": [
439
+ {
440
+ "type": "PATTERN",
441
+ "value": "[ \\t]+"
442
+ },
443
+ {
444
+ "type": "BLANK"
445
+ }
446
+ ]
447
+ },
448
+ {
449
+ "type": "ALIAS",
450
+ "content": {
451
+ "type": "PATTERN",
452
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
453
+ },
454
+ "named": true,
455
+ "value": "variable_name"
456
+ },
457
+ {
458
+ "type": "STRING",
459
+ "value": "="
460
+ },
461
+ {
462
+ "type": "CHOICE",
463
+ "members": [
464
+ {
465
+ "type": "SYMBOL",
466
+ "name": "assignment_value"
467
+ },
468
+ {
469
+ "type": "BLANK"
470
+ }
471
+ ]
472
+ }
473
+ ]
474
+ },
475
+ "arithmetic_expression": {
476
+ "type": "TOKEN",
477
+ "content": {
478
+ "type": "CHOICE",
479
+ "members": [
480
+ {
481
+ "type": "SEQ",
482
+ "members": [
483
+ {
484
+ "type": "STRING",
485
+ "value": "\""
347
486
  },
348
487
  {
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
- ]
488
+ "type": "PATTERN",
489
+ "value": "[^\"\\r\\n]*"
490
+ },
491
+ {
492
+ "type": "STRING",
493
+ "value": "\""
382
494
  }
383
495
  ]
496
+ },
497
+ {
498
+ "type": "PATTERN",
499
+ "value": "[^\\r\\n\"]+"
384
500
  }
385
501
  ]
386
502
  }
387
503
  },
504
+ "assignment_value": {
505
+ "type": "PREC_RIGHT",
506
+ "value": 0,
507
+ "content": {
508
+ "type": "REPEAT1",
509
+ "content": {
510
+ "type": "CHOICE",
511
+ "members": [
512
+ {
513
+ "type": "SYMBOL",
514
+ "name": "variable_reference"
515
+ },
516
+ {
517
+ "type": "ALIAS",
518
+ "content": {
519
+ "type": "PATTERN",
520
+ "value": "[^%!\\r\\n]+"
521
+ },
522
+ "named": true,
523
+ "value": "assignment_literal"
524
+ },
525
+ {
526
+ "type": "ALIAS",
527
+ "content": {
528
+ "type": "STRING",
529
+ "value": "%"
530
+ },
531
+ "named": true,
532
+ "value": "assignment_literal"
533
+ },
534
+ {
535
+ "type": "ALIAS",
536
+ "content": {
537
+ "type": "STRING",
538
+ "value": "!"
539
+ },
540
+ "named": true,
541
+ "value": "assignment_literal"
542
+ }
543
+ ]
544
+ }
545
+ }
546
+ },
547
+ "quoted_assignment_value": {
548
+ "type": "PREC_RIGHT",
549
+ "value": 0,
550
+ "content": {
551
+ "type": "REPEAT1",
552
+ "content": {
553
+ "type": "CHOICE",
554
+ "members": [
555
+ {
556
+ "type": "SYMBOL",
557
+ "name": "variable_reference"
558
+ },
559
+ {
560
+ "type": "ALIAS",
561
+ "content": {
562
+ "type": "PATTERN",
563
+ "value": "[^%!\"\\r\\n]+"
564
+ },
565
+ "named": true,
566
+ "value": "assignment_literal"
567
+ },
568
+ {
569
+ "type": "ALIAS",
570
+ "content": {
571
+ "type": "STRING",
572
+ "value": "%"
573
+ },
574
+ "named": true,
575
+ "value": "assignment_literal"
576
+ },
577
+ {
578
+ "type": "ALIAS",
579
+ "content": {
580
+ "type": "STRING",
581
+ "value": "!"
582
+ },
583
+ "named": true,
584
+ "value": "assignment_literal"
585
+ }
586
+ ]
587
+ }
588
+ }
589
+ },
388
590
  "if_stmt": {
389
591
  "type": "PREC_RIGHT",
390
592
  "value": 8,
@@ -1227,8 +1429,47 @@
1227
1429
  }
1228
1430
  },
1229
1431
  "for_set": {
1230
- "type": "PATTERN",
1231
- "value": "[^)\\r\\n]+"
1432
+ "type": "PREC_RIGHT",
1433
+ "value": 0,
1434
+ "content": {
1435
+ "type": "REPEAT1",
1436
+ "content": {
1437
+ "type": "CHOICE",
1438
+ "members": [
1439
+ {
1440
+ "type": "SYMBOL",
1441
+ "name": "variable_reference"
1442
+ },
1443
+ {
1444
+ "type": "ALIAS",
1445
+ "content": {
1446
+ "type": "PATTERN",
1447
+ "value": "[^%!)\\r\\n]+"
1448
+ },
1449
+ "named": true,
1450
+ "value": "for_set_literal"
1451
+ },
1452
+ {
1453
+ "type": "ALIAS",
1454
+ "content": {
1455
+ "type": "STRING",
1456
+ "value": "%"
1457
+ },
1458
+ "named": true,
1459
+ "value": "for_set_literal"
1460
+ },
1461
+ {
1462
+ "type": "ALIAS",
1463
+ "content": {
1464
+ "type": "STRING",
1465
+ "value": "!"
1466
+ },
1467
+ "named": true,
1468
+ "value": "for_set_literal"
1469
+ }
1470
+ ]
1471
+ }
1472
+ }
1232
1473
  },
1233
1474
  "parenthesized": {
1234
1475
  "type": "SEQ",
@@ -1702,7 +1943,7 @@
1702
1943
  },
1703
1944
  {
1704
1945
  "type": "PATTERN",
1705
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
1946
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
1706
1947
  },
1707
1948
  {
1708
1949
  "type": "STRING",
@@ -1791,7 +2032,7 @@
1791
2032
  },
1792
2033
  {
1793
2034
  "type": "PATTERN",
1794
- "value": "[a-zA-Z_][a-zA-Z0-9_]*"
2035
+ "value": "[a-zA-Z_][a-zA-Z0-9_()\\[\\]]*"
1795
2036
  },
1796
2037
  {
1797
2038
  "type": "STRING",
@@ -1962,6 +2203,5 @@
1962
2203
  "precedences": [],
1963
2204
  "externals": [],
1964
2205
  "inline": [],
1965
- "supertypes": [],
1966
- "reserved": {}
1967
- }
2206
+ "supertypes": []
2207
+ }