0
|
1 " Vim syntax file
|
|
2 " Language: C-shell (tcsh)
|
|
3 " Maintainer: Gautam Iyer <gi1242@users.sourceforge.net>
|
|
4 " Last Modified: Thu 16 Nov 2006 01:07:04 PM PST
|
|
5 "
|
|
6 " Description: We break up each statement into a "command" and an "end" part.
|
|
7 " All groups are either a "command" or part of the "end" of a statement (ie
|
|
8 " everything after the "command"). This is because blindly highlighting tcsh
|
|
9 " statements as keywords caused way too many false positives. Eg:
|
|
10 "
|
|
11 " set history=200
|
|
12 "
|
|
13 " causes history to come up as a keyword, which we want to avoid.
|
|
14
|
|
15 " Quit when a syntax file was already loaded
|
|
16 if exists("b:current_syntax")
|
|
17 finish
|
|
18 endif
|
|
19
|
|
20 syn case match
|
|
21
|
|
22 " ----- Clusters -----
|
|
23 syn cluster tcshModifiers contains=tcshModifier,tcshModifierError
|
|
24 syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote
|
|
25 syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,tcshUsrVar,TcshArgv,tcshSubst,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArguement
|
|
26 syn cluster tcshStatements contains=tcshBuiltins,tcshCommands,tcshSet,tcshSetEnv,tcshAlias,tcshIf,tcshWhile
|
|
27 syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst
|
|
28
|
|
29 " ----- Statements -----
|
|
30 " Tcsh commands: Any filename / modifiable variable (must be first!)
|
|
31 syn match tcshCommands '\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
|
|
32
|
|
33 " Builtin commands except (un)set(env), (un)alias, if, while, else
|
|
34 syn keyword tcshBuiltins nextgroup=tcshStatementEnd alloc bg bindkey break breaksw builtins bye case cd chdir complete continue default dirs echo echotc end endif endsw eval exec exit fg filetest foreach getspath getxvers glob goto hashstat history hup inlib jobs kill limit log login logout ls ls-F migrate newgrp nice nohup notify onintr popd printenv pushd rehash repeat rootnode sched setpath setspath settc setty setxvers shift source stop suspend switch telltc time umask uncomplete unhash universe unlimit ver wait warp watchlog where which
|
|
35
|
|
36 " StatementEnd is anything after a builtin / command till the lexical end of a
|
|
37 " statement (;, |, ||, |&, && or end of line)
|
|
38 syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltins start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
|
|
39
|
|
40 " set expressions (Contains shell variables)
|
|
41 syn keyword tcshShellVar contained afsuser ampm argv autocorrect autoexpand autolist autologout backslash_quote catalog cdpath color colorcat command complete continue continue_args correct cwd dextract dirsfile dirstack dspmbyte dunique echo echo_style edit ellipsis fignore filec gid group histchars histdup histfile histlit history home ignoreeof implicitcd inputmode killdup killring listflags listjobs listlinks listmax listmaxrows loginsh logout mail matchbeep nobeep noclobber noding noglob nokanji nonomatch nostat notify oid owd path printexitvalue prompt prompt2 prompt3 promptchars pushdtohome pushdsilent recexact recognize_only_executables rmstar rprompt savedirs savehist sched shell shlvl status symlinks tcsh term time tperiod tty uid user verbose version visiblebell watch who wordchars
|
|
42 syn keyword tcshSet nextgroup=tcshSetEnd set unset
|
|
43 syn region tcshSetEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshShellVar,@tcshStatementEnds
|
|
44
|
|
45 " setenv expressions (Contains enviorenment variables)
|
|
46 syn keyword tcshEnvVar contained AFSUSER COLUMNS DISPLAY EDITOR GROUP HOME HOST HOSTTYPE HPATH LANG LC_CTYPE LINES LS_COLORS MACHTYPE NOREBIND OSTYPE PATH PWD REMOTEHOST SHLVL SYSTYPE TERM TERMCAP USER VENDOR VISUAL
|
|
47 syn keyword tcshSetEnv nextgroup=tcshEnvEnd setenv unsetenv
|
|
48 syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshEnvVar,@tcshStatementEnds
|
|
49
|
|
50 " alias and unalias (contains special aliases)
|
|
51 syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
|
|
52 syn keyword tcshAlias nextgroup=tcshAliCmd skipwhite alias unalias
|
|
53 syn match tcshAliCmd contained nextgroup=tcshAliEnd skipwhite '\v[\w-]+' contains=tcshAliases
|
|
54 syn region tcshAliEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=@tcshStatementEnds
|
|
55
|
|
56 " if statements (contains expressions / operators)
|
|
57 syn keyword tcshIf nextgroup=tcshIfEnd if
|
|
58 syn region tcshIfEnd contained matchgroup=tcshBuiltins start='' skip="\\$" end="\v<then>|$" contains=tcshOperator,tcshNumber,@tcshStatementEnds
|
|
59
|
|
60 " else statements (nextgroup if)
|
|
61 syn keyword tcshElse nextgroup=tcshIf skipwhite else
|
|
62
|
|
63 " while statements (contains expressions / operators)
|
|
64 syn keyword tcshWhile nextgroup=tcshWhEnd while
|
|
65 syn region tcshWhEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="\v$" contains=tcshOperator,tcshNumber,@tcshStatementEnds
|
|
66
|
|
67 " Expressions start with @.
|
|
68 syn match tcshExprStart "\v\@\s+" nextgroup=tcshExprVar
|
|
69 syn match tcshExprVar contained "\v\h\w*%(\[\d+\])?" contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
|
|
70 syn match tcshExprOp contained "++\|--"
|
|
71 syn match tcshExprOp contained "\v\s*\=" nextgroup=tcshExprEnd
|
|
72 syn match tcshExprEnd contained "\v.*$"hs=e+1 contains=tcshOperator,tcshNumber,@tcshVarList
|
|
73 syn match tcshExprEnd contained "\v.{-};"hs=e contains=tcshOperator,tcshNumber,@tcshVarList
|
|
74
|
|
75 " ----- Comments: -----
|
|
76 syn match tcshComment '#\s.*' contains=tcshTodo,tcshCommentTi,@Spell
|
|
77 syn match tcshComment '\v#($|\S.*)' contains=tcshTodo,tcshCommentTi
|
|
78 syn match tcshSharpBang '^#! .*$'
|
|
79 syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
|
|
80 syn match tcshTodo contained '\v\c<todo>'
|
|
81
|
|
82 " ----- Strings -----
|
|
83 " Tcsh does not allow \" in strings unless the "backslash_quote" shell
|
|
84 " variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
|
|
85 " want VIM to assume that no backslash quote constructs exist.
|
|
86
|
|
87 " Backquotes are treated as commands, and are not contained in anything
|
|
88 if(exists("tcsh_backslash_quote") && tcsh_backslash_quote == 0)
|
|
89 syn region tcshSQuote keepend contained start="\v\\@<!'" end="'" contains=@Spell
|
|
90 syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
|
|
91 syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements
|
|
92 else
|
|
93 syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'" contains=@Spell
|
|
94 syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
|
|
95 syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
|
|
96 endif
|
|
97
|
|
98 " ----- Variables -----
|
|
99 " Variable Errors. Must come first! \$ constructs will be flagged by
|
|
100 " tcshSpecial, so we don't consider them here.
|
|
101 syn match tcshVarError '\v\$\S*' contained
|
|
102
|
|
103 " Modifiable Variables without {}.
|
|
104 syn match tcshUsrVar contained "\v\$\h\w*%(\[\d+%(-\d+)?\])?" nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
|
|
105 syn match tcshArgv contained "\v\$%(\d+|\*)" nextgroup=@tcshModifiers
|
|
106
|
|
107 " Modifiable Variables with {}.
|
|
108 syn match tcshUsrVar contained "\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}" contains=@tcshModifiers,tcshShellVar,tcshEnvVar
|
|
109 syn match tcshArgv contained "\v\$\{%(\d+|\*)%(:\S*)?\}" contains=@tcshModifiers
|
|
110
|
|
111 " UnModifiable Substitutions. Order is important here.
|
|
112 syn match tcshSubst contained "\v\$[?#$!_<]" nextgroup=tcshModifierError
|
|
113 syn match tcshSubst contained "\v\$[%#?]%(\h\w*|\d+)" nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
|
|
114 syn match tcshSubst contained "\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}" contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
|
|
115
|
|
116 " Variable Name Expansion Modifiers (order important)
|
|
117 syn match tcshModifierError contained '\v:\S*'
|
|
118 syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
|
|
119
|
|
120 " ----- Operators / Specials -----
|
|
121 " Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
|
|
122 syn match tcshRedir contained "\v\<|\>\>?\&?!?"
|
|
123
|
|
124 " Metachars
|
|
125 syn match tcshMeta contained "\v[]{}*?[]"
|
|
126
|
|
127 " Here Documents (<<)
|
|
128 syn region tcshHereDoc contained matchgroup=tcshRedir start="\v\<\<\s*\z(\h\w*)" end="^\z1$" contains=@tcshVarList,tcshSpecial
|
|
129 syn region tcshHereDoc contained matchgroup=tcshRedir start="\v\<\<\s*'\z(\h\w*)'" start='\v\<\<\s*"\z(\h\w*)"$' start="\v\<\<\s*\\\z(\h\w*)$" end="^\z1$"
|
|
130
|
|
131 " Operators
|
|
132 syn match tcshOperator contained "&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||"
|
|
133 syn match tcshOperator contained "[(){}]"
|
|
134
|
|
135 " Numbers
|
|
136 syn match tcshNumber contained "\v<-?\d+>"
|
|
137
|
|
138 " Arguements
|
|
139 syn match tcshArguement contained "\v\s@<=-(\w|-)*"
|
|
140
|
|
141 " Special charectors
|
|
142 syn match tcshSpecial contained "\v\\@<!\\(\d{3}|.)"
|
|
143
|
|
144 " ----- Syncronising -----
|
|
145 if exists("tcsh_minlines")
|
|
146 exec "syn sync minlines=" . tcsh_minlines
|
|
147 else
|
|
148 syn sync minlines=15 " Except 'here' documents, nothing is long
|
|
149 endif
|
|
150
|
|
151 " Define highlighting of syntax groups
|
|
152 hi def link tcshBuiltins statement
|
|
153 hi def link tcshShellVar preproc
|
|
154 hi def link tcshEnvVar tcshShellVar
|
|
155 hi def link tcshAliases tcshShellVar
|
|
156 hi def link tcshAliCmd identifier
|
|
157 hi def link tcshCommands identifier
|
|
158 hi def link tcshSet tcshBuiltins
|
|
159 hi def link tcshSetEnv tcshBuiltins
|
|
160 hi def link tcshAlias tcshBuiltins
|
|
161 hi def link tcshIf tcshBuiltins
|
|
162 hi def link tcshElse tcshBuiltins
|
|
163 hi def link tcshWhile tcshBuiltins
|
|
164 hi def link tcshExprStart tcshBuiltins
|
|
165 hi def link tcshExprVar tcshUsrVar
|
|
166 hi def link tcshExprOp tcshOperator
|
|
167 hi def link tcshExprEnd tcshOperator
|
|
168 hi def link tcshComment comment
|
|
169 hi def link tcshCommentTi preproc
|
|
170 hi def link tcshSharpBang tcshCommentTi
|
|
171 hi def link tcshTodo todo
|
|
172 hi def link tcshSQuote constant
|
|
173 hi def link tcshDQuote tcshSQuote
|
|
174 hi def link tcshBQuoteGrp include
|
|
175 hi def link tcshVarError error
|
|
176 hi def link tcshUsrVar type
|
|
177 hi def link tcshArgv tcshUsrVar
|
|
178 hi def link tcshSubst tcshUsrVar
|
|
179 hi def link tcshModifier tcshArguement
|
|
180 hi def link tcshModifierError tcshVarError
|
|
181 hi def link tcshMeta tcshSubst
|
|
182 hi def link tcshRedir tcshOperator
|
|
183 hi def link tcshHereDoc tcshSQuote
|
|
184 hi def link tcshOperator operator
|
|
185 hi def link tcshNumber number
|
|
186 hi def link tcshArguement special
|
|
187 hi def link tcshSpecial specialchar
|
|
188
|
|
189 let b:current_syntax = "tcsh"
|