xref: /vim-8.2.3635/runtime/syntax/tcsh.vim (revision 2e258bd7)
1" tcsh.vim: Vim syntax file for tcsh scripts
2" Maintainer: Doug Kearns <[email protected]> where NoSpam=gmail
3" Author: Gautam Iyer <[email protected]> where NoSpam=gmail
4" Modified: Sun 26 Sep 2021 12:40:55 PM EDT
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
16if exists('b:current_syntax')
17  finish
18endif
19
20let s:oldcpo = &cpo
21set cpo&vim " Line continuation is used
22
23setlocal iskeyword+=-
24
25syn case match
26
27" ----- Clusters -----
28syn cluster tcshModifiers	contains=tcshModifier,tcshModifierError
29syn cluster tcshQuoteList	contains=tcshDQuote,tcshSQuote,tcshBQuote
30syn cluster tcshStatementEnds	contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArguement
31syn cluster tcshStatements	contains=tcshBuiltin,tcshCommands,tcshIf,tcshWhile
32syn cluster tcshVarList		contains=tcshUsrVar,tcshArgv,tcshSubst
33syn cluster tcshConditions	contains=tcshCmdSubst,tcshParenExpr,tcshOperator,tcshNumber,@tcshVarList
34
35" ----- Errors -----
36" Define first, so can be easily overridden.
37syn match tcshError contained '\v\S.+'
38
39" ----- Statements -----
40" Tcsh commands: Any filename / modifiable variable (must be first!)
41syn match tcshCommands	'\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
42
43" Builtin commands except those treated specially. Currently (un)set(env),
44" (un)alias, if, while, else, bindkey
45syn keyword tcshBuiltin nextgroup=tcshStatementEnd alloc bg 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
46
47" StatementEnd is anything after a built-in / command till the lexical end of a
48" statement (;, |, ||, |&, && or end of line)
49syn region tcshStatementEnd	transparent contained matchgroup=tcshBuiltin start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
50
51" set expressions (Contains shell variables)
52syn 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
53syn keyword tcshBuiltin	nextgroup=tcshSetEnd set unset
54syn region  tcshSetEnd	contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshShellVar,@tcshStatementEnds
55
56" setenv expressions (Contains environment variables)
57syn 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
58syn keyword tcshBuiltin	nextgroup=tcshEnvEnd setenv unsetenv
59syn region  tcshEnvEnd	contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=tcshEnvVar,@tcshStatementEnds
60
61" alias and unalias (contains special aliases)
62syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
63syn keyword tcshBuiltin	nextgroup=tcshAliCmd skipwhite alias unalias
64syn match   tcshAliCmd	contained nextgroup=tcshAliEnd skipwhite '\v(\w|-)+' contains=tcshAliases
65syn region  tcshAliEnd	contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$\|;' contains=@tcshStatementEnds
66
67" if statements
68syn keyword tcshIf	nextgroup=tcshIfEnd skipwhite if
69syn region  tcshIfEnd	contained start='\S' skip='\\$' matchgroup=tcshBuiltin end='\v<then>|$' contains=@tcshConditions,tcshSpecial,@tcshStatementEnds
70syn region  tcshIfEnd	contained matchgroup=tcshBuiltin contains=@tcshConditions,tcshSpecial start='(' end='\v\)%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds
71syn region  tcshIfEnd	contained matchgroup=tcshBuiltin contains=tcshCommands,tcshSpecial start='\v\{\s+' end='\v\s+\}%(\s+then>)?' skipwhite nextgroup=@tcshStatementEnds keepend
72
73" else statements
74syn keyword tcshBuiltin	nextgroup=tcshIf skipwhite else
75
76" while statements (contains expressions / operators)
77syn keyword tcshBuiltin	nextgroup=@tcshConditions,tcshSpecial skipwhite while
78
79" Conditions (for if and while)
80syn region tcshParenExpr contained contains=@tcshConditions,tcshSpecial matchgroup=tcshBuiltin start='(' end=')'
81syn region tcshCmdSubst  contained contains=tcshCommands matchgroup=tcshBuiltin start='\v\{\s+' end='\v\s+\}' keepend
82
83" Bindkey. Internal editor functions
84syn keyword tcshBindkeyFuncs contained backward-char backward-delete-char
85	    \ backward-delete-word backward-kill-line backward-word
86	    \ beginning-of-line capitalize-word change-case
87	    \ change-till-end-of-line clear-screen complete-word
88	    \ complete-word-fwd complete-word-back complete-word-raw
89	    \ copy-prev-word copy-region-as-kill dabbrev-expand delete-char
90	    \ delete-char-or-eof delete-char-or-list
91	    \ delete-char-or-list-or-eof delete-word digit digit-argument
92	    \ down-history downcase-word end-of-file end-of-line
93	    \ exchange-point-and-mark expand-glob expand-history expand-line
94	    \ expand-variables forward-char forward-word
95	    \ gosmacs-transpose-chars history-search-backward
96	    \ history-search-forward insert-last-word i-search-fwd
97	    \ i-search-back keyboard-quit kill-line kill-region
98	    \ kill-whole-line list-choices list-choices-raw list-glob
99	    \ list-or-eof load-average magic-space newline normalize-path
100	    \ normalize-command overwrite-mode prefix-meta quoted-insert
101	    \ redisplay run-fg-editor run-help self-insert-command
102	    \ sequence-lead-in set-mark-command spell-word spell-line
103	    \ stuff-char toggle-literal-history transpose-chars
104	    \ transpose-gosling tty-dsusp tty-flush-output tty-sigintr
105	    \ tty-sigquit tty-sigtsusp tty-start-output tty-stop-output
106	    \ undefined-key universal-argument up-history upcase-word
107	    \ vi-beginning-of-next-word vi-add vi-add-at-eol vi-chg-case
108	    \ vi-chg-meta vi-chg-to-eol vi-cmd-mode vi-cmd-mode-complete
109	    \ vi-delprev vi-delmeta vi-endword vi-eword vi-char-back
110	    \ vi-char-fwd vi-charto-back vi-charto-fwd vi-insert
111	    \ vi-insert-at-bol vi-repeat-char-fwd vi-repeat-char-back
112	    \ vi-repeat-search-fwd vi-repeat-search-back vi-replace-char
113	    \ vi-replace-mode vi-search-back vi-search-fwd vi-substitute-char
114	    \ vi-substitute-line vi-word-back vi-word-fwd vi-undo vi-zero
115	    \ which-command yank yank-pop e_copy_to_clipboard
116	    \ e_paste_from_clipboard e_dosify_next e_dosify_prev e_page_up
117	    \ e_page_down
118syn keyword tcshBuiltin nextgroup=tcshBindkeyEnd bindkey
119syn region tcshBindkeyEnd contained transparent matchgroup=tcshBuiltin start='' skip='\\$' end='$' contains=@tcshQuoteList,tcshComment,@tcshVarList,tcshMeta,tcshSpecial,tcshArguement,tcshBindkeyFuncs
120
121" Expressions start with @.
122syn match tcshExprStart '\v\@\s+' nextgroup=tcshExprVar
123syn match tcshExprVar	contained '\v\h\w*%(\[\d+\])?' contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
124syn match tcshExprOp	contained '++\|--'
125syn match tcshExprOp	contained '\v\s*\=' nextgroup=tcshExprEnd
126syn match tcshExprEnd	contained '\v.*$'hs=e+1 contains=@tcshConditions
127syn match tcshExprEnd	contained '\v.{-};'hs=e	contains=@tcshConditions
128
129" ----- Comments: -----
130syn match tcshComment	'#\s.*' contains=tcshTodo,tcshCommentTi,@Spell
131syn match tcshComment	'\v#($|\S.*)' contains=tcshTodo,tcshCommentTi
132syn match tcshSharpBang '^#! .*$'
133syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
134syn match tcshTodo	contained '\v\c<todo>'
135
136" ----- Strings -----
137" Tcsh does not allow \" in strings unless the "backslash_quote" shell
138" variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
139" want VIM to assume that no backslash quote constructs exist.
140
141" Backquotes are treated as commands, and are not contained in anything
142if(exists('tcsh_backslash_quote') && tcsh_backslash_quote == 0)
143    syn region tcshSQuote	keepend contained start="\v\\@<!'" end="'"
144    syn region tcshDQuote	keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
145    syn region tcshBQuote	keepend start='\v\\@<!`' end='`' contains=@tcshStatements
146else
147    syn region tcshSQuote	contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'"
148    syn region tcshDQuote	contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
149    syn region tcshBQuote	keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
150endif
151
152" ----- Variables -----
153" Variable Errors. Must come first! \$ constructs will be flagged by
154" tcshSpecial, so we don't consider them here.
155syn match tcshVarError	'\v\$\S*'	contained
156
157" Modifiable Variables without {}.
158syn match tcshUsrVar contained '\v\$\h\w*%(\[\d+%(-\d+)?\])?' nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
159syn match tcshArgv   contained '\v\$%(\d+|\*)' nextgroup=@tcshModifiers
160
161" Modifiable Variables with {}.
162syn match tcshUsrVar contained '\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}' contains=@tcshModifiers,tcshShellVar,tcshEnvVar
163syn match tcshArgv   contained '\v\$\{%(\d+|\*)%(:\S*)?\}' contains=@tcshModifiers
164
165" Un-modifiable Substitutions. Order is important here.
166syn match tcshSubst contained	'\v\$[?#$!_<]' nextgroup=tcshModifierError
167syn match tcshSubst contained	'\v\$[%#?]%(\h\w*|\d+)' nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
168syn match tcshSubst contained	'\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}' contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
169
170" Variable Name Expansion Modifiers (order important)
171syn match tcshModifierError	contained '\v:\S*'
172syn match tcshModifier		contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
173
174" ----- Operators / Specials -----
175" Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
176syn match tcshRedir contained	'\v\<|\>\>?\&?!?'
177
178" Meta-chars
179syn match tcshMeta  contained	'\v[]{}*?[]'
180
181" Here documents (<<)
182syn region tcshHereDoc contained matchgroup=tcshShellVar start='\v\<\<\s*\z(\h\w*)' end='^\z1$' contains=@tcshVarList,tcshSpecial
183syn region tcshHereDoc contained matchgroup=tcshShellVar start="\v\<\<\s*'\z(\h\w*)'" start='\v\<\<\s*"\z(\h\w*)"$' start='\v\<\<\s*\\\z(\h\w*)$' end='^\z1$'
184
185" Operators
186syn match tcshOperator	contained '&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||'
187"syn match tcshOperator	contained '[(){}]'
188
189" Numbers
190syn match tcshNumber	contained '\v<-?\d+>'
191
192" Arguments
193syn match tcshArguement	contained '\v\s@<=-(\w|-)*'
194
195" Special characters. \xxx, or backslashed characters.
196"syn match tcshSpecial	contained '\v\\@<!\\(\d{3}|.)'
197syn match tcshSpecial	contained '\v\\%([0-7]{3}|.)'
198
199" ----- Synchronising -----
200if exists('tcsh_minlines')
201    if tcsh_minlines == 'fromstart'
202	syn sync fromstart
203    else
204	exec 'syn sync minlines=' . tcsh_minlines
205    endif
206else
207    syn sync minlines=100	" Some completions can be quite long
208endif
209
210" Define highlighting of syntax groups
211hi def link tcshError		Error
212hi def link tcshBuiltin		Statement
213hi def link tcshShellVar	Preproc
214hi def link tcshEnvVar		tcshShellVar
215hi def link tcshAliases		tcshShellVar
216hi def link tcshAliCmd		Identifier
217hi def link tcshCommands	Identifier
218hi def link tcshIf		tcshBuiltin
219hi def link tcshWhile		tcshBuiltin
220hi def link tcshBindkeyFuncs	Function
221hi def link tcshExprStart	tcshBuiltin
222hi def link tcshExprVar		tcshUsrVar
223hi def link tcshExprOp		tcshOperator
224hi def link tcshExprEnd		tcshOperator
225hi def link tcshComment		Comment
226hi def link tcshCommentTi	Preproc
227hi def link tcshSharpBang	tcshCommentTi
228hi def link tcshTodo		Todo
229hi def link tcshSQuote		Constant
230hi def link tcshDQuote		tcshSQuote
231hi def link tcshBQuoteGrp	Include
232hi def link tcshVarError	Error
233hi def link tcshUsrVar		Type
234hi def link tcshArgv		tcshUsrVar
235hi def link tcshSubst		tcshUsrVar
236hi def link tcshModifier	tcshArguement
237hi def link tcshModifierError	tcshVarError
238hi def link tcshMeta		tcshSubst
239hi def link tcshRedir		tcshOperator
240hi def link tcshHereDoc		tcshSQuote
241hi def link tcshOperator	Operator
242hi def link tcshNumber		Number
243hi def link tcshArguement	Special
244hi def link tcshSpecial		SpecialChar
245
246let &cpo = s:oldcpo
247unlet s:oldcpo
248
249let b:current_syntax = 'tcsh'
250