1" Vim syntax file 2" Language: C-shell (tcsh) 3" Maintainer: Gautam Iyer <[email protected]> 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 16if exists("b:current_syntax") 17 finish 18endif 19 20syn case match 21 22" ----- Clusters ----- 23syn cluster tcshModifiers contains=tcshModifier,tcshModifierError 24syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote 25syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,tcshUsrVar,TcshArgv,tcshSubst,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArguement 26syn cluster tcshStatements contains=tcshBuiltins,tcshCommands,tcshSet,tcshSetEnv,tcshAlias,tcshIf,tcshWhile 27syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst 28 29" ----- Statements ----- 30" Tcsh commands: Any filename / modifiable variable (must be first!) 31syn 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 34syn 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) 38syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltins start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds 39 40" set expressions (Contains shell variables) 41syn 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 42syn keyword tcshSet nextgroup=tcshSetEnd set unset 43syn region tcshSetEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshShellVar,@tcshStatementEnds 44 45" setenv expressions (Contains enviorenment variables) 46syn 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 47syn keyword tcshSetEnv nextgroup=tcshEnvEnd setenv unsetenv 48syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshEnvVar,@tcshStatementEnds 49 50" alias and unalias (contains special aliases) 51syn keyword tcshAliases contained beepcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell 52syn keyword tcshAlias nextgroup=tcshAliCmd skipwhite alias unalias 53syn match tcshAliCmd contained nextgroup=tcshAliEnd skipwhite '\v[\w-]+' contains=tcshAliases 54syn region tcshAliEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=@tcshStatementEnds 55 56" if statements (contains expressions / operators) 57syn keyword tcshIf nextgroup=tcshIfEnd if 58syn region tcshIfEnd contained matchgroup=tcshBuiltins start='' skip="\\$" end="\v<then>|$" contains=tcshOperator,tcshNumber,@tcshStatementEnds 59 60" else statements (nextgroup if) 61syn keyword tcshElse nextgroup=tcshIf skipwhite else 62 63" while statements (contains expressions / operators) 64syn keyword tcshWhile nextgroup=tcshWhEnd while 65syn region tcshWhEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="\v$" contains=tcshOperator,tcshNumber,@tcshStatementEnds 66 67" Expressions start with @. 68syn match tcshExprStart "\v\@\s+" nextgroup=tcshExprVar 69syn match tcshExprVar contained "\v\h\w*%(\[\d+\])?" contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp 70syn match tcshExprOp contained "++\|--" 71syn match tcshExprOp contained "\v\s*\=" nextgroup=tcshExprEnd 72syn match tcshExprEnd contained "\v.*$"hs=e+1 contains=tcshOperator,tcshNumber,@tcshVarList 73syn match tcshExprEnd contained "\v.{-};"hs=e contains=tcshOperator,tcshNumber,@tcshVarList 74 75" ----- Comments: ----- 76syn match tcshComment '#\s.*' contains=tcshTodo,tcshCommentTi,@Spell 77syn match tcshComment '\v#($|\S.*)' contains=tcshTodo,tcshCommentTi 78syn match tcshSharpBang '^#! .*$' 79syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo 80syn 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 88if(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 92else 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 96endif 97 98" ----- Variables ----- 99" Variable Errors. Must come first! \$ constructs will be flagged by 100" tcshSpecial, so we don't consider them here. 101syn match tcshVarError '\v\$\S*' contained 102 103" Modifiable Variables without {}. 104syn match tcshUsrVar contained "\v\$\h\w*%(\[\d+%(-\d+)?\])?" nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar 105syn match tcshArgv contained "\v\$%(\d+|\*)" nextgroup=@tcshModifiers 106 107" Modifiable Variables with {}. 108syn match tcshUsrVar contained "\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}" contains=@tcshModifiers,tcshShellVar,tcshEnvVar 109syn match tcshArgv contained "\v\$\{%(\d+|\*)%(:\S*)?\}" contains=@tcshModifiers 110 111" UnModifiable Substitutions. Order is important here. 112syn match tcshSubst contained "\v\$[?#$!_<]" nextgroup=tcshModifierError 113syn match tcshSubst contained "\v\$[%#?]%(\h\w*|\d+)" nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar 114syn match tcshSubst contained "\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}" contains=tcshModifierError contains=tcshShellVar,tcshEnvVar 115 116" Variable Name Expansion Modifiers (order important) 117syn match tcshModifierError contained '\v:\S*' 118syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers 119 120" ----- Operators / Specials ----- 121" Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!] 122syn match tcshRedir contained "\v\<|\>\>?\&?!?" 123 124" Metachars 125syn match tcshMeta contained "\v[]{}*?[]" 126 127" Here Documents (<<) 128syn region tcshHereDoc contained matchgroup=tcshRedir start="\v\<\<\s*\z(\h\w*)" end="^\z1$" contains=@tcshVarList,tcshSpecial 129syn 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 132syn match tcshOperator contained "&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||" 133syn match tcshOperator contained "[(){}]" 134 135" Numbers 136syn match tcshNumber contained "\v<-?\d+>" 137 138" Arguements 139syn match tcshArguement contained "\v\s@<=-(\w|-)*" 140 141" Special charectors 142syn match tcshSpecial contained "\v\\@<!\\(\d{3}|.)" 143 144" ----- Syncronising ----- 145if exists("tcsh_minlines") 146 exec "syn sync minlines=" . tcsh_minlines 147else 148 syn sync minlines=15 " Except 'here' documents, nothing is long 149endif 150 151" Define highlighting of syntax groups 152hi def link tcshBuiltins statement 153hi def link tcshShellVar preproc 154hi def link tcshEnvVar tcshShellVar 155hi def link tcshAliases tcshShellVar 156hi def link tcshAliCmd identifier 157hi def link tcshCommands identifier 158hi def link tcshSet tcshBuiltins 159hi def link tcshSetEnv tcshBuiltins 160hi def link tcshAlias tcshBuiltins 161hi def link tcshIf tcshBuiltins 162hi def link tcshElse tcshBuiltins 163hi def link tcshWhile tcshBuiltins 164hi def link tcshExprStart tcshBuiltins 165hi def link tcshExprVar tcshUsrVar 166hi def link tcshExprOp tcshOperator 167hi def link tcshExprEnd tcshOperator 168hi def link tcshComment comment 169hi def link tcshCommentTi preproc 170hi def link tcshSharpBang tcshCommentTi 171hi def link tcshTodo todo 172hi def link tcshSQuote constant 173hi def link tcshDQuote tcshSQuote 174hi def link tcshBQuoteGrp include 175hi def link tcshVarError error 176hi def link tcshUsrVar type 177hi def link tcshArgv tcshUsrVar 178hi def link tcshSubst tcshUsrVar 179hi def link tcshModifier tcshArguement 180hi def link tcshModifierError tcshVarError 181hi def link tcshMeta tcshSubst 182hi def link tcshRedir tcshOperator 183hi def link tcshHereDoc tcshSQuote 184hi def link tcshOperator operator 185hi def link tcshNumber number 186hi def link tcshArguement special 187hi def link tcshSpecial specialchar 188 189let b:current_syntax = "tcsh" 190