2 " Language: C-shell (csh)
3 " Maintainer: Dr. Charles E. Campbell, Jr. <Charles.E.Campbell.1@gsfc.nasa.gov>
5 " Last Change: September 19, 2000
7 " For version 5.x: Clear all syntax items
8 " For version 6.x: Quit when a syntax file was already loaded
11 elseif exists("b:current_syntax")
16 syn cluster cshQuoteList contains=cshDblQuote,cshSnglQuote,cshBckQuote
18 " Variables which affect the csh itself
19 syn match cshSetVariables contained "argv\|histchars\|ignoreeof\|noglob\|prompt\|status"
20 syn match cshSetVariables contained "cdpath\|history\|mail\|nonomatch\|savehist\|time"
21 syn match cshSetVariables contained "cwd\|home\|noclobber\|path\|shell\|verbose"
22 syn match cshSetVariables contained "echo"
25 syn keyword cshTodo contained todo
28 " Variable Name Expansion Modifiers
29 syn match cshModifier contained ":\(h\|t\|r\|q\|x\|gh\|gt\|gr\)"
31 " Strings and Comments
32 syn match cshNoEndlineDQ contained "[^\"]\(\\\\\)*$"
33 syn match cshNoEndlineSQ contained "[^\']\(\\\\\)*$"
34 syn match cshNoEndlineBQ contained "[^\`]\(\\\\\)*$"
36 syn region cshDblQuote start=+[^\\]"+lc=1 skip=+\\\\\|\\"+ end=+"+ contains=cshSpecial,cshShellVariables,cshExtVar,cshSelector,cshQtyWord,cshArgv,cshSubst,cshNoEndlineDQ,cshBckQuote
37 syn region cshSnglQuote start=+[^\\]'+lc=1 skip=+\\\\\|\\'+ end=+'+ contains=cshNoEndlineSQ
38 syn region cshBckQuote start=+[^\\]`+lc=1 skip=+\\\\\|\\`+ end=+`+ contains=cshNoEndlineBQ
39 syn region cshDblQuote start=+^"+ skip=+\\\\\|\\"+ end=+"+ contains=cshSpecial,cshExtVar,cshSelector,cshQtyWord,cshArgv,cshSubst,cshNoEndlineDQ
40 syn region cshSnglQuote start=+^'+ skip=+\\\\\|\\'+ end=+'+ contains=cshNoEndlineSQ
41 syn region cshBckQuote start=+^`+ skip=+\\\\\|\\`+ end=+`+ contains=cshNoEndlineBQ
42 syn cluster cshCommentGroup contains=cshTodo
43 syn match cshComment "#.*$" contains=@cshCommentGroup
45 " A bunch of useful csh keywords
46 syn keyword cshStatement alias end history onintr setenv unalias
47 syn keyword cshStatement cd eval kill popd shift unhash
48 syn keyword cshStatement chdir exec login pushd source
49 syn keyword cshStatement continue exit logout rehash time unsetenv
50 syn keyword cshStatement dirs glob nice repeat umask wait
51 syn keyword cshStatement echo goto nohup
53 syn keyword cshConditional break case else endsw switch
54 syn keyword cshConditional breaksw default endif
55 syn keyword cshRepeat foreach
57 " Special environment variables
58 syn keyword cshShellVariables HOME LOGNAME PATH TERM USER
60 " Modifiable Variables without {}
61 syn match cshExtVar "\$[a-zA-Z_][a-zA-Z0-9_]*\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=" contains=cshModifier
62 syn match cshSelector "\$[a-zA-Z_][a-zA-Z0-9_]*\[[a-zA-Z_]\+\]\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=" contains=cshModifier
63 syn match cshQtyWord "\$#[a-zA-Z_][a-zA-Z0-9_]*\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=" contains=cshModifier
64 syn match cshArgv "\$\d\+\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=" contains=cshModifier
65 syn match cshArgv "\$\*\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=" contains=cshModifier
67 " Modifiable Variables with {}
68 syn match cshExtVar "\${[a-zA-Z_][a-zA-Z0-9_]*\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=}" contains=cshModifier
69 syn match cshSelector "\${[a-zA-Z_][a-zA-Z0-9_]*\[[a-zA-Z_]\+\]\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=}" contains=cshModifier
70 syn match cshQtyWord "\${#[a-zA-Z_][a-zA-Z0-9_]*\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=}" contains=cshModifier
71 syn match cshArgv "\${\d\+\(:h\|:t\|:r\|:q\|:x\|:gh\|:gt\|:gr\)\=}" contains=cshModifier
73 " UnModifiable Substitutions
74 syn match cshSubstError "\$?[a-zA-Z_][a-zA-Z0-9_]*:\(h\|t\|r\|q\|x\|gh\|gt\|gr\)"
75 syn match cshSubstError "\${?[a-zA-Z_][a-zA-Z0-9_]*:\(h\|t\|r\|q\|x\|gh\|gt\|gr\)}"
76 syn match cshSubstError "\$?[0$<]:\(h\|t\|r\|q\|x\|gh\|gt\|gr\)"
77 syn match cshSubst "\$?[a-zA-Z_][a-zA-Z0-9_]*"
78 syn match cshSubst "\${?[a-zA-Z_][a-zA-Z0-9_]*}"
79 syn match cshSubst "\$?[0$<]"
82 syn match cshRedir ">>&!\|>&!\|>>&\|>>!\|>&\|>!\|>>\|<<\|>\|<"
84 " Handle set expressions
85 syn keyword cshSetStmt contained set unset
86 syn region cshSetExpr transparent start="set\|unset" end="$\|;" contains=cshSetVariables,cshSetStmt,@cshQuoteList
88 " Operators and Expression-Using constructs
89 syn keyword cshExprUsing contained if while exit then
90 syn match cshOperator contained "\(&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|\|%\|&\|+\|-\|/\|<\|>\||\)"
91 syn match cshOperator contained "[(){}]"
92 syn region cshTest transparent start="if\|while\|exit" skip="\\$" end="$\|;\|then" contains=cshOperator,cshExprUsing,@cshQuoteList
95 " Highlight special characters (those which have a backslash) differently
96 syn match cshSpecial contained "\\\d\d\d\|\\[abcfnrtv\\]"
97 syn match cshNumber "-\=\<\d\+\>"
99 " All other identifiers
100 "syn match cshIdentifier "\<[a-zA-Z._][a-zA-Z0-9._]*\>"
102 " Shell Input Redirection (Here Documents)
104 syn region cshHereDoc matchgroup=cshRedir start="<<-\=\s*\**END[a-zA-Z_0-9]*\**" matchgroup=cshRedir end="^END[a-zA-Z_0-9]*$"
105 syn region cshHereDoc matchgroup=cshRedir start="<<-\=\s*\**EOF\**" matchgroup=cshRedir end="^EOF$"
107 syn region cshHereDoc matchgroup=cshRedir start="<<-\=\s*\**\z(\h\w*\)\**" matchgroup=cshRedir end="^\z1$"
110 " Define the default highlighting.
111 " For version 5.7 and earlier: only when not done already
112 " For version 5.8 and later: only when an item doesn't have highlighting yet
113 if version >= 508 || !exists("did_csh_syntax_inits")
115 let did_csh_syntax_inits = 1
116 command -nargs=+ HiLink hi link <args>
118 command -nargs=+ HiLink hi def link <args>
121 HiLink cshArgv cshVariables
122 HiLink cshBckQuote cshCommand
123 HiLink cshDblQuote cshString
124 HiLink cshExprUsing cshStatement
125 HiLink cshExtVar cshVariables
126 HiLink cshHereDoc cshString
127 HiLink cshNoEndlineBQ cshNoEndline
128 HiLink cshNoEndlineDQ cshNoEndline
129 HiLink cshNoEndlineSQ cshNoEndline
130 HiLink cshQtyWord cshVariables
131 HiLink cshRedir cshOperator
132 HiLink cshSelector cshVariables
133 HiLink cshSetStmt cshStatement
134 HiLink cshSetVariables cshVariables
135 HiLink cshSnglQuote cshString
136 HiLink cshSubst cshVariables
138 HiLink cshCommand Statement
139 HiLink cshComment Comment
140 HiLink cshConditional Conditional
141 HiLink cshIdentifier Error
142 HiLink cshModifier Special
143 HiLink cshNoEndline Error
144 HiLink cshNumber Number
145 HiLink cshOperator Operator
146 HiLink cshRedir Statement
147 HiLink cshRepeat Repeat
148 HiLink cshShellVariables Special
149 HiLink cshSpecial Special
150 HiLink cshStatement Statement
151 HiLink cshString String
152 HiLink cshSubstError Error
154 HiLink cshVariables Type
159 let b:current_syntax = "csh"