codekingpro/portable-devtools
115k
1" Vim syntax file2" Language: MS-DOS/Windows batch file (with NT command extensions)3" Maintainer: Mike Williams <mrmrdubya@gmail.com>4" Filenames: *.bat5" Last Change: 3rd February 20246" 2024 Aug 14 by Vim Project: improve syntax (#15453)7"8" Options Flags:9" dosbatch_cmdextversion - 1 = Windows NT, 2 = Windows 2000 [default]10" dosbatch_colons_comment - any value to allow :: comments in code blocks11"12 13" quit when a syntax file was already loaded14if exists("b:current_syntax")15 finish16endif17 18" Set default highlighting to Win2k19if !exists("dosbatch_cmdextversion")20 let dosbatch_cmdextversion = 221endif22 23" DOS bat files are case insensitive but case preserving!24syn case ignore25 26syn keyword dosbatchTodo contained TODO27 28" Dosbat keywords29syn keyword dosbatchStatement goto call exit30syn keyword dosbatchConditional if else31syn keyword dosbatchRepeat for32 33" Some operators - first lot are case sensitive!34syn case match35syn keyword dosbatchOperator EQU NEQ LSS LEQ GTR GEQ36syn case ignore37syn match dosbatchOperator "\s[-+\*/%!~]\s"38syn match dosbatchOperator "="39syn match dosbatchOperator "[-+\*/%]="40syn match dosbatchOperator "\s\(&\||\|^\|<<\|>>\)=\=\s"41syn match dosbatchIfOperator "if\s\+\(\(not\)\=\s\+\)\=\(exist\|defined\|errorlevel\|cmdextversion\)\="lc=242 43" String - using "'s is a convenience rather than a requirement outside of FOR44syn match dosbatchString "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell45syn match dosbatchString "\<echo\([^)>|]\|\^\@<=[)>|]\)*"lc=4 contains=dosbatchVariable,dosbatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell46syn match dosbatchEchoOperator "\<echo\s\+\(on\|off\)\s*$"lc=447 48" For embedded commands49syn match dosbatchCmd "(\s*'[^']*'"lc=1 contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator,dosbatchIfOperator50 51" Numbers - surround with ws to not include in dir and filenames52syn match dosbatchInteger "[[:space:]=(/:,!~-]\d\+"lc=153syn match dosbatchHex "[[:space:]=(/:,!~-]0x\x\+"lc=154syn match dosbatchBinary "[[:space:]=(/:,!~-]0b[01]\+"lc=155syn match dosbatchOctal "[[:space:]=(/:,!~-]0\o\+"lc=156syn cluster dosbatchNumber contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal57 58" Command line switches59syn match dosbatchSwitch "/\(\a\+\|?\)"60 61" Various special escaped char formats62syn match dosbatchSpecialChar "\^[&|()<>^]"63syn match dosbatchSpecialChar "\$[a-hl-npqstv_$+]"64syn match dosbatchSpecialChar "%%"65 66" Environment variables67syn match dosbatchIdentifier contained "\s\h\w*\>"68syn match dosbatchVariable "%\h\w*%"69syn match dosbatchVariable "%\h\w*:\*\=[^=]*=[^%]*%"70syn match dosbatchVariable "%\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=%" contains=dosbatchInteger71syn match dosbatchVariable "!\h\w*!"72syn match dosbatchVariable "!\h\w*:\*\=[^=]*=[^!]*!"73syn match dosbatchVariable "!\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=!" contains=dosbatchInteger74syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator75 76" Args to bat files and for loops, etc77syn match dosbatchArgument "%\(\d\|\*\)"78syn match dosbatchArgument "%%[a-z]\>"79if dosbatch_cmdextversion == 180 syn match dosbatchArgument "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"81else82 syn match dosbatchArgument "%\~[fdpnxsatz]\+\(\($PATH:\)\=[a-z]\|\d\)\>"83endif84 85" Line labels86syn match dosbatchLabel "^\s*:\s*\h\w*\>"87syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=488syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=489syn match dosbatchLabel ":\h\w*\>"90 91" Comments - usual rem but also two colons as first non-space is an idiom92syn match dosbatchRemComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell93syn match dosbatchRemComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell94syn match dosbatchRemComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell95syn match dosbatchRemComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell96syn match dosbatchColonComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell97 98" Commands code blocks99syn cluster dosbatchCodeBlockComment contains=dosbatchRemComment100if exists("dosbatch_colons_comment")101 syn cluster dosbatchCodeBlockComment add=dosbatchColonComment102else103 syn match dosbatchColonCommentErr contained "\s*:\s*:.*$"104endif105syn match dosbatchColonCommentErr contained "\s*:\s*:[^)]*\(\(\n\s*\)\?)\)\@="106syn region dosbatchCodeBlock transparent start=+(+ end=+)+ contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator,dosbatchIfOperator,@dosbatchCodeBlockComment,dosbatchColonCommentErr,dosbatchCodeBlock107syn match dosbatchCodeBlockErr ")"108 109syn sync match dosbatchSyncCodeBlock grouphere NONE "^)\s*$"110 111syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir112syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy113syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal114syn keyword dosbatchImplicit erase fc find findstr format ftype115syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move116syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem117syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift118syn keyword dosbatchImplicit sort start subst time title tree type ver verify119syn keyword dosbatchImplicit vol xcopy120 121" Define the default highlighting.122" Only when an item doesn't have highlighting yet123 124hi def link dosbatchTodo Todo125hi def link dosbatchError Error126hi def link dosbatchCodeBlockErr dosbatchError127hi def link dosbatchColonCommentErr dosbatchError128 129hi def link dosbatchStatement Statement130hi def link dosbatchCommands dosbatchStatement131hi def link dosbatchLabel Label132hi def link dosbatchConditional Conditional133hi def link dosbatchRepeat Repeat134 135hi def link dosbatchOperator Operator136hi def link dosbatchEchoOperator dosbatchOperator137hi def link dosbatchIfOperator dosbatchOperator138 139hi def link dosbatchArgument Identifier140hi def link dosbatchIdentifier Identifier141hi def link dosbatchVariable dosbatchIdentifier142 143hi def link dosbatchSpecialChar SpecialChar144hi def link dosbatchString String145hi def link dosbatchNumber Number146hi def link dosbatchInteger dosbatchNumber147hi def link dosbatchHex dosbatchNumber148hi def link dosbatchBinary dosbatchNumber149hi def link dosbatchOctal dosbatchNumber150 151hi def link dosbatchComment Comment152hi def link dosbatchRemComment dosbatchComment153hi def link dosbatchColonComment dosbatchComment154 155hi def link dosbatchImplicit Function156 157hi def link dosbatchSwitch Special158 159hi def link dosbatchCmd PreProc160 161 162let b:current_syntax = "dosbatch"163 164" vim: ts=8165 