robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
66.5 KiB1064 linesraw
1" Vim syntax file
2" Language:		shell (sh) Korn shell (ksh) bash (sh)
3" Maintainer:		This runtime file is looking for a new maintainer.
4" Previous Maintainers:	Charles E. Campbell
5" 		Lennart Schultz <Lennart.Schultz@ecmwf.int>
6" Last Change:		2026 Sep 15 by Vim Project
7" Version:		208
8" Former URL:		http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH
9" For options and settings, please use:      :help ft-sh-syntax
10" This file includes many ideas from Eric Brunet (eric.brunet@ens.fr) and heredoc fixes from Felipe Contreras
11
12" quit when a syntax file was already loaded {{{1
13if exists("b:current_syntax")
14    finish
15endif
16
17" Ensure this is set unless we find another shell
18let b:is_sh = 1
19
20" If the shell script itself specifies which shell to use, use it
21let s:shebang = getline(1)
22
23if s:shebang =~ '^#!.\{-2,}\<ksh\>'
24    " The binary is too ambiguous (i.e. '/bin/ksh' or some such).
25    let b:is_kornshell = 1
26    let b:generic_korn = 1
27elseif s:shebang =~ '^#!.\{-2,}\<ksh93u\+\>'
28    " ksh93u+ (or 93u-) release (still much too common to encounter)
29    let b:is_kornshell = 1
30    let b:is_ksh93u = 1
31elseif s:shebang =~ '^#!.\{-2,}\<ksh93v\>'
32    " ksh93v- alpha or beta
33    let b:is_kornshell = 1
34    let b:is_ksh93v = 1
35elseif s:shebang =~ '^#!.\{-2,}\<ksh93\>'
36    " Could be any ksh93 release
37    let b:is_kornshell = 1
38    let b:is_ksh93 = 1
39elseif s:shebang =~ '^#!.\{-2,}\<ksh2020\>'
40    let b:is_kornshell = 1
41    let b:is_ksh2020 = 1
42elseif s:shebang =~ '^#!.\{-2,}\<ksh88\>'
43    " The actual AT&T ksh88 and its feature set is assumed.
44    let b:is_kornshell = 1
45    let b:is_ksh88 = 1
46elseif s:shebang =~ '^#!.\{-2,}\<mksh\>'
47    " MirBSD Korn Shell
48    let b:is_kornshell = 1
49    let b:is_mksh = 1
50elseif s:shebang =~ '^#!.\{-2,}\<bash\>'
51    let b:is_bash      = 1
52elseif s:shebang =~ '^#!.\{-2,}\<dash\>'
53    let b:is_dash      = 1
54" handling /bin/sh with is_kornshell/is_sh {{{1
55" b:is_sh will be set when "#! /bin/sh" is found;
56" However, it often is just a masquerade by bash (typically Linux)
57" or kornshell (typically workstations with Posix "sh").
58" So, when the user sets "g:is_kornshell", "g:is_bash",
59" "g:is_posix" or "g:is_dash", a b:is_sh is converted into
60" b:is_kornshell/b:is_bash/b:is_posix/b:is_dash, respectively.
61elseif !exists("b:is_kornshell") && !exists("b:is_bash") && !exists("b:is_posix") && !exists("b:is_dash")
62    if exists("g:is_kornshell")
63        let b:is_kornshell= 1
64        let b:generic_korn = 1
65    elseif exists("g:is_bash")
66        let b:is_bash= 1
67    elseif exists("g:is_dash")
68        let b:is_dash= 1
69    elseif exists("g:is_posix")
70        let b:is_posix= 1
71    elseif exists("g:is_sh")
72        let b:is_sh= 1
73    else
74        " user did not specify which shell to use, and
75        " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous.
76        " Assuming /bin/sh is executable, and if its a link, find out what it links to.
77        let s:shell = ""
78        if executable("/bin/sh")
79            let s:shell = resolve("/bin/sh")
80        elseif executable("/usr/bin/sh")
81            let s:shell = resolve("/usr/bin/sh")
82        endif
83        if s:shell =~ '\<ksh\>'
84            " The binary is too ambiguous (i.e. '/bin/ksh' or some such).
85            let b:is_kornshell = 1
86            let b:generic_korn = 1
87        elseif s:shell =~ '\<ksh93u\+\>'
88            " ksh93u+ (or 93u-) release (still much too common to encounter)
89            let b:is_kornshell = 1
90            let b:is_ksh93u = 1
91        elseif s:shell =~ '\<ksh93v\>'
92            " ksh93v- alpha or beta
93            let b:is_kornshell = 1
94            let b:is_ksh93v = 1
95        elseif s:shell =~ '\<ksh93\>'
96            " Could be any ksh93 release
97            let b:is_kornshell = 1
98            let b:is_ksh93 = 1
99        elseif s:shebang =~ '\<ksh2020\>'
100            let b:is_kornshell = 1
101            let b:is_ksh2020 = 1
102        elseif s:shell =~ '\<ksh88\>'
103            " The actual AT&T ksh88 and its feature set is assumed.
104            let b:is_kornshell = 1
105            let b:is_ksh88 = 1
106        elseif s:shell =~ '\<mksh\>'
107            " MirBSD Korn Shell
108            let b:is_kornshell = 1
109            let b:is_mksh = 1
110        elseif s:shell =~ '\<bash\>'
111            let b:is_bash = 1
112        elseif s:shell =~ '\<dash\>'
113            let b:is_dash = 1
114        else
115            let b:is_posix = 1
116        endif
117        unlet s:shell
118    endif
119endif
120
121unlet s:shebang
122
123" if b:is_dash, set b:is_posix too
124if exists("b:is_dash")
125    let b:is_posix= 1
126endif
127
128if exists("b:is_kornshell") || exists("b:is_bash")
129    if exists("b:is_sh")
130        unlet b:is_sh
131    endif
132endif
133
134" set up default g:sh_fold_enabled {{{1
135" ================================
136if !exists("g:sh_fold_enabled")
137    let g:sh_fold_enabled= 0
138elseif g:sh_fold_enabled != 0 && !has("folding")
139    echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
140    let g:sh_fold_enabled= 0
141endif
142let s:sh_fold_functions= and(g:sh_fold_enabled,1)
143let s:sh_fold_heredoc  = and(g:sh_fold_enabled,2)
144let s:sh_fold_ifdofor  = and(g:sh_fold_enabled,4)
145if g:sh_fold_enabled && &fdm == "manual"
146    " Given that	the	user provided g:sh_fold_enabled
147    " 	AND	g:sh_fold_enabled is manual (usual default)
148    " 	implies	a desire for syntax-based folding
149    setl fdm=syntax
150endif
151
152" set up the syntax-highlighting for iskeyword
153if (v:version == 704 && has("patch-7.4.1142")) || v:version > 704
154    if !exists("g:sh_syntax_isk") || (exists("g:sh_syntax_isk") && g:sh_syntax_isk)
155        if exists("b:is_bash")
156            exe "syn iskeyword ".&iskeyword.",-,:"
157        elseif exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh")
158            exe "syn iskeyword ".&iskeyword.",-,."
159        else
160            exe "syn iskeyword ".&iskeyword.",-"
161        endif
162    endif
163endif
164
165" Set up folding commands for shell {{{1
166" =================================
167if exists(":ShFoldFunctions") == 2
168    delc ShFoldFunctions
169endif
170if exists(":ShFoldIfHereDoc") == 2
171    delc ShFoldHereDoc
172endif
173if exists(":ShFoldIfDoFor") == 2
174    delc ShFoldIfDoFor
175endif
176if s:sh_fold_functions
177    com! -nargs=* ShFoldFunctions <args> fold
178else
179    com! -nargs=* ShFoldFunctions <args>
180endif
181if s:sh_fold_heredoc
182    com! -nargs=* ShFoldHereDoc <args> fold
183else
184    com! -nargs=* ShFoldHereDoc <args>
185endif
186if s:sh_fold_ifdofor
187    com! -nargs=* ShFoldIfDoFor <args> fold
188else
189    com! -nargs=* ShFoldIfDoFor <args>
190endif
191
192" Set up syntax error commands for shell {{{1
193" ======================================
194if exists("g:sh_no_error_rules") && type(g:sh_no_error_rules) == type([])
195    fun! s:ScanAndCondExecSynErrCmd(idx, cmd) abort
196        let parts = matchlist(a:cmd, '\(\(\S\+\)\s\+\(\S\+\)\s*\)\{2}')
197        " Do nothing for matchable names listed in "g:sh_no_error_rules".
198        if len(parts) < a:idx || index(g:sh_no_error_rules, parts[a:idx]) < 0
199            exec a:cmd
200        endif
201    endfun
202elseif exists("g:sh_no_error")
203    fun! s:ScanAndCondExecSynErrCmd(_, __) abort
204    endfun
205else
206    fun! s:ScanAndCondExecSynErrCmd(_, cmd) abort
207        exec a:cmd
208    endfun
209endif
210
211" Read shFooError from "syn match shFooError '<pattern>'" etc.
212com! -nargs=+ ShDefSynErrRule call s:ScanAndCondExecSynErrCmd(2, <q-args>)
213" Read shFooError from "hi def link shFooError Error".
214com! -nargs=+ ShLinkSynErrGroup call s:ScanAndCondExecSynErrCmd(3, <q-args>)
215
216" Generate bracket expression items {{{1
217" =================================
218" Note that the following function can be invoked as many times as necessary
219" provided that these constraints hold for the passed dictionary argument:
220" - every time a unique group-name value is assigned to the "itemGroup" key;
221" - only ONCE either the "extraArgs" key is not entered or it is entered and
222"   its value does not have "contained" among other optional arguments (":help
223"   :syn-arguments").
224fun! s:GenerateBracketExpressionItems(dict) abort
225    let itemGroup = a:dict.itemGroup
226    let bracketGroup = a:dict.bracketGroup
227    let invGroup = itemGroup . 'Inv'
228    let skipLeftBracketGroup = itemGroup . 'SkipLeftBracket'
229    let skipRightBracketGroup = itemGroup . 'SkipRightBracket'
230    let extraArgs = has_key(a:dict, 'extraArgs') ? a:dict.extraArgs : ''
231
232    " Make the leading "[!^]" stand out in a NON-matching expression.
233    exec 'syn match ' . invGroup . ' contained "\[\@<=[!^]"'
234
235    " Set up indirections for unbalanced-bracket highlighting.
236    exec 'syn region ' . skipRightBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" matchgroup=shCollSymb end="\[\.[^]]\{-}\][^]]\{-}\.\]" matchgroup=' . itemGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup
237    exec 'syn region ' . skipLeftBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" skip="[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\%(\[[:.=]\@!\)\@=" matchgroup=' . itemGroup . ' end="\[[:.=]\@!" contains=@shBracketExprList,shDoubleQuote,' . invGroup
238
239    " Look for a general matching expression.
240    exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[\S\@=" end="\]" contains=@shBracketExprList,shDoubleQuote ' . extraArgs
241    " Look for a general NON-matching expression.
242    exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[[!^]\@=" end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup . ' ' . extraArgs
243
244    " Accommodate unbalanced brackets in bracket expressions.  The supported
245    " syntax for a plain "]" can be: "[]ws]" and "[^]ws]"; or, "[ws[.xs]ys.]zs]"
246    " and "[^ws[.xs]ys.]zs]"; see §9.3.5 RE Bracket Expression (in XBD).
247    exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipRightBracketGroup . ' ' . extraArgs
248    " Strive to handle "[]...[]" etc.
249    exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\[[:.=]\@!" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipLeftBracketGroup . ' ' . extraArgs
250
251    if !exists("g:skip_sh_syntax_inits")
252        exec 'hi def link ' . skipLeftBracketGroup . ' ' . itemGroup
253        exec 'hi def link ' . skipRightBracketGroup . ' ' . itemGroup
254        exec 'hi def link ' . invGroup . ' Underlined'
255    endif
256endfun
257
258call s:GenerateBracketExpressionItems({'itemGroup': 'shBracketExpr', 'bracketGroup': 'shBracketExprDelim'})
259
260" sh syntax is case sensitive {{{1
261syn case match
262
263" Clusters: contains=@... clusters {{{1
264"==================================
265syn cluster shErrorList	contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK
266if exists("b:is_kornshell") || exists("b:is_bash")
267    syn cluster ErrorList add=shDTestError
268endif
269syn cluster shArithParenList	contains=shArithmetic,shArithParen,shCaseEsac,shComment,shDeref,shDerefVarArray,shDo,shDerefSimple,shEcho,shEscape,shExpr,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shHereString,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement,shIf,shFor
270syn cluster shArithList	contains=@shArithParenList,shParenError
271syn cluster shBracketExprList	contains=shCharClassOther,shCharClass,shCollSymb,shEqClass
272syn cluster shCaseEsacList	contains=shCaseStart,shCaseLabel,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange
273syn cluster shCaseList	contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shComment,shDblBrace,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
274if exists("b:is_kornshell") || exists("b:is_bash")
275    syn cluster shCaseList	add=shForPP,shDblParen
276endif
277syn cluster shCommandSubList	contains=shAlias,shArithmetic,shBracketExpr,shCmdParenRegion,shCommandSub,shComment,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable
278syn cluster shCurlyList	contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
279" COMBAK: removing shEscape from shDblQuoteList fails ksh04:43 -- Jun 09, 2022: I don't see the problem with ksh04, so am reinstating shEscape
280syn cluster shDblQuoteList	contains=shArithmetic,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shDeref,shDerefSimple,shEscape,shPosnParm,shCtrlSeq,shSpecial,shSpecialDQ
281syn cluster shDerefList	contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPSR,shDerefPPS
282syn cluster shDerefVarList	contains=shDerefOffset,shDerefOp,shDerefVarArray,shDerefOpError
283syn cluster shEchoList	contains=shArithmetic,shBracketExpr,shCommandSub,shCommandSubBQ,shDerefVarArray,shSubshare,shValsub,shDeref,shDerefSimple,shEscape,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote
284syn cluster shExprList1	contains=shBracketExpr,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
285syn cluster shExprList2	contains=@shExprList1,@shCaseList,shTest,shFunctionNameAssignError
286syn cluster shFunctionCmds	contains=shFor,shCaseEsac,shIf,shRepeat,shDblBrace,shDblParen
287if exists("b:is_ksh88") || exists("b:is_mksh")
288    " Offer "shFunctionCmds" as is.
289elseif exists("b:is_kornshell") || exists("b:is_bash")
290    syn cluster shFunctionCmds	add=shForPP
291else
292    syn cluster shFunctionCmds	remove=shDblBrace,shDblParen
293endif
294syn cluster shFunctionDefList	contains=shDoError,shIfError,shFunctionKey,shFunctionOne,shFunctionThree,shFunctionCmdOne
295syn cluster shFunctionList	contains=shBracketExpr,@shCommandSubList,shCaseEsac,shColon,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shOption,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq,@shFunctionDefList
296if exists("b:is_kornshell") || exists("b:is_bash")
297    syn cluster shFunctionList	add=shRepeat,shDblBrace,shDblParen,shForPP
298    syn cluster shDerefList	add=shCommandSubList,shEchoDeref
299endif
300syn cluster shHereBeginList	contains=@shCommandSubList
301syn cluster shHereList	contains=shBeginHere,shHerePayload
302syn cluster shHereListDQ	contains=shBeginHere,@shDblQuoteList,shHerePayload
303syn cluster shIdList	contains=shArithmetic,shCommandSub,shCommandSubBQ,shDerefVarArray,shSubshare,shValsub,shWrapLineOperator,shSetOption,shComment,shDeref,shDerefSimple,shHereString,shNumber,shOperator,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial,shAtExpr
304syn cluster shIfList	contains=@shLoopList,shDblBrace,shDblParen,@shFunctionDefList
305syn cluster shLoopList	contains=@shCaseList,@shErrorList,shCaseEsac,shConditional,shDblBrace,shExpr,shFor,shIf,shOption,shSet,shTest,shTestOpr,shTouch
306if exists("b:is_kornshell") || exists("b:is_bash")
307    syn cluster shLoopList	add=shForPP,shDblParen
308endif
309syn cluster shPPSLeftList	contains=shAlias,shArithmetic,shBracketExpr,shCmdParenRegion,shCommandSub,shSubshare,shValsub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable
310syn cluster shPPSRightList	contains=shDeref,shDerefSimple,shEscape,shPosnParm
311syn cluster shSubShList	contains=shBracketExpr,@shCommandSubList,shCommandSubBQ,shSubshare,shValsub,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator,shFunctionNameAssignError
312syn cluster shTestList	contains=shArithmetic,shBracketExpr,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shSpecialDQ,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr
313syn cluster shNoZSList	contains=shSpecialNoZS
314syn cluster shForList	contains=shTestOpr,shNumber,shDerefSimple,shDeref,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shArithmetic
315
316" Echo: {{{1
317" ====
318" This one is needed INSIDE a CommandSub, so that `echo bla` be correct
319if (exists("b:is_kornshell") && !exists("b:is_ksh88"))
320    syn region shEcho matchgroup=shStatement start="\<echo\>"  skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 end="\ze[ \t\n;]}" contains=@shEchoList skipwhite nextgroup=shQuickComment
321    syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 end="\ze[ \t\n;]}" contains=@shEchoList skipwhite nextgroup=shQuickComment
322else
323    syn region shEcho matchgroup=shStatement start="\<echo\>"  skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment
324    syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment
325endif
326if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix")
327    syn region shEchoDeref contained matchgroup=shStatement start="\<echo\>"  skip="\\$" matchgroup=shEchoDelim end="$" end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment
328    syn region shEchoDeref contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment
329endif
330syn match  shEchoQuote contained	'\%(\\\\\)*\\["`'()]'
331
332" This must be after the strings, so that ... \" will be correct
333syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=shBracketExpr,shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shExDoubleQuote,shDoubleQuote,shCtrlSeq
334
335" Alias: {{{1
336" =====
337if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix")
338    syn match shStatement "\<alias\>"
339    syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]*\)\@="  skip="\\$" end="\>\|`"
340    syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]*=\)\@=" skip="\\$" end="="
341
342    " Touch: {{{1
343    " =====
344    syn match shTouch	'\<touch\>[^;#]*'	skipwhite nextgroup=shComment contains=shTouchCmd,shDoubleQuote,shSingleQuote,shDeref,shDerefSimple,shExpr
345    syn match shTouchCmd	'\<touch\>'		contained
346endif
347
348" Error Codes: {{{1
349" ============
350ShDefSynErrRule syn match   shDoError "\<done\>"
351ShDefSynErrRule syn match   shIfError "\<fi\>"
352ShDefSynErrRule syn match   shInError "\<in\>"
353ShDefSynErrRule syn match   shCaseError ";;"
354ShDefSynErrRule syn match   shEsacError "\<esac\>"
355ShDefSynErrRule syn match   shCurlyError "}"
356ShDefSynErrRule syn match   shParenError ")"
357ShDefSynErrRule syn match   shOK	'\.\%(done\|fi\|in\|esac\)'
358if exists("b:is_kornshell") || exists("b:is_bash")
359    ShDefSynErrRule syn match     shDTestError "]]"
360endif
361ShDefSynErrRule syn match     shTestError "]"
362
363" Options: {{{1
364" ====================
365syn match   shOption	"\s\zs[-+][-_a-zA-Z#@0-9]\+"
366syn match   shOption	"\s\zs--[^ \t$=`'"|);]\+"
367
368" File Redirection Highlighted As Operators: {{{1
369"===========================================
370syn match      shRedir	"\d\=>\(&[-0-9]\)\="
371syn match      shRedir	"\d\=>>-\="
372syn match      shRedir	"\d\=<\(&[-0-9]\)\="
373syn match      shRedir	"\d<<-\="
374
375" Operators: {{{1
376" ==========
377syn match   shOperator	"<<\|>>"		contained
378syn match   shOperator	"[!&;|]"		contained
379syn match   shOperator	"[-=/*+%]\=="		skipwhite nextgroup=shPattern
380syn match   shPattern	"\<\S\+\())\)\@="	contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref
381
382" Subshells: {{{1
383" ==========
384syn region shExpr  transparent matchgroup=shExprRegion  start="{" end="}"		contains=@shExprList2 nextgroup=shSpecialNxt
385syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")"	contains=@shSubShList nextgroup=shSpecialNxt
386
387" Tests: {{{1
388"=======
389syn region shExpr	matchgroup=shRange start="\[\s\@=" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial
390syn region shTest	transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
391syn region shNoQuote	start='\S'	skip='\%(\\\\\)*\\.'	end='\ze\s' end="\ze['"]"	contained contains=shBracketExpr,shDerefSimple,shDeref,shEscape
392syn match  shAstQuote	contained	'\*\ze"'	nextgroup=shString
393syn match  shTestOpr	contained	'[^-+/%]\zs=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern
394syn match  shTestOpr	contained	"<=\|>=\|!=\|==\|=\~\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]"
395syn match  shTestPattern	contained	'\w\+'
396syn region shTestDoubleQuote	contained	start='\%(\%(\\\\\)*\\\)\@<!"' skip=+\\\\\|\\"+ end='"'	contains=shDeref,shDerefSimple,shDerefSpecial
397syn match  shTestSingleQuote	contained	'\\.'	nextgroup=shTestSingleQuote
398syn match  shTestSingleQuote	contained	"'[^']*'"
399if exists("b:is_kornshell") || exists("b:is_bash")
400    syn region  shDblBrace matchgroup=Delimiter start="\[\[\s\@="	skip=+\%(\\\\\)*\\$+ end="\]\]"	contains=@shTestList,shAstQuote,shNoQuote,shComment
401    syn region  shDblParen matchgroup=Delimiter start="(("	skip=+\%(\\\\\)*\\$+ end="))"	contains=@shTestList,shComment
402endif
403
404" Character Class In Range: {{{1
405" =========================
406syn match   shCharClassOther	contained	"\[:\w\{-}:\]"
407syn match   shCharClass	contained	"\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\]"
408syn match   shCollSymb	contained	"\[\..\{-}\.\]"
409syn match   shEqClass	contained	"\[=.\{-}=\]"
410
411" Loops: do, if, while, until {{{1
412" ======
413ShFoldIfDoFor syn region shDo	transparent	matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>"			contains=@shLoopList
414ShFoldIfDoFor syn region shIf	transparent	matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>"	contains=@shIfList
415ShFoldIfDoFor syn region shFor		matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2			contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
416if exists("b:is_kornshell") || exists("b:is_bash")
417    ShFoldIfDoFor syn region shForPP	matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=@shForList
418endif
419
420if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix")
421    syn cluster shCaseList	add=shRepeat
422    syn cluster shFunctionList	add=shRepeat
423    syn region shRepeat   matchgroup=shLoop   start="\<while\_s" end="\<do\>"me=e-2	contains=@shLoopList,shDblParen,shDblBrace
424    syn region shRepeat   matchgroup=shLoop   start="\<until\_s" end="\<do\>"me=e-2	contains=@shLoopList,shDblParen,shDblBrace
425    if !exists("b:is_posix")
426        syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
427    endif
428else
429    syn region shRepeat   matchgroup=shLoop   start="\<while\_s" end="\<do\>"me=e-2		contains=@shLoopList
430    syn region shRepeat   matchgroup=shLoop   start="\<until\_s" end="\<do\>"me=e-2		contains=@shLoopList
431endif
432syn region shCurlyIn   contained	matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
433syn match  shComma     contained	","
434
435" Case: case...esac {{{1
436" ====
437syn match shCaseBar	contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|"		nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
438syn match shCaseStart	contained skipwhite skipnl "("			nextgroup=shCase,shCaseBar
439syn match shCaseLabel	contained skipwhite	"\%(\\.\|[-a-zA-Z0-9_*.]\)\+"	contains=shBracketExpr
440if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_ksh93u") && !exists("b:is_ksh93v") && !exists("b:is_ksh2020"))
441    ShFoldIfDoFor syn region	shCase	contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)"  end=";;" end=";&" end=";;&" end="esac"me=s-1	contains=@shCaseList	nextgroup=shCaseStart,shCase,shComment
442elseif exists("b:is_kornshell")
443    ShFoldIfDoFor syn region	shCase	contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)"  end=";;" end=";&" end="esac"me=s-1	contains=@shCaseList	nextgroup=shCaseStart,shCase,shComment
444else
445    ShFoldIfDoFor syn region	shCase	contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)"  end=";;" end="esac"me=s-1		contains=@shCaseList	nextgroup=shCaseStart,shCase,shComment
446endif
447ShFoldIfDoFor syn region	shCaseEsac	matchgroup=shConditional start="\<case\>" end="\<esac\>"	contains=@shCaseEsacList
448
449syn keyword shCaseIn	contained skipwhite skipnl in			nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
450if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88"))
451    syn region  shCaseExSingleQuote	matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+	contains=shStringSpecial,shSpecial	skipwhite skipnl nextgroup=shCaseBar	contained
452else
453    ShDefSynErrRule syn region  shCaseExSingleQuote	matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+	contains=shStringSpecial	skipwhite skipnl nextgroup=shCaseBar	contained
454endif
455syn region  shCaseSingleQuote	matchgroup=shQuote start=+'+ end=+'+		contains=shStringSpecial		skipwhite skipnl nextgroup=shCaseBar	contained
456syn region  shCaseDoubleQuote	matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+	contains=@shDblQuoteList,shStringSpecial	skipwhite skipnl nextgroup=shCaseBar	contained
457syn region  shCaseCommandSub	start=+`+ skip=+\\\\\|\\.+ end=+`+		contains=@shCommandSubList		skipwhite skipnl nextgroup=shCaseBar	contained
458call s:GenerateBracketExpressionItems({'itemGroup': 'shCaseRange', 'bracketGroup': 'shBracketExprDelim', 'extraArgs': 'skip=+\\\\+ contained'})
459if exists("b:is_bash")
460    syn match   shCharClass	"\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]"	contained
461elseif exists("b:is_kornshell")
462    syn match   shCharClass	"\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]"	contained
463endif
464" Misc: {{{1
465"======
466syn match   shWrapLineOperator "\\$"
467syn region  shCommandSubBQ   	start="`" skip="\\\\\|\\." end="`"	contains=shBQComment,@shCommandSubList
468syn match   shEscape	contained	'\%(^\)\@!\%(\\\\\)*\\.'
469
470" $() and $(()): {{{1
471" $(..) is not supported by sh (Bourne shell).  However, apparently
472" some systems (HP?) have as their /bin/sh a (link to) Korn shell
473" (ie. Posix compliant shell).  /bin/ksh should work for those
474" systems too, however, so the following syntax will flag $(..) as
475" an Error under /bin/sh.  By consensus of vimdev'ers!
476if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix")
477    syn region shCommandSub matchgroup=shCmdSubRegion start="\$((\@!"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList
478    if exists("b:is_kornshell")
479        if !exists("b:is_ksh88")
480            if exists("b:is_mksh")
481	syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n]"  skip='\\\\\|\\.' end="\zs[ \t\n;]}"  contains=@shCommandSubList
482            else
483	syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n<]"  skip='\\\\\|\\.' end="\zs[ \t\n;]}"  contains=@shCommandSubList
484            endif
485        endif
486        if exists("b:is_mksh") || exists("b:generic_korn")
487            syn region shValsub matchgroup=shCmdSubRegion start="\${|"  skip='\\\\\|\\.' end="}"  contains=@shCommandSubList
488        endif
489    elseif exists("b:is_bash")
490        syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n]"  skip='\\\\\|\\.' end="\zs[;\n][ \t\n]*}"  contains=@shCommandSubList
491        syn region shValsub matchgroup=shCmdSubRegion start="\${|"  skip='\\\\\|\\.' end="[;\n][ \t\n]*}"  contains=@shCommandSubList
492    endif
493    syn region shArithmetic matchgroup=shArithRegion  start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
494    syn region shArithmetic matchgroup=shArithRegion  start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList
495    syn match  shSkipInitWS contained	"^\s\+"
496    syn region shArithParen matchgroup=shArithRegion  contained start="(" end=")" contains=@shArithParenList
497else
498    ShDefSynErrRule syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
499endif
500syn region shCmdParenRegion matchgroup=shCmdSubRegion start="((\@!" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
501
502if exists("b:is_bash")
503    syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
504    syn cluster shCaseList add=bashAdminStatement,bashStatement
505    syn keyword bashSpecialVariables contained auto_resume BASH BASH_ALIASES BASH_ARGC BASH_ARGV BASH_CMDS BASH_COMMAND BASH_ENV BASH_EXECUTION_STRING BASH_LINENO BASHOPTS BASHPID BASH_REMATCH BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION BASH_XTRACEFD CDPATH COLUMNS COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS COPROC COPROC_PID DIRSTACK EMACS ENV EUID FCEDIT FIGNORE FUNCNAME FUNCNEST GLOBIGNORE GROUPS histchars HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HISTTIMEFORMAT HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LINENO LINES MACHTYPE MAIL MAILCHECK MAILPATH MAPFILE OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS POSIXLY_CORRECT PPID PROMPT_COMMAND PS0 PS1 PS2 PS3 PS4 PWD RANDOM READLINE_LINE READLINE_POINT REPLY SECONDS SHELL SHELLOPTS SHLVL TIMEFORMAT TIMEOUT TMPDIR UID
506    syn keyword bashStatement bind builtin caller compgen complete compopt declare dirs disown enable fg help history let logout mapfile popd pushd readarray shopt source suspend time
507    syn keyword bashStatement typeset nextgroup=shSetOption
508    syn keyword bashAdminStatement reload restart start status stop
509endif
510
511" for all kornshells
512if exists("b:is_kornshell")
513    syn cluster shCaseList add=kshStatement
514    syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
515    syn keyword kshSpecialVariables contained CDPATH COLUMNS EDITOR ENV FCEDIT FIGNORE FPATH HISTCMD HISTEDIT HISTFILE HISTSIZE HOME IFS JOBMAX KSH_VERSION LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME LINENO LINES MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL SHLVL TMOUT VISUAL
516    syn keyword kshStatement autoload builtin compound disown enum fg float functions hist history integer let nameref r redirect source stop suspend time whence
517    syn keyword shStatement typeset skipwhite nextgroup=shSetOption
518endif
519
520" kornshell flavors
521if exists("b:generic_korn")
522    syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME ERRNO EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID SH_OPTIONS COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMP_KEY COMPREPLY COMP_WORDBREAKS COMP_TYPE VPATH SRANDOM SYSTYPE CSWIDTH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.pid .sh.ppid .sh.tilde .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.sig.value.q .sh.sig.value.Q .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell .sh.install_prefix
523    syn keyword kshStatement alarm bind compgen complete eloop fds mkservice pids poll sha2sum vmstate xgrep
524elseif exists("b:is_ksh88")
525    syn keyword kshSpecialVariables contained ERRNO
526elseif exists("b:is_ksh93")
527    syn keyword kshSpecialVariables contained COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS CSWIDTH SH_OPTIONS SRANDOM SYSTYPE VPATH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.pid .sh.ppid .sh.tilde .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.sig.value.q .sh.sig.value.Q .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell
528    syn keyword kshStatement alarm compgen complete eloop fds mkservice pids poll sha2sum vmstate xgrep
529elseif exists("b:is_ksh93v")
530    syn keyword kshSpecialVariables contained COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS CSWIDTH SH_OPTIONS VPATH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.sig.value.q .sh.sig.value.Q .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell
531    syn keyword kshStatement alarm compgen complete fds pids poll sha2sum vmstate xgrep
532elseif exists("b:is_ksh93u")
533    syn keyword kshSpecialVariables contained CSWIDTH SYSTYPE VPATH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.dollar .sh.pool .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell
534    syn keyword kshStatement alarm fds pids vmstate
535elseif exists("b:is_ksh2020")
536    syn keyword kshSpecialVariables contained COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS SH_OPTIONS .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell .sh.install_prefix
537    syn keyword kshStatement compgen complete
538elseif exists("b:is_mksh")
539    syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID
540    syn keyword kshStatement bind
541endif
542
543syn match   shSource	"^\.\s"
544syn match   shSource	"\s\.\s"
545if exists("b:is_kornshell") || exists("b:is_posix")
546    syn match   shColon	'^\s*\zs:'
547endif
548
549" String And Character Constants: {{{1
550"================================
551syn match   shNumber	"\<\d\+\>#\="
552syn match   shNumber	"\<-\=\.\=\d\+\>#\="
553syn match   shCtrlSeq	"\\\d\d\d\|\\[abcfnrtv0]"			contained
554if exists("b:is_bash") || exists("b:is_kornshell")
555    syn match   shSpecial	"[^\\]\(\\\\\)*\zs\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]"	contained
556    syn match   shSpecial	"^\(\\\\\)*\zs\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]"	contained
557    syn region  shExSingleQuote	matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+	contains=shStringSpecial,shSpecial		nextgroup=shSpecialNxt
558    syn region  shExDoubleQuote	matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+	contains=@shDblQuoteList,shStringSpecial,shSpecial	nextgroup=shSpecialNxt
559else
560    ShDefSynErrRule syn region  shExSingleQuote	matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+	contains=shStringSpecial
561    ShDefSynErrRule syn region  shExDoubleQuote	matchgroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+	contains=shStringSpecial
562endif
563syn region  shSingleQuote	matchgroup=shQuote start=+'+ end=+'+		contains=@Spell	nextgroup=shSpecialStart,shSpecialSQ
564syn region  shDoubleQuote	matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\.+ end=+"+			contains=@shDblQuoteList,shStringSpecial,@Spell	nextgroup=shSpecialStart
565syn match   shStringSpecial	"[^[:print:] \t]"			contained
566syn match   shStringSpecial	"[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+"			nextgroup=shComment
567syn match   shSpecialSQ	"[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+"		contained	nextgroup=shBkslshSnglQuote,@shNoZSList
568syn match   shSpecialDQ	"[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+"		contained	nextgroup=shBkslshDblQuote,@shNoZSList
569syn match   shSpecialStart	"\%(\\\\\)*\\[\\"'`$()#]"			contained	nextgroup=shBkslshSnglQuote,shBkslshDblQuote,@shNoZSList
570syn match   shSpecial	"^\%(\\\\\)*\\[\\"'`$()#]"
571syn match   shSpecialNoZS	contained	"\%(\\\\\)*\\[\\"'`$()#]"
572syn match   shSpecialNxt	contained	"\\[\\"'`$()#]"
573
574" Comments: {{{1
575"==========
576syn cluster	shCommentGroup	contains=shTodo,@Spell
577if exists("b:is_bash")
578    syn match	shTodo	contained		"\<\%(COMBAK\|FIXME\|TODO\|XXX\)\ze:\=\>"
579else
580    syn keyword	shTodo	contained		COMBAK FIXME TODO XXX
581endif
582syn match	shComment		"^\s*\zs#.*$"	contains=@shCommentGroup
583syn match	shComment		"\s\zs#.*$"	contains=@shCommentGroup
584syn match	shComment	contained	"#.*$"	contains=@shCommentGroup
585syn match	shQuickComment	contained	"#.*$"          contains=@shCommentGroup
586syn match	shBQComment	contained	"#.\{-}\ze`"	contains=@shCommentGroup
587
588" Here Documents: {{{1
589"  (modified by Felipe Contreras)
590" =========================================
591ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\z([^ \t|>]\+\)"		matchgroup=shHereDoc01 end="^\z1$"	contains=@shDblQuoteList
592ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\z([^ \t|>]\+\)"		matchgroup=shHereDoc02 end="^\t*\z1$"	contains=@shDblQuoteList
593ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc03 start="<<\s*\\\z([^ \t|>]\+\)"		matchgroup=shHereDoc03 end="^\z1$"
594ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc04 start="<<-\s*\\\z([^ \t|>]\+\)"		matchgroup=shHereDoc04 end="^\t*\z1$"
595ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc05 start="<<\s*'\z([^']\+\)'"		matchgroup=shHereDoc05 end="^\z1$"
596ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc06 start="<<-\s*'\z([^']\+\)'"		matchgroup=shHereDoc06 end="^\t*\z1$"
597ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc07 start="<<\s*\"\z([^"]\+\)\""		matchgroup=shHereDoc07 end="^\z1$"
598ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc08 start="<<-\s*\"\z([^"]\+\)\""		matchgroup=shHereDoc08 end="^\t*\z1$"
599ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc09 start="<<\s*\\\_$\_s*\z([^ \t|>]\+\)"		matchgroup=shHereDoc09 end="^\z1$"	contains=@shDblQuoteList
600ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc10 start="<<-\s*\\\_$\_s*\z([^ \t|>]\+\)"	matchgroup=shHereDoc10 end="^\t*\z1$"	contains=@shDblQuoteList
601ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc11 start="<<\s*\\\_$\_s*\\\z([^ \t|>]\+\)"	matchgroup=shHereDoc11 end="^\z1$"
602ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc12 start="<<-\s*\\\_$\_s*\\\z([^ \t|>]\+\)"	matchgroup=shHereDoc12 end="^\t*\z1$"
603ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc13 start="<<\s*\\\_$\_s*'\z([^']\+\)'"		matchgroup=shHereDoc13 end="^\z1$"
604ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc14 start="<<-\s*\\\_$\_s*'\z([^']\+\)'"		matchgroup=shHereDoc14 end="^\t*\z1$"
605ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc15 start="<<\s*\\\_$\_s*\"\z([^"]\+\)\""		matchgroup=shHereDoc15 end="^\z1$"
606ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc16 start="<<-\s*\\\_$\_s*\"\z([^"]\+\)\""	matchgroup=shHereDoc16 end="^\t*\z1$"
607
608
609" Here Strings: {{{1
610" =============
611" available for: bash and ksh (except ksh88) but not if its a posix
612if exists("b:is_bash") || ((exists("b:is_kornshell") && !exists("b:is_ksh88")) && !exists("b:is_posix"))
613    syn match shHereString "<<<"	skipwhite	nextgroup=shCmdParenRegion
614endif
615
616" Identifiers: {{{1
617"=============
618syn match  shSetOption	"\s\zs[-+][a-zA-Z0-9]\+\>"	contained
619syn match  shVariable	"\<\h\w*\ze="			nextgroup=shVarAssign
620if exists("b:is_bash")
621    " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)".
622    syn region  shArrayValue	contained	start="\[\%(..\{-}\]=\)\@=" end="\]=\@="	contains=@shArrayValueList nextgroup=shVarAssign
623    syn cluster shArrayValueList	contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,bashSpecialVariables,shParenError
624    syn region  shArrayRegion	contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment
625elseif (exists("b:is_kornshell") && !exists("b:is_ksh88"))
626    " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)".
627    syn region  shArrayValue	contained	start="\[\%(..\{-}\]=\)\@=" end="\]=\@="	contains=@shArrayValueList nextgroup=shVarAssign
628    syn cluster shArrayValueList	contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,kshSpecialVariables,shParenError
629    syn region  shArrayRegion	contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment,shArrayRegion
630endif
631if exists("b:is_bash") || exists("b:is_kornshell")
632    syn match shVariable	"\<\h\w*\%(\[..\{-}\]\)\=\ze\%([|^&*/%+-]\|[<^]<\|[>^]>\)\=="	contains=shDerefVarArray nextgroup=shVarAssign
633    syn match shVarAssign	contained	"\%([|^&*/%+-]\|[<^]<\|[>^]>\)\=="	nextgroup=shArrayRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar
634else
635    syn match  shVarAssign	contained	"="	nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar
636endif
637syn match  shVar	contained	"\h\w*"
638syn region shAtExpr	contained	start="@(" end=")" contains=@shIdList
639if exists("b:is_bash")
640    syn match  shSet "^\s*set\ze\s\+$"
641    syn region shSetList oneline matchgroup=shSet start="\<\%(declare\|local\|export\)\>\ze[/a-zA-Z_]\@!" end="$"		matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+#\|="	contains=@shIdList
642    syn region shSetList oneline matchgroup=shSet start="\<\%(set\|unset\)\>[/a-zA-Z_]\@!" end="\ze[;|#)]\|$"		matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+="	contains=@shIdList nextgroup=shComment
643elseif exists("b:is_kornshell") || exists("b:is_posix")
644    syn match  shSet "^\s*set\ze\s\+$"
645    if exists("b:is_dash")
646        syn region shSetList oneline matchgroup=shSet start="\<\%(local\)\>\ze[/]\@!" end="$"			matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]"	contains=@shIdList
647        syn keyword shStatement chdir
648    endif
649    syn region shSetList oneline matchgroup=shSet start="\<\(export\)\>\ze[/]\@!" end="$"			matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]"	contains=@shIdList
650    syn region shSetList oneline matchgroup=shSet start="\<\%(set\|unset\>\)\ze[/a-zA-Z_]\@!" end="\ze[;|#)]\|$"		matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]"	contains=@shIdList nextgroup=shComment
651else
652    syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[/a-zA-Z_]\@!" end="\ze[;|#)]\|$"	matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]"	contains=@shIdList
653endif
654
655" KornShell namespace: {{{1
656if exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh")
657    syn keyword shFunctionKey namespace	skipwhite nextgroup=shNamespaceOne
658endif
659
660" Functions: {{{1
661if !exists("b:is_posix")
662    syn match shFunctionKeyDelim "\s\+"	contained transparent nextgroup=shDoError,shIfError,shFunctionNameCommentError,shFunctionTwo,shFunctionFour,shFunctionCmdTwo
663    syn match shFunctionKey "\<function\s\@="	nextgroup=shFunctionKeyDelim
664endif
665
666ShFoldFunctions syn region shFunctionExpr	matchgroup=shFunctionExprRegion start="{"	end="}"	contains=@shFunctionList	 contained skipwhite skipnl nextgroup=shQuickComment
667ShFoldFunctions syn region shFunctionSubSh	matchgroup=shFunctionSubShRegion start="("	end=")"	contains=@shFunctionList	 contained skipwhite skipnl nextgroup=shQuickComment
668
669syn match shFunctionParens	"()" contained
670
671if exists("b:is_bash")
672    syn keyword shFunctionKey coproc
673    syn match shFunctionCmdOne	"\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"	skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
674    syn match shFunctionCmdTwo	"\%#=1\%(\%(\<\k\+\>\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\s*\%(()\ze\)\=\_s*\%(\<\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"	contained skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
675    syn match shFunctionOne	"\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*{"	skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
676    syn match shFunctionThree	"\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*((\@!"	skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
677    " Proof against future changes by inducing priority-driven "backtracking"
678    " between shFunctionFour (goes before) and shFunctionTwo (goes after) so
679    " that e.g. "function f () {}" is still claimed by shFunctionTwo (observe
680    " "f[[:blank:]]()").
681    syn match shFunctionFour	"\%#=1\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\%(\%(\s*()\ze\)\=\)\@>\_s*((\@!"	contained skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
682    syn match shFunctionTwo	"\%#=1\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\%(\%(\s*()\ze\)\=\)\@>\_s*{"	contained skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
683    " Claim empty array assignments.
684    syn match shArrayEmptyDecl	"\%#=1\ze\%(\<\h\w*=\)\@>()"	transparent nextgroup=shVariable
685    " Claim commented out function declaration headers.
686    syn match shFunctionComment	"^\s*\zs\ze#"	transparent nextgroup=shComment
687    ShDefSynErrRule syn match shFunctionNameAssignError	"\%#=1\%(\%(\<\h\w*\)\@>=\)\%(\%(\w\+\)\@>=\=\)\+()"	skipwhite skipnl nextgroup=shExpr,shSubSh
688    ShDefSynErrRule syn match shFunctionNameCommentError	"#"	contained
689elseif exists("b:is_ksh88")
690    " AT&T ksh88
691    syn match shFunctionCmdOne	"^\s*\zs\h\w*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"	skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
692    syn match shFunctionOne	"^\s*\zs\h\w*\s*()\ze\_s*{"	skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
693    syn match shFunctionTwo	"\<\h\w*\>\ze\_s*{"	contained skipwhite skipnl nextgroup=shFunctionExpr
694    syn match shFunctionThree	"^\s*\zs\h\w*\s*()\ze\_s*((\@!"	skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
695elseif exists("b:is_mksh")
696    " MirBSD ksh is the wild west of absurd and abstruse function names...
697    syn match shFunctionCmdOne	"^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"	skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
698    syn match shFunctionOne	"^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*{"	skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
699    syn match shFunctionTwo	"\%#=1\%(\%(\<\w\+\|[@!+.%,:-]\+\)*[-A-Za-z_.%,0-9:]\)\@>\ze\s*\%(()\ze\)\=\_s*{"	contained skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
700    syn match shFunctionThree	"^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*((\@!"	skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
701elseif exists("b:is_kornshell")
702    " ksh93
703    syn match shFunctionCmdOne	"^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"	skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
704    syn match shFunctionOne	"^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*{"	skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
705    syn match shFunctionTwo	"\%(\<\h\+\|\.\)[A-Za-z_.0-9]*\ze\_s*{"	contained skipwhite skipnl nextgroup=shFunctionExpr
706    syn match shFunctionThree	"^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*((\@!"	skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
707    syn match shNamespaceOne	"\<\h\w*\>\ze\_s*{"	contained skipwhite skipnl nextgroup=shFunctionExpr
708else
709    syn match shFunctionCmdOne	"^\s*\zs\h\w*\s*()\ze\_s*\%(for\|case\|if\|while\|until\)\>"	skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
710    syn match shFunctionCmdTwo	"\<\h\w*\s*()\ze\_s*\%(for\|case\|if\|while\|until\)\>"	contained skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens
711    syn match shFunctionOne	"^\s*\zs\h\w*\s*()\ze\_s*{"	skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
712    syn match shFunctionTwo	"\<\h\w*\>\s*()\ze\_s*{"	contained skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens
713    syn match shFunctionThree	"^\s*\zs\h\w*\s*()\ze\_s*("	skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
714    syn match shFunctionFour	"\<\h\w*\>\s*()\ze\_s*("	contained skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens
715endif
716
717ShDefSynErrRule syn match   shDoError "\<do\%(ne\)\=\s*()"
718ShDefSynErrRule syn match   shIfError "\<then\s*()"
719ShDefSynErrRule syn match   shIfError "\<else\s*()"
720
721" Parameter Dereferencing: {{{1
722" ========================
723ShDefSynErrRule syn match  shDerefWordError	"[^}$[~]"	contained
724syn match  shDerefSimple	"\$\%(\h\w*\|\d\)"	nextgroup=@shNoZSList
725if exists("b:is_kornshell") && !exists("b:is_ksh88")
726    if exists("b:is_mksh")
727        syn region shDeref	matchgroup=PreProc start="\${\ze[^ \t\n|]" end="}"	contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart
728    elseif exists("b:generic_korn")
729        syn region shDeref	matchgroup=PreProc start="\${\ze[^ \t\n<|]" end="}"	contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart
730    else
731        syn region shDeref	matchgroup=PreProc start="\${\ze[^ \t\n<]" end="}"	contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart
732    endif
733elseif exists("b:is_bash")
734    syn region shDeref	matchgroup=PreProc start="\${\ze[^ \t\n|]" end="}"	contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart
735else
736    syn region shDeref	matchgroup=PreProc start="\${" end="}"			contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart
737endif
738syn match  shDerefSimple	"\$[-#*@!?]"	nextgroup=@shNoZSList
739syn match  shDerefSimple	"\$\$"	nextgroup=@shNoZSList
740syn match  shDerefSimple	"\${\d}"	nextgroup=@shNoZSList	nextgroup=shSpecialStart
741if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix")
742    syn region shDeref	matchgroup=PreProc start="\${##\=" end="}"	contains=@shDerefList	nextgroup=@shSpecialNoZS,shSpecialStart
743    syn region shDeref	matchgroup=PreProc start="\${\$\$" end="}"	contains=@shDerefList	nextgroup=@shSpecialNoZS,shSpecialStart
744endif
745
746" ksh: ${.sh.*} variables: {{{1
747" ========================================
748if exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh")
749    syn match  shDerefVar	contained	"\.\+"	nextgroup=@shDerefVarList
750    syn region shDeref	matchgroup=PreProc start="\${\ze[\.]" end="}"	contains=@shDerefVarList,shDerefPSR,shDerefPPS
751endif
752
753" ksh: ${!var[*]} array index list syntax: {{{1
754" ========================================
755if (exists("b:is_kornshell") && !exists("b:is_ksh88")) || exists("b:is_posix")
756    syn region shDeref	matchgroup=PreProc start="\${!" end="}"	contains=@shDerefVarArray
757endif
758
759" bash: ${!prefix*} and ${#parameter}: {{{1
760" ====================================
761if exists("b:is_bash")
762    syn region shDeref	matchgroup=PreProc start="\${!" end="\*\=}"	contains=@shDerefList,shDerefOffset
763    syn match  shDerefVar	contained	"{\@<=!\h\w*"		nextgroup=@shDerefVarList
764    syn match  shDerefSpecial	contained	"\({!\)\@<=[[:alnum:]*#@_]\+"	nextgroup=@shDerefVarList,shDerefOp
765endif
766if (exists("b:is_kornshell") && !exists("b:is_ksh88"))
767    syn match  shDerefVar	contained	"{\@<=!\h\w*[[:alnum:]_.]*"	nextgroup=@shDerefVarList
768    syn match  shDerefSpecial	contained	"\({!\)\@<=[[:alnum:]*#@_]\+"	nextgroup=@shDerefVarList,shDerefOp
769endif
770
771syn match  shDerefSpecial	contained	"{\@<=[-*@?0]"		nextgroup=shDerefOp,shDerefOffset,shDerefOpError
772syn match  shDerefSpecial	contained	"\({[#]\)\@<=[[:alnum:]*@_]\+"	nextgroup=@shDerefVarList,shDerefOp
773syn match  shDerefVar	contained	"{\@<=\h\w*"		nextgroup=@shDerefVarList
774syn match  shDerefVar	contained	'\d'                            nextgroup=@shDerefVarList
775if exists("b:is_kornshell") || exists("b:is_posix")
776    syn match  shDerefVar	contained	"{\@<=\h\w*[[:alnum:]_.]*"	nextgroup=@shDerefVarList
777endif
778
779" sh ksh bash : ${var[... ]...}  array reference: {{{1
780syn region  shDerefVarArray   contained	matchgroup=shDeref start="\[" end="]"	contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError,shDerefOffset
781
782" Special ${parameter OPERATOR word} handling: {{{1
783" sh ksh bash : ${parameter:-word}    word is default value
784" sh ksh bash : ${parameter:=word}    assign word as default value
785" sh ksh bash : ${parameter:?word}    display word if parameter is null
786" sh ksh bash : ${parameter:+word}    use word if parameter is not null, otherwise nothing
787"    ksh bash : ${parameter#pattern}  remove small left  pattern
788"    ksh bash : ${parameter##pattern} remove large left  pattern
789"    ksh bash : ${parameter%pattern}  remove small right pattern
790"    ksh bash : ${parameter%%pattern} remove large right pattern
791"    ksh bash : ${parameter^pattern}  Case modification
792"    ksh bash : ${parameter^^pattern} Case modification
793"    ksh bash : ${parameter,pattern}  Case modification
794"    ksh bash : ${parameter,,pattern} Case modification
795"        bash : ${@:start:qty}        display command line arguments from start to start+qty-1 (inferred)
796"        bash : ${parameter@operator} transforms parameter (operator∈[uULqEPARa])
797syn cluster shDerefPatternList	contains=shDerefPattern,shDerefString
798ShDefSynErrRule syn match shDerefOpError	contained	":[[:punct:]]"
799syn match  shDerefOp	contained	":\=[-=?]"	nextgroup=@shDerefPatternList
800syn match  shDerefOp	contained	":\=+"	nextgroup=@shDerefPatternList
801if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix")
802    syn match  shDerefOp	contained	"#\{1,2}"		nextgroup=@shDerefPatternList
803    syn match  shDerefOp	contained	"%\{1,2}"		nextgroup=@shDerefPatternList
804    syn match  shDerefPattern	contained	"[^{}]\+"		contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern skipnl
805    syn region shDerefPattern	contained	start="{" end="}"	contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
806    " Match parametric bracket expressions with a leading whitespace character.
807    syn region shDerefPattern	contained	matchgroup=shBracketExprDelim start="\[" end="\]"	contains=@shBracketExprList,shDoubleQuote nextgroup=shDerefPattern
808    call s:GenerateBracketExpressionItems({'itemGroup': 'shDerefPattern', 'bracketGroup': 'shBracketExprDelim', 'extraArgs': 'contained nextgroup=shDerefPattern'})
809    syn match  shDerefEscape	contained	'\%(\\\\\)*\\.'
810endif
811if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") && !exists("b:is_ksh93u") && !exists("b:is_ksh2020"))
812    syn match  shDerefOp	contained	"[,^]\{1,2}"	nextgroup=@shDerefPatternList
813endif
814if exists("b:is_bash")
815    syn match  shDerefOp	contained	"@[uULQEPAKa]"
816endif
817syn region shDerefString	contained	matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+
818syn region shDerefString	contained	matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+	contains=@shDblQuoteList,shStringSpecial
819syn match  shDerefString	contained	"\\["']"	nextgroup=shDerefPattern
820
821if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) || exists("b:is_posix")
822    " bash ksh posix : ${parameter:offset}
823    " bash ksh posix : ${parameter:offset:length}
824    syn region shDerefOffset	contained	start=':[^-=?+]' end='\ze:'	end='\ze}'	contains=shDeref,shDerefSimple,shDerefEscape	nextgroup=shDerefLen,shDeref,shDerefSimple
825    syn region shDerefOffset	contained	start=':\s-'	end='\ze:'	end='\ze}'	contains=shDeref,shDerefSimple,shDerefEscape	nextgroup=shDerefLen,shDeref,shDerefSimple
826    syn match  shDerefLen	contained	":[^}]\+"	contains=shDeref,shDerefSimple,shArithmetic
827endif
828
829if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88"))
830    " bash ksh : ${parameter/pattern/string}
831    " bash ksh : ${parameter//pattern/string}
832    syn match  shDerefPPS	contained	'/\{1,2}'	nextgroup=shDerefPPSleft
833    syn region shDerefPPSleft	contained	start='.'	skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp	end='/' end='\ze}' end='"'	nextgroup=shDerefPPSright	contains=@shPPSLeftList
834    syn region shDerefPPSright	contained	start='.'	skip=@\%(\\\\\)\+@		end='\ze}'				contains=@shPPSRightList
835
836    " bash ksh : ${parameter/#pattern/string}
837    " bash ksh : ${parameter/%pattern/string}
838    syn match  shDerefPSR	contained	'/[#%]'	nextgroup=shDerefPSRleft,shDoubleQuote,shSingleQuote
839    syn region shDerefPSRleft	contained	start='[^"']'	skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp	end='/' end='\ze}'	nextgroup=shDerefPSRright	contains=shBracketExpr
840    syn region shDerefPSRright	contained	start='.'	skip=@\%(\\\\\)\+@		end='\ze}'
841endif
842
843" Arithmetic Parenthesized Expressions: {{{1
844"syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList
845syn region shParen matchgroup=shArithRegion start='\$\@!(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList
846
847" Additional sh Keywords: {{{1
848" ===================
849" builtins:
850syn keyword shStatement bg break cd continue command eval exec exit export fc getopts hash jobs local printf read readonly return shift times trap type ulimit umask unalias wait
851" external programs:
852syn keyword shStatement basename cat chgrp chmod chown cksum clear cmp comm cp cut date dirname du egrep expr false fgrep find fmt fold getconf grep head iconv id join kill killall less ln login logname ls md5sum mkdir mkfifo mknod mktemp mv newgrp nice nohup od paste pathchk printenv pwd readlink realpath rename rev rm rmdir sed sha1sum sha224sum sha256sum sha384sum sha512sum sleep sort strip stty sum sync tail tee test tput tr true tty uname uniq wc which xargs
853syn keyword shConditional contained elif else then
854ShDefSynErrRule syn keyword shCondError elif else then
855
856" Synchronization: {{{1
857" ================
858if !exists("g:sh_minlines")
859    let s:sh_minlines = 200
860else
861    let s:sh_minlines= g:sh_minlines
862endif
863if !exists("g:sh_maxlines")
864    let s:sh_maxlines = 2*s:sh_minlines
865    if s:sh_maxlines < 25
866        let s:sh_maxlines= 25
867    endif
868else
869    let s:sh_maxlines= g:sh_maxlines
870endif
871exec "syn sync minlines=" . s:sh_minlines . " maxlines=" . s:sh_maxlines
872syn sync match shCaseEsacSync	grouphere	shCaseEsac	"\<case\>"
873syn sync match shCaseEsacSync	groupthere	shCaseEsac	"\<esac\>"
874syn sync match shDoSync	grouphere	shDo	"\<do\>"
875syn sync match shDoSync	groupthere	shDo	"\<done\>"
876syn sync match shForSync	grouphere	shFor	"\<for\>"
877syn sync match shForSync	groupthere	shFor	"\<in\>"
878syn sync match shIfSync	grouphere	shIf	"\<if\>"
879syn sync match shIfSync	groupthere	shIf	"\<fi\>"
880syn sync match shUntilSync	grouphere	shRepeat	"\<until\>"
881syn sync match shWhileSync	grouphere	shRepeat	"\<while\>"
882
883" Default Highlighting: {{{1
884" =====================
885if !exists("skip_sh_syntax_inits")
886    hi def link shArithRegion	shShellVariables
887    hi def link shArrayValue	shDeref
888    hi def link shAstQuote	shDoubleQuote
889    hi def link shAtExpr	shSetList
890    hi def link shBkslshSnglQuote	shSingleQuote
891    hi def link shBkslshDblQuote	shDOubleQuote
892    hi def link shBeginHere	shRedir
893    hi def link shCaseBar	shConditional
894    hi def link shCaseCommandSub	shCommandSub
895    hi def link shCaseDoubleQuote	shDoubleQuote
896    hi def link shCaseIn	shConditional
897    hi def link shQuote	shOperator
898    hi def link shCaseSingleQuote	shSingleQuote
899    hi def link shCaseStart	shConditional
900    hi def link shCmdSubRegion	shShellVariables
901    hi def link shColon	shComment
902    hi def link shDerefOp	shOperator
903    hi def link shDerefPOL	shDerefOp
904    hi def link shDerefPPS	shDerefOp
905    hi def link shDerefPSR	shDerefOp
906    hi def link shDeref	shShellVariables
907    hi def link shDerefDelim	shOperator
908    hi def link shDerefSimple	shDeref
909    hi def link shDerefSpecial	shDeref
910    hi def link shDerefString	shDoubleQuote
911    hi def link shDerefVar	shDeref
912    hi def link shDoubleQuote	shString
913    hi def link shEcho	shString
914    hi def link shEchoDelim	shOperator
915    hi def link shEchoQuote	shString
916    hi def link shForPP	shLoop
917    hi def link shEmbeddedEcho	shString
918    hi def link shEscape	shCommandSub
919    hi def link shExDoubleQuote	shDoubleQuote
920    hi def link shExSingleQuote	shSingleQuote
921    hi def link shHereDoc	shString
922    hi def link shHereString	shRedir
923    hi def link shHerePayload	shHereDoc
924    hi def link shLoop	shStatement
925    hi def link shSpecialNxt	shSpecial
926    hi def link shNoQuote	shDoubleQuote
927    hi def link shOption	shCommandSub
928    hi def link shPattern	shString
929    hi def link shParen	shArithmetic
930    hi def link shPosnParm	shShellVariables
931    hi def link shQuickComment	shComment
932    hi def link shBQComment	shComment
933    hi def link shRange	shOperator
934    hi def link shRedir	shOperator
935    hi def link shSetListDelim	shOperator
936    hi def link shSetOption	shOption
937    hi def link shSingleQuote	shString
938    hi def link shSource	shOperator
939    hi def link shStringSpecial	shSpecial
940    hi def link shSpecialStart	shSpecial
941    hi def link shSubShRegion	shOperator
942    hi def link shTestOpr	shConditional
943    hi def link shTestPattern	shString
944    hi def link shTestDoubleQuote	shString
945    hi def link shTestSingleQuote	shString
946    hi def link shTouchCmd	shStatement
947    hi def link shVariable	shSetList
948    hi def link shWrapLineOperator	shOperator
949
950    if exists("b:is_bash")
951        hi def link bashAdminStatement	shStatement
952        hi def link bashSpecialVariables	shShellVariables
953        hi def link bashStatement		shStatement
954        hi def link shCharClass		shSpecial
955        hi def link shDerefOffset		shDerefOp
956        hi def link shDerefLen		shDerefOffset
957    endif
958    if exists("b:is_kornshell") || exists("b:is_posix")
959        hi def link kshSpecialVariables	shShellVariables
960        hi def link kshStatement		shStatement
961    endif
962
963    ShLinkSynErrGroup hi def link shCaseError		Error
964    ShLinkSynErrGroup hi def link shCondError		Error
965    ShLinkSynErrGroup hi def link shCurlyError		Error
966    ShLinkSynErrGroup hi def link shDerefOpError		Error
967    ShLinkSynErrGroup hi def link shDerefWordError		Error
968    ShLinkSynErrGroup hi def link shDoError		Error
969    ShLinkSynErrGroup hi def link shEsacError		Error
970    ShLinkSynErrGroup hi def link shIfError		Error
971    ShLinkSynErrGroup hi def link shInError		Error
972    ShLinkSynErrGroup hi def link shParenError		Error
973    ShLinkSynErrGroup hi def link shTestError		Error
974    if exists("b:is_bash")
975        ShLinkSynErrGroup hi def link shFunctionNameAssignError	Error
976        ShLinkSynErrGroup hi def link shFunctionNameCommentError	Error
977    endif
978    if exists("b:is_kornshell") || exists("b:is_posix")
979        ShLinkSynErrGroup hi def link shDTestError		Error
980    endif
981
982    hi def link shArithmetic		Special
983    hi def link shBracketExprDelim		Delimiter
984    hi def link shCharClass		Identifier
985    hi def link shCollSymb		shCharClass
986    hi def link shEqClass		shCharClass
987    hi def link shSnglCase		Statement
988    hi def link shCommandSub		Special
989    hi def link shCommandSubBQ		shCommandSub
990    hi def link shSubshare		shCommandSub
991    hi def link shValsub		shCommandSub
992    hi def link shComment		Comment
993    hi def link shConditional		Conditional
994    hi def link shCtrlSeq		Special
995    hi def link shExprRegion		Delimiter
996    hi def link shFunctionKey		Keyword
997    hi def link shFunctionParens	Delimiter
998    hi def link shFunctionOne		Function
999    hi def link shFunctionTwo		shFunctionOne
1000    hi def link shFunctionThree		shFunctionOne
1001    hi def link shFunctionFour		shFunctionOne
1002    hi def link shFunctionCmdOne	shFunctionOne
1003    hi def link shFunctionCmdTwo	shFunctionOne
1004    hi def link shFunctionExprRegion	shExprRegion
1005    hi def link shFunctionSubShRegion	shSubShRegion
1006    hi def link shNamespaceOne		Function
1007    hi def link shNumber		Number
1008    hi def link shOperator		Operator
1009    hi def link shRepeat		Repeat
1010    hi def link shSet		Statement
1011    hi def link shSetList		Identifier
1012    hi def link shShellVariables		PreProc
1013    hi def link shSpecial		Special
1014    hi def link shSpecialDQ		Special
1015    hi def link shSpecialSQ		Special
1016    hi def link shSpecialNoZS		shSpecial
1017    hi def link shStatement		Statement
1018    hi def link shString		String
1019    hi def link shTodo		Todo
1020    hi def link shAlias		Identifier
1021    hi def link shHereDoc01		shRedir
1022    hi def link shHereDoc02		shRedir
1023    hi def link shHereDoc03		shRedir
1024    hi def link shHereDoc04		shRedir
1025    hi def link shHereDoc05		shRedir
1026    hi def link shHereDoc06		shRedir
1027    hi def link shHereDoc07		shRedir
1028    hi def link shHereDoc08		shRedir
1029    hi def link shHereDoc09		shRedir
1030    hi def link shHereDoc10		shRedir
1031    hi def link shHereDoc11		shRedir
1032    hi def link shHereDoc12		shRedir
1033    hi def link shHereDoc13		shRedir
1034    hi def link shHereDoc14		shRedir
1035    hi def link shHereDoc15		shRedir
1036    hi def link shHereDoc16		shRedir
1037endif
1038
1039" Delete shell commands {{{1
1040" =====================
1041delc ShFoldFunctions
1042delc ShFoldHereDoc
1043delc ShFoldIfDoFor
1044delc ShLinkSynErrGroup
1045delc ShDefSynErrRule
1046
1047" Delete shell functions {{{1
1048" ======================
1049delfun s:ScanAndCondExecSynErrCmd
1050delfun s:GenerateBracketExpressionItems
1051
1052" Set Current Syntax: {{{1
1053" ===================
1054if exists("b:is_bash")
1055    let b:current_syntax = "bash"
1056elseif exists("b:is_kornshell")
1057    let b:current_syntax = "ksh"
1058elseif exists("b:is_posix")
1059    let b:current_syntax = "posix"
1060else
1061    let b:current_syntax = "sh"
1062endif
1063
1064" vim: ts=16 fdm=marker