robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0c3bdb80bd
master
1" Vim syntax file 2" Language: MS-DOS/Windows batch file (with NT command extensions) 3" Maintainer: Mike Williams <mrmrdubya@gmail.com> 4" Filenames: *.bat 5" Last Change: 3rd February 2024 6" 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 blocks 11" 12 13" quit when a syntax file was already loaded 14if exists ( "b:current_syntax" ) 15finish 16endif 17 18" Set default highlighting to Win2k 19if ! exists ( "dosbatch_cmdextversion" ) 20let dosbatch_cmdextversion = 2 21endif 22 23" DOS bat files are case insensitive but case preserving! 24syn case ignore 25 26syn keyword dosbatchTodo contained TODO 27 28" Dosbat keywords 29syn keyword dosbatchStatement goto call exit 30syn keyword dosbatchConditional if else 31syn keyword dosbatchRepeat for 32 33" Some operators - first lot are case sensitive! 34syn case match 35syn keyword dosbatchOperator EQU NEQ LSS LEQ GTR GEQ 36syn case ignore 37syn 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= 2 42 43" String - using "'s is a convenience rather than a requirement outside of FOR 44syn match dosbatchString "\" [ ^" ] * \" "contains = dosbatchVariable , dosBatchArgument , dosbatchSpecialChar , @dosbatchNumber , @Spell 45syn match dosbatchString "\<echo\( [ ^)>| ] \|\^\@<= [ )>| ] \) * "lc= 4contains = dosbatchVariable , dosbatchArgument , dosbatchSpecialChar , @dosbatchNumber , @Spell 46syn match dosbatchEchoOperator "\<echo\s\+\(on\|off\)\s * $ "lc= 4 47 48" For embedded commands 49syn match dosbatchCmd "(\s * ' [ ^' ] * ' "lc= 1contains = dosbatchString , dosbatchVariable , dosBatchArgument , @dosbatchNumber , dosbatchImplicit , dosbatchStatement , dosbatchConditional , dosbatchRepeat , dosbatchOperator , dosbatchIfOperator 50 51" Numbers - surround with ws to not include in dir and filenames 52syn match dosbatchInteger "[ [:space: ] =(/:,!~-]\d\+ "lc= 1 53syn match dosbatchHex "[ [:space: ] =(/:,!~-]0x\x\+ "lc= 1 54syn match dosbatchBinary "[ [:space: ] =(/:,!~-]0b [ 01 ] \+ "lc= 1 55syn match dosbatchOctal "[ [:space: ] =(/:,!~-]0\o\+ "lc= 1 56syn cluster dosbatchNumber contains = dosbatchInteger , dosbatchHex , dosbatchBinary , dosbatchOctal 57 58" Command line switches 59syn match dosbatchSwitch "/\(\a\+\|?\) " 60 61" Various special escaped char formats 62syn match dosbatchSpecialChar "\^ [ &|()<>^ ] " 63syn match dosbatchSpecialChar "\$ [ a-hl-npqstv_$+ ] " 64syn match dosbatchSpecialChar "%% " 65 66" Environment variables 67syn match dosbatchIdentifier contained "\s\h\w * \> " 68syn match dosbatchVariable "%\h\w * % " 69syn match dosbatchVariable "%\h\w * :\*\= [ ^= ] * = [ ^% ] * % " 70syn match dosbatchVariable "%\h\w * :\~ [ - ] \=\d\+\(, [ - ] \=\d\+\)\=% "contains = dosbatchInteger 71syn match dosbatchVariable "!\h\w * ! " 72syn match dosbatchVariable "!\h\w * :\*\= [ ^= ] * = [ ^! ] * ! " 73syn match dosbatchVariable "!\h\w * :\~ [ - ] \=\d\+\(, [ - ] \=\d\+\)\=! "contains = dosbatchInteger 74syn match dosbatchSet "\s\h\w * [ +- ] \==\{-1} "contains = dosbatchIdentifier , dosbatchOperator 75 76" Args to bat files and for loops, etc 77syn match dosbatchArgument "%\(\d\|\*\) " 78syn match dosbatchArgument "%% [ a-z ] \> " 79if dosbatch_cmdextversion == 1 80syn match dosbatchArgument "%\~ [ fdpnxs ] \+\(\($PATH:\)\= [ a-z ] \|\d\)\> " 81else 82syn match dosbatchArgument "%\~ [ fdpnxsatz ] \+\(\($PATH:\)\= [ a-z ] \|\d\)\> " 83endif 84 85" Line labels 86syn match dosbatchLabel "^\s * :\s * \h\w * \> " 87syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w * \> "lc= 4 88syn match dosbatchLabel "\<goto\s\+\h\w * \> "lc= 4 89syn match dosbatchLabel ":\h\w * \> " 90 91" Comments - usual rem but also two colons as first non-space is an idiom 92syn match dosbatchRemComment "^rem\($\|\s. * $\) "lc= 3contains = dosbatchTodo , dosbatchSpecialChar , @dosbatchNumber , dosbatchVariable , dosbatchArgument , @Spell 93syn match dosbatchRemComment "^@rem\($\|\s. * $\) "lc= 4contains = dosbatchTodo , @dosbatchNumber , dosbatchVariable , dosbatchArgument , @Spell 94syn match dosbatchRemComment "\srem\($\|\s. * $\) "lc= 4contains = dosbatchTodo , dosbatchSpecialChar , @dosbatchNumber , dosbatchVariable , dosbatchArgument , @Spell 95syn match dosbatchRemComment "\s@rem\($\|\s. * $\) "lc= 5contains = dosbatchTodo , @dosbatchNumber , dosbatchVariable , dosbatchArgument , @Spell 96syn match dosbatchColonComment "\s * :\s * :. * $ "contains = dosbatchTodo , dosbatchSpecialChar , @dosbatchNumber , dosbatchVariable , dosbatchArgument , @Spell 97 98" Commands code blocks 99syn cluster dosbatchCodeBlockComment contains = dosbatchRemComment 100if exists ( "dosbatch_colons_comment" ) 101syn cluster dosbatchCodeBlockComment add = dosbatchColonComment 102else 103syn match dosbatchColonCommentErr contained "\s * :\s * :. * $ " 104endif 105syn 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 , dosbatchCodeBlock 107syn match dosbatchCodeBlockErr ") " 108 109syn syncmatch dosbatchSyncCodeBlock grouphereNONE "^)\s * $ " 110 111syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir 112syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy 113syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal 114syn keyword dosbatchImplicit erase fc find findstr format ftype 115syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move 116syn keyword dosbatchImplicit path pause popd prompt pushd rd recover rem 117syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift 118syn keyword dosbatchImplicit sort start subst time title tree type ver verify 119syn keyword dosbatchImplicit vol xcopy 120 121" Define the default highlighting. 122" Only when an item doesn't have highlighting yet 123 124hi def link dosbatchTodo Todo 125hi def link dosbatchError Error 126hi def link dosbatchCodeBlockErr dosbatchError 127hi def link dosbatchColonCommentErr dosbatchError 128 129hi def link dosbatchStatement Statement 130hi def link dosbatchCommands dosbatchStatement 131hi def link dosbatchLabel Label 132hi def link dosbatchConditional Conditional 133hi def link dosbatchRepeat Repeat 134 135hi def link dosbatchOperator Operator 136hi def link dosbatchEchoOperator dosbatchOperator 137hi def link dosbatchIfOperator dosbatchOperator 138 139hi def link dosbatchArgument Identifier 140hi def link dosbatchIdentifier Identifier 141hi def link dosbatchVariable dosbatchIdentifier 142 143hi def link dosbatchSpecialChar SpecialChar 144hi def link dosbatchString String 145hi def link dosbatchNumber Number 146hi def link dosbatchInteger dosbatchNumber 147hi def link dosbatchHex dosbatchNumber 148hi def link dosbatchBinary dosbatchNumber 149hi def link dosbatchOctal dosbatchNumber 150 151hi def link dosbatchComment Comment 152hi def link dosbatchRemComment dosbatchComment 153hi def link dosbatchColonComment dosbatchComment 154 155hi def link dosbatchImplicit Function 156 157hi def link dosbatchSwitch Special 158 159hi def link dosbatchCmd PreProc 160 161 162let b: current_syntax = "dosbatch" 163 164" vim: ts=8