Skip to content

Commit eab5b06

Browse files
committed
Add support for Batch (Fix #398)
1 parent 792e35c commit eab5b06

File tree

7 files changed

+258
-0
lines changed

7 files changed

+258
-0
lines changed

components.js

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ var components = {
9797
"title": "BASIC",
9898
"owner": "Golmote"
9999
},
100+
"batch": {
101+
"title": "Batch",
102+
"owner": "Golmote"
103+
},
100104
"bison": {
101105
"title": "Bison",
102106
"require": "c",

components/prism-batch.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
(function (Prism) {
2+
var variable = /%%?[~:\w]+%?|!\S+!/;
3+
var parameter = {
4+
pattern: /\/[a-z?]+(?=[ :]|$):?|-[a-z]\b|--[a-z-]+\b/im,
5+
alias: 'attr-name',
6+
inside: {
7+
'punctuation': /:/
8+
}
9+
};
10+
var string = /"[^"]*"/;
11+
var number = /(?:\b|-)\d+\b/;
12+
13+
Prism.languages.batch = {
14+
'comment': [
15+
/^::.*/m,
16+
{
17+
pattern: /((?:^|[&(])[ \t]*)rem\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
18+
lookbehind: true
19+
}
20+
],
21+
'label': {
22+
pattern: /^:.*/m,
23+
alias: 'property'
24+
},
25+
'command': [
26+
{
27+
// FOR command
28+
pattern: /((?:^|[&(])[ \t]*)for(?: ?\/[a-z?](?:[ :](?:"[^"]*"|\S+))?)* \S+ in \([^)]+\) do/im,
29+
lookbehind: true,
30+
inside: {
31+
'keyword': /^for\b|\b(?:in|do)\b/i,
32+
'string': string,
33+
'parameter': parameter,
34+
'variable': variable,
35+
'number': number,
36+
'punctuation': /[()',]/
37+
}
38+
},
39+
{
40+
// IF command
41+
pattern: /((?:^|[&(])[ \t]*)if(?: ?\/[a-z?](?:[ :](?:"[^"]*"|\S+))?)* (?:not )?(?:cmdextversion \d+|defined \w+|errorlevel \d+|exist \S+|(?:"[^"]*"|\S+)?(?:==| (?:equ|neq|lss|leq|gtr|geq) )(?:"[^"]*"|\S+))/im,
42+
lookbehind: true,
43+
inside: {
44+
'keyword': /^if\b|\b(?:not|cmdextversion|defined|errorlevel|exist)\b/i,
45+
'string': string,
46+
'parameter': parameter,
47+
'variable': variable,
48+
'number': number,
49+
'operator': /\^|==|\b(?:equ|neq|lss|leq|gtr|geq)\b/i
50+
}
51+
},
52+
{
53+
// ELSE command
54+
pattern: /((?:^|[&()])[ \t]*)else\b/im,
55+
lookbehind: true,
56+
inside: {
57+
'keyword': /^else\b/i
58+
}
59+
},
60+
{
61+
// SET command
62+
pattern: /((?:^|[&(])[ \t]*)set(?: ?\/[a-z](?:[ :](?:"[^"]*"|\S+))?)* (?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
63+
lookbehind: true,
64+
inside: {
65+
'keyword': /^set\b/i,
66+
'string': string,
67+
'parameter': parameter,
68+
'variable': [
69+
variable,
70+
/\w+(?=(?:[*\/%+\-&^|]|<<|>>)?=)/
71+
],
72+
'number': number,
73+
'operator': /[*\/%+\-&^|]=?|<<=?|>>=?|[!~_=]/,
74+
'punctuation': /[()',]/
75+
}
76+
},
77+
{
78+
// Other commands
79+
pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
80+
lookbehind: true,
81+
inside: {
82+
'keyword': /^\w+\b/i,
83+
'string': string,
84+
'parameter': parameter,
85+
'label': {
86+
pattern: /(^\s*):\S+/m,
87+
lookbehind: true,
88+
alias: 'property'
89+
},
90+
'variable': variable,
91+
'number': number,
92+
'operator': /\^/
93+
}
94+
}
95+
],
96+
'operator': /[&@]/,
97+
'punctuation': /[()']/
98+
};
99+
}(Prism));

components/prism-batch.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-batch.html

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h1>Batch</h1>
2+
<p>To use this language, use the class "language-batch".</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code>::
6+
:: Foo bar
7+
REM This is a comment too
8+
REM Multi-line ^
9+
comment</code></pre>
10+
11+
<h2>Labels</h2>
12+
<pre><code>:foobar
13+
GOTO :EOF</code></pre>
14+
15+
<h2>Commands</h2>
16+
<pre><code>@ECHO OFF
17+
FOR /l %%a in (5,-1,1) do (TITLE %title% -- closing in %%as)
18+
SET title=%~n0
19+
if /i "%InstSize:~0,1%"=="M" set maxcnt=3
20+
ping -n 2 -w 1 127.0.0.1</code></pre>
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
FOR /l %%a in (5,-1,1) do (TITLE %title% -- closing in %%as)
2+
SET title=%~n0
3+
echo.Hello World
4+
@ECHO OFF
5+
if not defined ProgressFormat set "ProgressFormat=[PPPP]"
6+
EXIT /b
7+
set /a ProgressCnt+=1
8+
IF "%~1" NEQ "" (SET %~1=%new%) ELSE (echo.%new%)
9+
10+
----------------------------------------------------
11+
12+
[
13+
["command", [
14+
["keyword", "FOR"],
15+
["parameter", ["/l"]],
16+
["variable", "%%a"],
17+
["keyword", "in"],
18+
["punctuation", "("],
19+
["number", "5"], ["punctuation", ","],
20+
["number", "-1"], ["punctuation", ","],
21+
["number", "1"], ["punctuation", ")"],
22+
["keyword", "do"]
23+
]],
24+
["punctuation", "("],
25+
["command", [
26+
["keyword", "TITLE"],
27+
["variable", "%title%"],
28+
" -- closing in ",
29+
["variable", "%%as"]
30+
]],
31+
["punctuation", ")"],
32+
33+
["command", [
34+
["keyword", "SET"],
35+
["variable", "title"],
36+
["operator", "="],
37+
["variable", "%~n0"]
38+
]],
39+
40+
["command", [
41+
["keyword", "echo"],
42+
".Hello World"
43+
]],
44+
45+
["operator", "@"],
46+
["command", [
47+
["keyword", "ECHO"],
48+
" OFF"
49+
]],
50+
51+
["command", [
52+
["keyword", "if"],
53+
["keyword", "not"],
54+
["keyword", "defined"],
55+
" ProgressFormat"
56+
]],
57+
["command", [
58+
["keyword", "set"],
59+
["string", "\"ProgressFormat=[PPPP]\""]
60+
]],
61+
62+
["command", [
63+
["keyword", "EXIT"],
64+
["parameter", ["/b"]]
65+
]],
66+
67+
["command", [
68+
["keyword", "set"],
69+
["parameter", ["/a"]],
70+
["variable", "ProgressCnt"],
71+
["operator", "+="],
72+
["number", "1"]
73+
]],
74+
75+
["command", [
76+
["keyword", "IF"],
77+
["string", "\"%~1\""],
78+
["operator", "NEQ"],
79+
["string", "\"\""]
80+
]],
81+
["punctuation", "("],
82+
["command", [
83+
["keyword", "SET"],
84+
["variable", "%~1"],
85+
["operator", "="],
86+
["variable", "%new%"]
87+
]],
88+
["punctuation", ")"],
89+
["command", [
90+
["keyword", "ELSE"]
91+
]],
92+
["punctuation", "("],
93+
["command", [
94+
["keyword", "echo"],
95+
".",
96+
["variable", "%new%"]
97+
]],
98+
["punctuation", ")"]
99+
]
100+
101+
----------------------------------------------------
102+
103+
Checks for commands.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
::
2+
:: Foobar
3+
REM Foobar
4+
rem foo^
5+
bar
6+
7+
----------------------------------------------------
8+
9+
[
10+
["comment", "::"],
11+
["comment", ":: Foobar"],
12+
["comment", "REM Foobar"],
13+
["comment", "rem foo^\r\nbar"]
14+
]
15+
16+
----------------------------------------------------
17+
18+
Checks for comments.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:foo
2+
:Foo_Bar
3+
4+
----------------------------------------------------
5+
6+
[
7+
["label", ":foo"],
8+
["label", ":Foo_Bar"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for labels.

0 commit comments

Comments
 (0)