2 " Language: MSDOS batch file (with NT command extensions)
3 " Maintainer: Mike Williams <mrw@netcomuk.co.uk>
5 " Last Change: 14th May 1999
8 " For version 5.x: Clear all syntax items
9 " For version 6.x: Quit when a syntax file was already loaded
12 elseif exists("b:current_syntax")
16 " DOS bat files are case insensitive but case preserving!
19 syn keyword dosbatchTodo contained TODO
22 syn keyword dosbatchStatement goto call exit
23 syn keyword dosbatchConditional if else
24 syn keyword dosbatchRepeat for
26 " Some operators - first lot are case sensitive!
28 syn keyword dosbatchOperator EQU NEQ LSS LEQ GTR GEQ
30 syn match dosbatchOperator "\s[-+\*/%]\s"
31 syn match dosbatchOperator "="
32 syn match dosbatchOperator "[-+\*/%]="
33 syn match dosbatchOperator "\s\(&\||\|^\|<<\|>>\)=\=\s"
34 syn match dosbatchIfOperator "if\s\+\(\(not\)\=\s\+\)\=\(exist\|defined\|errorlevel\|cmdextversion\)\="lc=2
36 " String - using "'s is a convenience rather than a requirement outside of FOR
37 syn match dosbatchString "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,@dosbatchNumber
38 syn match dosbatchString "\<echo[^)>|]*"lc=4 contains=dosbatchVariable,dosbatchArgument,@dosbatchNumber
39 syn match dosbatchEchoOperator "\<echo\s\+\(on\|off\)\s*$"lc=4
41 " For embedded commands
42 syn match dosbatchCmd "(\s*'[^']*'"lc=1 contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator
44 " Numbers - surround with ws to not include in dir and filenames
45 syn match dosbatchInteger "[[:space:]=(/:]\d\+"lc=1
46 syn match dosbatchHex "[[:space:]=(/:]0x\x\+"lc=1
47 syn match dosbatchBinary "[[:space:]=(/:]0b[01]\+"lc=1
48 syn match dosbatchOctal "[[:space:]=(/:]0\o\+"lc=1
49 syn cluster dosbatchNumber contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal
51 " Command line switches
52 syn match dosbatchSwitch "/\(\a\+\|?\)"
54 " Various special escaped char formats
55 syn match dosbatchSpecialChar "\^[&|()<>^]"
56 syn match dosbatchSpecialChar "\$[a-hl-npqstv_$+]"
57 syn match dosbatchSpecialChar "%%"
59 " Environment variables
60 syn match dosbatchIdentifier contained "\s\h\w*\>"
61 syn match dosbatchVariable "%\h\w*%"
62 syn match dosbatchVariable "%\h\w*:\*\=[^=]*=[^%]*%"
63 syn match dosbatchVariable "%\h\w*:\~\d\+,\d\+%" contains=dosbatchInteger
64 syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
66 " Args to bat files and for loops, etc
67 syn match dosbatchArgument "%\(\d\|\*\)"
68 syn match dosbatchArgument "%%[a-z]\>"
69 syn match dosbatchArgument "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
72 syn match dosbatchLabel "^\s*:\s*\h\w*\>"
73 syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
74 syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=4
75 syn match dosbatchLabel ":\h\w*\>"
77 " Comments - usual rem but also two colons as first non-space is an idiom
78 syn match dosbatchComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
79 syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
80 syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
82 " Comments in ()'s - still to handle spaces before rem
83 syn match dosbatchComment "(rem[^)]*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument
85 syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
86 syn keyword dosbatchImplicit chkdsk cls cmd color comp compact convert copy
87 syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
88 syn keyword dosbatchImplicit erase fc find findstr format ftype
89 syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move
90 syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem
91 syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift
92 syn keyword dosbatchImplicit sort start subst time title tree type ver verify
93 syn keyword dosbatchImplicit vol xcopy
95 " Define the default highlighting.
96 " For version 5.7 and earlier: only when not done already
97 " For version 5.8 and later: only when an item doesn't have highlighting yet
98 if version >= 508 || !exists("did_dosbatch_syntax_inits")
100 let did_dosbatch_syntax_inits = 1
101 command -nargs=+ HiLink hi link <args>
103 command -nargs=+ HiLink hi def link <args>
106 HiLink dosbatchTodo Todo
108 HiLink dosbatchStatement Statement
109 HiLink dosbatchCommands dosbatchStatement
110 HiLink dosbatchLabel Label
111 HiLink dosbatchConditional Conditional
112 HiLink dosbatchRepeat Repeat
114 HiLink dosbatchOperator Operator
115 HiLink dosbatchEchoOperator dosbatchOperator
116 HiLink dosbatchIfOperator dosbatchOperator
118 HiLink dosbatchArgument Identifier
119 HiLink dosbatchIdentifier Identifier
120 HiLink dosbatchVariable dosbatchIdentifier
122 HiLink dosbatchSpecialChar SpecialChar
123 HiLink dosbatchString String
124 HiLink dosbatchNumber Number
125 HiLink dosbatchInteger dosbatchNumber
126 HiLink dosbatchHex dosbatchNumber
127 HiLink dosbatchBinary dosbatchNumber
128 HiLink dosbatchOctal dosbatchNumber
130 HiLink dosbatchComment Comment
131 HiLink dosbatchImplicit Function
133 HiLink dosbatchSwitch Special
135 HiLink dosbatchCmd PreProc
140 let b:current_syntax = "dosbatch"