Update runtime files
[MacVim.git] / runtime / syntax / dosbatch.vim
blobcbff81c9b06789dae1c33797791c9759d5a96d58
1 " Vim syntax file
2 " Language:     MSDOS batch file (with NT command extensions)
3 " Maintainer:   Mike Williams <mrw@eandem.co.uk>
4 " Filenames:    *.bat
5 " Last Change:  30th October 2007
6 " Web Page:     http://www.eandem.co.uk/mrw/vim
8 " Options Flags:
9 " dosbatch_cmdextversion        - 1 = Windows NT, 2 = Windows 2000 [default]
12 " For version 5.x: Clear all syntax items
13 " For version 6.x: Quit when a syntax file was already loaded
14 if version < 600
15   syntax clear
16 elseif exists("b:current_syntax")
17   finish
18 endif
20 " Set default highlighting to Win2k
21 if !exists("dosbatch_cmdextversion")
22   let dosbatch_cmdextversion = 2
23 endif
25 " DOS bat files are case insensitive but case preserving!
26 syn case ignore
28 syn keyword dosbatchTodo contained      TODO
30 " Dosbat keywords
31 syn keyword dosbatchStatement   goto call exit
32 syn keyword dosbatchConditional if else
33 syn keyword dosbatchRepeat      for
35 " Some operators - first lot are case sensitive!
36 syn case match
37 syn keyword dosbatchOperator    EQU NEQ LSS LEQ GTR GEQ
38 syn case ignore
39 syn match dosbatchOperator      "\s[-+\*/%]\s"
40 syn match dosbatchOperator      "="
41 syn match dosbatchOperator      "[-+\*/%]="
42 syn match dosbatchOperator      "\s\(&\||\|^\|<<\|>>\)=\=\s"
43 syn match dosbatchIfOperator    "if\s\+\(\(not\)\=\s\+\)\=\(exist\|defined\|errorlevel\|cmdextversion\)\="lc=2
45 " String - using "'s is a convenience rather than a requirement outside of FOR
46 syn match dosbatchString        "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,@dosbatchNumber,@Spell
47 syn match dosbatchString        "\<echo[^)>|]*"lc=4 contains=dosbatchVariable,dosbatchArgument,@dosbatchNumber,@Spell
48 syn match dosbatchEchoOperator  "\<echo\s\+\(on\|off\)\s*$"lc=4
50 " For embedded commands
51 syn match dosbatchCmd           "(\s*'[^']*'"lc=1 contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator
53 " Numbers - surround with ws to not include in dir and filenames
54 syn match dosbatchInteger       "[[:space:]=(/:]\d\+"lc=1
55 syn match dosbatchHex           "[[:space:]=(/:]0x\x\+"lc=1
56 syn match dosbatchBinary        "[[:space:]=(/:]0b[01]\+"lc=1
57 syn match dosbatchOctal         "[[:space:]=(/:]0\o\+"lc=1
58 syn cluster dosbatchNumber      contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal
60 " Command line switches
61 syn match dosbatchSwitch        "/\(\a\+\|?\)"
63 " Various special escaped char formats
64 syn match dosbatchSpecialChar   "\^[&|()<>^]"
65 syn match dosbatchSpecialChar   "\$[a-hl-npqstv_$+]"
66 syn match dosbatchSpecialChar   "%%"
68 " Environment variables
69 syn match dosbatchIdentifier    contained "\s\h\w*\>"
70 syn match dosbatchVariable      "%\h\w*%"
71 syn match dosbatchVariable      "%\h\w*:\*\=[^=]*=[^%]*%"
72 syn match dosbatchVariable      "%\h\w*:\~\d\+,\d\+%" contains=dosbatchInteger
73 syn match dosbatchVariable      "!\h\w*!"
74 syn match dosbatchVariable      "!\h\w*:\*\=[^=]*=[^%]*!"
75 syn match dosbatchVariable      "!\h\w*:\~\d\+,\d\+!" contains=dosbatchInteger
76 syn match dosbatchSet           "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
78 " Args to bat files and for loops, etc
79 syn match dosbatchArgument      "%\(\d\|\*\)"
80 syn match dosbatchArgument      "%%[a-z]\>"
81 if dosbatch_cmdextversion == 1
82   syn match dosbatchArgument    "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
83 else
84   syn match dosbatchArgument    "%\~[fdpnxsatz]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
85 endif
87 " Line labels
88 syn match dosbatchLabel         "^\s*:\s*\h\w*\>"
89 syn match dosbatchLabel         "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
90 syn match dosbatchLabel         "\<goto\s\+\h\w*\>"lc=4
91 syn match dosbatchLabel         ":\h\w*\>"
93 " Comments - usual rem but also two colons as first non-space is an idiom
94 syn match dosbatchComment       "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
95 syn match dosbatchComment       "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
96 syn match dosbatchComment       "\s*:\s*:.*$" contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
98 " Comments in ()'s - still to handle spaces before rem
99 syn match dosbatchComment       "(rem[^)]*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
101 syn keyword dosbatchImplicit    append assoc at attrib break cacls cd chcp chdir
102 syn keyword dosbatchImplicit    chkdsk chkntfs cls cmd color comp compact convert copy
103 syn keyword dosbatchImplicit    date del dir diskcomp diskcopy doskey echo endlocal
104 syn keyword dosbatchImplicit    erase fc find findstr format ftype
105 syn keyword dosbatchImplicit    graftabl help keyb label md mkdir mode more move
106 syn keyword dosbatchImplicit    path pause popd print prompt pushd rd recover rem
107 syn keyword dosbatchImplicit    ren rename replace restore rmdir set setlocal shift
108 syn keyword dosbatchImplicit    sort start subst time title tree type ver verify
109 syn keyword dosbatchImplicit    vol xcopy
111 " Define the default highlighting.
112 " For version 5.7 and earlier: only when not done already
113 " For version 5.8 and later: only when an item doesn't have highlighting yet
114 if version >= 508 || !exists("did_dosbatch_syntax_inits")
115   if version < 508
116     let did_dosbatch_syntax_inits = 1
117     command -nargs=+ HiLink hi link <args>
118   else
119     command -nargs=+ HiLink hi def link <args>
120   endif
122   HiLink dosbatchTodo           Todo
124   HiLink dosbatchStatement      Statement
125   HiLink dosbatchCommands       dosbatchStatement
126   HiLink dosbatchLabel          Label
127   HiLink dosbatchConditional    Conditional
128   HiLink dosbatchRepeat         Repeat
130   HiLink dosbatchOperator       Operator
131   HiLink dosbatchEchoOperator   dosbatchOperator
132   HiLink dosbatchIfOperator     dosbatchOperator
134   HiLink dosbatchArgument       Identifier
135   HiLink dosbatchIdentifier     Identifier
136   HiLink dosbatchVariable       dosbatchIdentifier
138   HiLink dosbatchSpecialChar    SpecialChar
139   HiLink dosbatchString         String
140   HiLink dosbatchNumber         Number
141   HiLink dosbatchInteger        dosbatchNumber
142   HiLink dosbatchHex            dosbatchNumber
143   HiLink dosbatchBinary         dosbatchNumber
144   HiLink dosbatchOctal          dosbatchNumber
146   HiLink dosbatchComment        Comment
147   HiLink dosbatchImplicit       Function
149   HiLink dosbatchSwitch         Special
151   HiLink dosbatchCmd            PreProc
153   delcommand HiLink
154 endif
156 let b:current_syntax = "dosbatch"
158 " vim: ts=8