1{
2	"information_for_contributors": [
3		"This file has been converted from https://github.com/mmims/language-batchfile/blob/master/grammars/batchfile.cson",
4		"If you want to provide a fix or improvement, please create a pull request against the original repository.",
5		"Once accepted there, we are happy to receive an update request."
6	],
7	"version": "https://github.com/mmims/language-batchfile/commit/6154ae25a24e01ac9329e7bcf958e093cd8733a9",
8	"name": "Batch File",
9	"scopeName": "source.batchfile",
10	"injections": {
11		"L:meta.block.repeat.batchfile": {
12			"patterns": [
13				{
14					"include": "#repeatParameter"
15				}
16			]
17		}
18	},
19	"patterns": [
20		{
21			"include": "#commands"
22		},
23		{
24			"include": "#comments"
25		},
26		{
27			"include": "#constants"
28		},
29		{
30			"include": "#controls"
31		},
32		{
33			"include": "#escaped_characters"
34		},
35		{
36			"include": "#labels"
37		},
38		{
39			"include": "#numbers"
40		},
41		{
42			"include": "#operators"
43		},
44		{
45			"include": "#parens"
46		},
47		{
48			"include": "#strings"
49		},
50		{
51			"include": "#variables"
52		}
53	],
54	"repository": {
55		"commands": {
56			"patterns": [
57				{
58					"match": "(?<=^|[\\s@])(?i:adprep|append|arp|assoc|at|atmadm|attrib|auditpol|autochk|autoconv|autofmt|bcdboot|bcdedit|bdehdcfg|bitsadmin|bootcfg|brea|cacls|cd|certreq|certutil|change|chcp|chdir|chglogon|chgport|chgusr|chkdsk|chkntfs|choice|cipher|clip|cls|clscluadmin|cluster|cmd|cmdkey|cmstp|color|comp|compact|convert|copy|cprofile|cscript|csvde|date|dcdiag|dcgpofix|dcpromo|defra|del|dfscmd|dfsdiag|dfsrmig|diantz|dir|dirquota|diskcomp|diskcopy|diskpart|diskperf|diskraid|diskshadow|dispdiag|doin|dnscmd|doskey|driverquery|dsacls|dsadd|dsamain|dsdbutil|dsget|dsmgmt|dsmod|dsmove|dsquery|dsrm|edit|endlocal|eraseesentutl|eventcreate|eventquery|eventtriggers|evntcmd|expand|extract|fc|filescrn|find|findstr|finger|flattemp|fonde|forfiles|format|freedisk|fsutil|ftp|ftype|fveupdate|getmac|gettype|gpfixup|gpresult|gpupdate|graftabl|hashgen|hep|helpctr|hostname|icacls|iisreset|inuse|ipconfig|ipxroute|irftp|ismserv|jetpack|klist|ksetup|ktmutil|ktpass|label|ldifd|ldp|lodctr|logman|logoff|lpq|lpr|macfile|makecab|manage-bde|mapadmin|md|mkdir|mklink|mmc|mode|more|mount|mountvol|move|mqbup|mqsvc|mqtgsvc|msdt|msg|msiexec|msinfo32|mstsc|nbtstat|net computer|net group|net localgroup|net print|net session|net share|net start|net stop|net use|net user|net view|net|netcfg|netdiag|netdom|netsh|netstat|nfsadmin|nfsshare|nfsstat|nlb|nlbmgr|nltest|nslookup|ntackup|ntcmdprompt|ntdsutil|ntfrsutl|openfiles|pagefileconfig|path|pathping|pause|pbadmin|pentnt|perfmon|ping|pnpunatten|pnputil|popd|powercfg|powershell|powershell_ise|print|prncnfg|prndrvr|prnjobs|prnmngr|prnport|prnqctl|prompt|pubprn|pushd|pushprinterconnections|pwlauncher|qappsrv|qprocess|query|quser|qwinsta|rasdial|rcp|rd|rdpsign|regentc|recover|redircmp|redirusr|reg|regini|regsvr32|relog|ren|rename|rendom|repadmin|repair-bde|replace|reset session|rxec|risetup|rmdir|robocopy|route|rpcinfo|rpcping|rsh|runas|rundll32|rwinsta|sc|schtasks|scp|scwcmd|secedit|serverceipoptin|servrmanagercmd|serverweroptin|setspn|setx|sfc|sftp|shadow|shift|showmount|shutdown|sort|ssh|ssh-add|ssh-agent|ssh-keygen|ssh-keyscan|start|storrept|subst|sxstrace|ysocmgr|systeminfo|takeown|tapicfg|taskkill|tasklist|tcmsetup|telnet|tftp|time|timeout|title|tlntadmn|tpmvscmgr|tpmvscmgr|tacerpt|tracert|tree|tscon|tsdiscon|tsecimp|tskill|tsprof|type|typeperf|tzutil|uddiconfig|umount|unlodctr|ver|verifier|verif|vol|vssadmin|w32tm|waitfor|wbadmin|wdsutil|wecutil|wevtutil|where|whoami|winnt|winnt32|winpop|winrm|winrs|winsat|wlbs|wmic|wscript|wsl|xcopy)(?=$|\\s)",
59					"name": "keyword.command.batchfile"
60				},
61				{
62					"begin": "(?i)(?<=^|[\\s@])(echo)(?:(?=$|\\.|:)|\\s+(?:(on|off)(?=\\s*$))?)",
63					"beginCaptures": {
64						"1": {
65							"name": "keyword.command.batchfile"
66						},
67						"2": {
68							"name": "keyword.other.special-method.batchfile"
69						}
70					},
71					"end": "(?=$\\n|[&|><)])",
72					"patterns": [
73						{
74							"include": "#escaped_characters"
75						},
76						{
77							"include": "#variables"
78						},
79						{
80							"include": "#numbers"
81						},
82						{
83							"include": "#strings"
84						}
85					]
86				},
87				{
88					"match": "(?i)(?<=^|[\\s@])(setlocal)(?:\\s*$|\\s+(EnableExtensions|DisableExtensions|EnableDelayedExpansion|DisableDelayedExpansion)(?=\\s*$))",
89					"captures": {
90						"1": {
91							"name": "keyword.command.batchfile"
92						},
93						"2": {
94							"name": "keyword.other.special-method.batchfile"
95						}
96					}
97				},
98				{
99					"include": "#command_set"
100				}
101			]
102		},
103		"command_set": {
104			"patterns": [
105				{
106					"begin": "(?<=^|[\\s@])(?i:SET)(?=$|\\s)",
107					"beginCaptures": {
108						"0": {
109							"name": "keyword.command.batchfile"
110						}
111					},
112					"end": "(?=$\\n|[&|><)])",
113					"patterns": [
114						{
115							"include": "#command_set_inside"
116						}
117					]
118				}
119			]
120		},
121		"command_set_inside": {
122			"patterns": [
123				{
124					"include": "#escaped_characters"
125				},
126				{
127					"include": "#variables"
128				},
129				{
130					"include": "#numbers"
131				},
132				{
133					"include": "#parens"
134				},
135				{
136					"include": "#command_set_strings"
137				},
138				{
139					"include": "#strings"
140				},
141				{
142					"begin": "([^ ][^=]*)(=)",
143					"beginCaptures": {
144						"1": {
145							"name": "variable.other.readwrite.batchfile"
146						},
147						"2": {
148							"name": "keyword.operator.assignment.batchfile"
149						}
150					},
151					"end": "(?=$\\n|[&|><)])",
152					"patterns": [
153						{
154							"include": "#escaped_characters"
155						},
156						{
157							"include": "#variables"
158						},
159						{
160							"include": "#numbers"
161						},
162						{
163							"include": "#parens"
164						},
165						{
166							"include": "#strings"
167						}
168					]
169				},
170				{
171					"begin": "\\s+/[aA]\\s+",
172					"end": "(?=$\\n|[&|><)])",
173					"name": "meta.expression.set.batchfile",
174					"patterns": [
175						{
176							"begin": "\"",
177							"beginCaptures": {
178								"0": {
179									"name": "punctuation.definition.string.begin.batchfile"
180								}
181							},
182							"end": "\"",
183							"endCaptures": {
184								"0": {
185									"name": "punctuation.definition.string.end.batchfile"
186								}
187							},
188							"name": "string.quoted.double.batchfile",
189							"patterns": [
190								{
191									"include": "#command_set_inside_arithmetic"
192								},
193								{
194									"include": "#command_set_group"
195								},
196								{
197									"include": "#variables"
198								}
199							]
200						},
201						{
202							"include": "#command_set_inside_arithmetic"
203						},
204						{
205							"include": "#command_set_group"
206						}
207					]
208				},
209				{
210					"begin": "\\s+/[pP]\\s+",
211					"end": "(?=$\\n|[&|><)])",
212					"patterns": [
213						{
214							"include": "#command_set_strings"
215						},
216						{
217							"begin": "([^ ][^=]*)(=)",
218							"beginCaptures": {
219								"1": {
220									"name": "variable.other.readwrite.batchfile"
221								},
222								"2": {
223									"name": "keyword.operator.assignment.batchfile"
224								}
225							},
226							"end": "(?=$\\n|[&|><)])",
227							"name": "meta.prompt.set.batchfile",
228							"patterns": [
229								{
230									"include": "#strings"
231								}
232							]
233						}
234					]
235				}
236			]
237		},
238		"command_set_group": {
239			"patterns": [
240				{
241					"begin": "\\(",
242					"beginCaptures": {
243						"0": {
244							"name": "punctuation.section.group.begin.batchfile"
245						}
246					},
247					"end": "\\)",
248					"endCaptures": {
249						"0": {
250							"name": "punctuation.section.group.end.batchfile"
251						}
252					},
253					"patterns": [
254						{
255							"include": "#command_set_inside_arithmetic"
256						}
257					]
258				}
259			]
260		},
261		"command_set_inside_arithmetic": {
262			"patterns": [
263				{
264					"include": "#command_set_operators"
265				},
266				{
267					"include": "#numbers"
268				},
269				{
270					"match": ",",
271					"name": "punctuation.separator.batchfile"
272				}
273			]
274		},
275		"command_set_operators": {
276			"patterns": [
277				{
278					"match": "([^ ]*)(\\+\\=|\\-\\=|\\*\\=|\\/\\=|%%\\=|&\\=|\\|\\=|\\^\\=|<<\\=|>>\\=)",
279					"captures": {
280						"1": {
281							"name": "variable.other.readwrite.batchfile"
282						},
283						"2": {
284							"name": "keyword.operator.assignment.augmented.batchfile"
285						}
286					}
287				},
288				{
289					"match": "\\+|\\-|/|\\*|%%|\\||&|\\^|<<|>>|~",
290					"name": "keyword.operator.arithmetic.batchfile"
291				},
292				{
293					"match": "!",
294					"name": "keyword.operator.logical.batchfile"
295				},
296				{
297					"match": "([^ =]*)(=)",
298					"captures": {
299						"1": {
300							"name": "variable.other.readwrite.batchfile"
301						},
302						"2": {
303							"name": "keyword.operator.assignment.batchfile"
304						}
305					}
306				}
307			]
308		},
309		"command_set_strings": {
310			"patterns": [
311				{
312					"begin": "(\")\\s*([^ ][^=]*)(=)",
313					"beginCaptures": {
314						"1": {
315							"name": "punctuation.definition.string.begin.batchfile"
316						},
317						"2": {
318							"name": "variable.other.readwrite.batchfile"
319						},
320						"3": {
321							"name": "keyword.operator.assignment.batchfile"
322						}
323					},
324					"end": "\"",
325					"endCaptures": {
326						"0": {
327							"name": "punctuation.definition.string.end.batchfile"
328						}
329					},
330					"name": "string.quoted.double.batchfile",
331					"patterns": [
332						{
333							"include": "#variables"
334						},
335						{
336							"include": "#numbers"
337						},
338						{
339							"include": "#escaped_characters"
340						}
341					]
342				}
343			]
344		},
345		"comments": {
346			"patterns": [
347				{
348					"begin": "(?:^|(&))\\s*(?=((?::[+=,;: ])))",
349					"beginCaptures": {
350						"1": {
351							"name": "keyword.operator.conditional.batchfile"
352						}
353					},
354					"end": "\\n",
355					"patterns": [
356						{
357							"begin": "((?::[+=,;: ]))",
358							"beginCaptures": {
359								"1": {
360									"name": "punctuation.definition.comment.batchfile"
361								}
362							},
363							"end": "(?=\\n)",
364							"name": "comment.line.colon.batchfile"
365						}
366					]
367				},
368				{
369					"begin": "(?<=^|[\\s@])(?i)(REM)(\\.)",
370					"beginCaptures": {
371						"1": {
372							"name": "keyword.command.rem.batchfile"
373						},
374						"2": {
375							"name": "punctuation.separator.batchfile"
376						}
377					},
378					"end": "(?=$\\n|[&|><)])",
379					"name": "comment.line.rem.batchfile"
380				},
381				{
382					"begin": "(?<=^|[\\s@])(?i:rem)\\b",
383					"beginCaptures": {
384						"0": {
385							"name": "keyword.command.rem.batchfile"
386						}
387					},
388					"end": "\\n",
389					"name": "comment.line.rem.batchfile",
390					"patterns": [
391						{
392							"match": "[><|]",
393							"name": "invalid.illegal.unexpected-character.batchfile"
394						}
395					]
396				}
397			]
398		},
399		"constants": {
400			"patterns": [
401				{
402					"match": "\\b(?i:NUL)\\b",
403					"name": "constant.language.batchfile"
404				}
405			]
406		},
407		"controls": {
408			"patterns": [
409				{
410					"match": "(?i)(?<=^|\\s)(?:call|exit(?=$|\\s)|goto(?=$|\\s|:))",
411					"name": "keyword.control.statement.batchfile"
412				},
413				{
414					"match": "(?<=^|\\s)(?i)(if)\\s+(?:(not)\\s+)?(exist|defined|errorlevel|cmdextversion)(?=\\s)",
415					"captures": {
416						"1": {
417							"name": "keyword.control.conditional.batchfile"
418						},
419						"2": {
420							"name": "keyword.operator.logical.batchfile"
421						},
422						"3": {
423							"name": "keyword.other.special-method.batchfile"
424						}
425					}
426				},
427				{
428					"match": "(?<=^|\\s)(?i)(?:if|else)(?=$|\\s)",
429					"name": "keyword.control.conditional.batchfile"
430				},
431				{
432					"begin": "(?<=^|[\\s(&^])(?i)for(?=\\s)",
433					"beginCaptures": {
434						"0": {
435							"name": "keyword.control.repeat.batchfile"
436						}
437					},
438					"name": "meta.block.repeat.batchfile",
439					"end": "\\n",
440					"patterns": [
441						{
442							"begin": "(?<=[\\s^])(?i)in(?=\\s)",
443							"beginCaptures": {
444								"0": {
445									"name": "keyword.control.repeat.in.batchfile"
446								}
447							},
448							"end": "(?<=[\\s)^])(?i)do(?=\\s)|\\n",
449							"endCaptures": {
450								"0": {
451									"name": "keyword.control.repeat.do.batchfile"
452								}
453							},
454							"patterns": [
455								{
456									"include": "$self"
457								}
458							]
459						},
460						{
461							"include": "$self"
462						}
463					]
464				}
465			]
466		},
467		"escaped_characters": {
468			"patterns": [
469				{
470					"match": "%%|\\^\\^!|\\^(?=.)|\\^\\n",
471					"name": "constant.character.escape.batchfile"
472				}
473			]
474		},
475		"labels": {
476			"patterns": [
477				{
478					"match": "(?i)(?:^\\s*|(?<=call|goto)\\s*)(:)([^+=,;:\\s]\\S*)",
479					"captures": {
480						"1": {
481							"name": "punctuation.separator.batchfile"
482						},
483						"2": {
484							"name": "keyword.other.special-method.batchfile"
485						}
486					}
487				}
488			]
489		},
490		"numbers": {
491			"patterns": [
492				{
493					"match": "(?<=^|\\s|=)(0[xX][0-9A-Fa-f]*|[+-]?\\d+)(?=$|\\s|<|>)",
494					"name": "constant.numeric.batchfile"
495				}
496			]
497		},
498		"operators": {
499			"patterns": [
500				{
501					"match": "@(?=\\S)",
502					"name": "keyword.operator.at.batchfile"
503				},
504				{
505					"match": "(?<=\\s)(?i:EQU|NEQ|LSS|LEQ|GTR|GEQ)(?=\\s)|==",
506					"name": "keyword.operator.comparison.batchfile"
507				},
508				{
509					"match": "(?<=\\s)(?i)(NOT)(?=\\s)",
510					"name": "keyword.operator.logical.batchfile"
511				},
512				{
513					"match": "(?<!\\^)&&?|\\|\\|",
514					"name": "keyword.operator.conditional.batchfile"
515				},
516				{
517					"match": "(?<!\\^)\\|",
518					"name": "keyword.operator.pipe.batchfile"
519				},
520				{
521					"match": "<&?|>[&>]?",
522					"name": "keyword.operator.redirection.batchfile"
523				}
524			]
525		},
526		"parens": {
527			"patterns": [
528				{
529					"begin": "\\(",
530					"beginCaptures": {
531						"0": {
532							"name": "punctuation.section.group.begin.batchfile"
533						}
534					},
535					"end": "\\)",
536					"endCaptures": {
537						"0": {
538							"name": "punctuation.section.group.end.batchfile"
539						}
540					},
541					"name": "meta.group.batchfile",
542					"patterns": [
543						{
544							"match": ",|;",
545							"name": "punctuation.separator.batchfile"
546						},
547						{
548							"include": "$self"
549						}
550					]
551				}
552			]
553		},
554		"repeatParameter": {
555			"patterns": [
556				{
557					"match": "(%%)(?:(?i:~[fdpnxsatz]*(?:\\$PATH:)?)?[a-zA-Z])",
558					"captures": {
559						"1": {
560							"name": "punctuation.definition.variable.batchfile"
561						}
562					},
563					"name": "variable.parameter.repeat.batchfile"
564				}
565			]
566		},
567		"strings": {
568			"patterns": [
569				{
570					"begin": "\"",
571					"beginCaptures": {
572						"0": {
573							"name": "punctuation.definition.string.begin.batchfile"
574						}
575					},
576					"end": "(\")|(\\n)",
577					"endCaptures": {
578						"1": {
579							"name": "punctuation.definition.string.end.batchfile"
580						},
581						"2": {
582							"name": "invalid.illegal.newline.batchfile"
583						}
584					},
585					"name": "string.quoted.double.batchfile",
586					"patterns": [
587						{
588							"match": "%%",
589							"name": "constant.character.escape.batchfile"
590						},
591						{
592							"include": "#variables"
593						}
594					]
595				}
596			]
597		},
598		"variables": {
599			"patterns": [
600				{
601					"match": "(%)(?:(?i:~[fdpnxsatz]*(?:\\$PATH:)?)?\\d|\\*)",
602					"captures": {
603						"1": {
604							"name": "punctuation.definition.variable.batchfile"
605						}
606					},
607					"name": "variable.parameter.batchfile"
608				},
609				{
610					"include": "#variable"
611				},
612				{
613					"include": "#variable_delayed_expansion"
614				}
615			]
616		},
617		"variable": {
618			"patterns": [
619				{
620					"begin": "%(?=[^%]+%)",
621					"beginCaptures": {
622						"0": {
623							"name": "punctuation.definition.variable.begin.batchfile"
624						}
625					},
626					"end": "(%)|\\n",
627					"endCaptures": {
628						"1": {
629							"name": "punctuation.definition.variable.end.batchfile"
630						}
631					},
632					"name": "variable.other.readwrite.batchfile",
633					"patterns": [
634						{
635							"begin": ":~",
636							"beginCaptures": {
637								"0": {
638									"name": "punctuation.separator.batchfile"
639								}
640							},
641							"end": "(?=%|\\n)",
642							"name": "meta.variable.substring.batchfile",
643							"patterns": [
644								{
645									"include": "#variable_substring"
646								}
647							]
648						},
649						{
650							"begin": ":",
651							"beginCaptures": {
652								"0": {
653									"name": "punctuation.separator.batchfile"
654								}
655							},
656							"end": "(?=%|\\n)",
657							"name": "meta.variable.substitution.batchfile",
658							"patterns": [
659								{
660									"include": "#variable_replace"
661								},
662								{
663									"begin": "=",
664									"beginCaptures": {
665										"0": {
666											"name": "punctuation.separator.batchfile"
667										}
668									},
669									"end": "(?=%|\\n)",
670									"patterns": [
671										{
672											"include": "#variable_delayed_expansion"
673										},
674										{
675											"match": "[^%]+",
676											"name": "string.unquoted.batchfile"
677										}
678									]
679								}
680							]
681						}
682					]
683				}
684			]
685		},
686		"variable_delayed_expansion": {
687			"patterns": [
688				{
689					"begin": "!(?=[^!]+!)",
690					"beginCaptures": {
691						"0": {
692							"name": "punctuation.definition.variable.begin.batchfile"
693						}
694					},
695					"end": "(!)|\\n",
696					"endCaptures": {
697						"1": {
698							"name": "punctuation.definition.variable.end.batchfile"
699						}
700					},
701					"name": "variable.other.readwrite.batchfile",
702					"patterns": [
703						{
704							"begin": ":~",
705							"beginCaptures": {
706								"0": {
707									"name": "punctuation.separator.batchfile"
708								}
709							},
710							"end": "(?=!|\\n)",
711							"name": "meta.variable.substring.batchfile",
712							"patterns": [
713								{
714									"include": "#variable_substring"
715								}
716							]
717						},
718						{
719							"begin": ":",
720							"beginCaptures": {
721								"0": {
722									"name": "punctuation.separator.batchfile"
723								}
724							},
725							"end": "(?=!|\\n)",
726							"name": "meta.variable.substitution.batchfile",
727							"patterns": [
728								{
729									"include": "#escaped_characters"
730								},
731								{
732									"include": "#variable_replace"
733								},
734								{
735									"include": "#variable"
736								},
737								{
738									"begin": "=",
739									"beginCaptures": {
740										"0": {
741											"name": "punctuation.separator.batchfile"
742										}
743									},
744									"end": "(?=!|\\n)",
745									"patterns": [
746										{
747											"include": "#variable"
748										},
749										{
750											"match": "[^!]+",
751											"name": "string.unquoted.batchfile"
752										}
753									]
754								}
755							]
756						}
757					]
758				}
759			]
760		},
761		"variable_replace": {
762			"patterns": [
763				{
764					"match": "[^=%!\\n]+",
765					"name": "string.unquoted.batchfile"
766				}
767			]
768		},
769		"variable_substring": {
770			"patterns": [
771				{
772					"match": "([+-]?\\d+)(?:(,)([+-]?\\d+))?",
773					"captures": {
774						"1": {
775							"name": "constant.numeric.batchfile"
776						},
777						"2": {
778							"name": "punctuation.separator.batchfile"
779						},
780						"3": {
781							"name": "constant.numeric.batchfile"
782						}
783					}
784				}
785			]
786		}
787	}
788}