1" Vim syntax file 2" Language: C-shell (tcsh) 3" Maintainor: Gautam Iyer <[email protected]> 4" Last Modified: Sat 11 Mar 2006 11:16:47 AM CST 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 beemcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell 52syn keyword tcshAlias nextgroup=tcshAliEnd alias unalias 53syn region tcshAliEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshAliases,@tcshStatementEnds 54 55" if statements (contains expressions / operators) 56syn keyword tcshIf nextgroup=tcshIfEnd if 57syn region tcshIfEnd contained matchgroup=tcshBuiltins start='' skip="\\$" end="\v<then>|$" contains=tcshOperator,tcshNumber,@tcshStatementEnds 58 59" else statements (nextgroup if) 60syn keyword tcshElse nextgroup=tcshIf skipwhite else 61 62" while statements (contains expressions / operators) 63syn keyword tcshWhile nextgroup=tcshWhEnd while 64syn region tcshWhEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="\v$" contains=tcshOperator,tcshNumber,@tcshStatementEnds 65 66" Expressions start with @. 67syn match tcshExprStart "\v\@\s+" nextgroup=tcshExprVar 68syn match tcshExprVar contained "\v\h\w*%(\[\d+\])?" contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp 69syn match tcshExprOp contained "++\|--" 70syn match tcshExprOp contained "\v\s*\=" nextgroup=tcshExprEnd 71syn match tcshExprEnd contained "\v.*$"hs=e+1 contains=tcshOperator,tcshNumber,@tcshVarList 72syn match tcshExprEnd contained "\v.{-};"hs=e contains=tcshOperator,tcshNumber,@tcshVarList 73 74" ----- Comments: ----- 75syn match tcshComment "#.*" contains=tcshTodo,tcshCommentTi,tcshCommentSp,@Spell 76syn match tcshSharpBang "^#! .*$" 77syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo 78syn match tcshCommentSp contained '\v<\u{3,}>' contains=tcshTodo 79syn match tcshTodo contained '\v\c<todo>' 80 81" ----- Strings ----- 82" Tcsh does not allow \" in strings unless the "backslash_quote" shell 83" variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you 84" want VIM to assume that no backslash quote constructs exist. 85 86" Backquotes are treated as commands, and are not contained in anything 87if(exists("tcsh_backslash_quote") && tcsh_backslash_quote == 0) 88 syn region tcshSQuote keepend contained start="\v\\@<!'" end="'" contains=@Spell 89 syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell 90 syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements 91else 92 syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'" contains=@Spell 93 syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell 94 syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements 95endif 96 97" ----- Variables ----- 98" Variable Errors. Must come first! \$ constructs will be flagged by 99" tcshSpecial, so we don't consider them here. 100syn match tcshVarError '\v\$\S*' contained 101 102" Modifiable Variables without {}. 103syn match tcshUsrVar contained "\v\$\h\w*%(\[\d+%(-\d+)?\])?" nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar 104syn match tcshArgv contained "\v\$%(\d+|\*)" nextgroup=@tcshModifiers 105 106" Modifiable Variables with {}. 107syn match tcshUsrVar contained "\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}" contains=@tcshModifiers,tcshShellVar,tcshEnvVar 108syn match tcshArgv contained "\v\$\{%(\d+|\*)%(:\S*)?\}" contains=@tcshModifiers 109 110" UnModifiable Substitutions. Order is important here. 111syn match tcshSubst contained "\v\$[?#$!_<]" nextgroup=tcshModifierError 112syn match tcshSubst contained "\v\$[%#?]%(\h\w*|\d+)" nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar 113syn match tcshSubst contained "\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}" contains=tcshModifierError contains=tcshShellVar,tcshEnvVar 114 115" Variable Name Expansion Modifiers (order important) 116syn match tcshModifierError contained '\v:\S*' 117syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers 118 119" ----- Operators / Specials ----- 120" Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!] 121syn match tcshRedir contained "\v\<|\>\>?\&?!?" 122 123" Metachars 124syn match tcshMeta contained "\v[]{}*?[]" 125 126" Here Documents (<<) 127syn region tcshHereDoc contained matchgroup=tcshRedir start="\v\<\<\s*\z(\h\w*)" end="^\z1$" contains=@tcshVarList,tcshSpecial 128syn 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$" 129 130" Operators 131syn match tcshOperator contained "&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||" 132syn match tcshOperator contained "[(){}]" 133 134" Numbers 135syn match tcshNumber contained "\v<-?\d+>" 136 137" Arguements 138syn match tcshArguement contained "\v\s@<=-(\w|-)*" 139 140" Special charectors 141syn match tcshSpecial contained "\v\\@<!\\(\d{3}|.)" 142 143" ----- Syncronising ----- 144if exists("tcsh_minlines") 145 exec "syn sync minlines=" . tcsh_minlines 146else 147 syn sync minlines=15 " Except 'here' documents, nothing is long 148endif 149 150" Define highlighting of syntax groups 151hi def link tcshBuiltins statement 152hi def link tcshShellVar preproc 153hi def link tcshEnvVar tcshShellVar 154hi def link tcshAliases tcshShellVar 155hi def link tcshCommands identifier 156hi def link tcshSet tcshBuiltins 157hi def link tcshSetEnv tcshBuiltins 158hi def link tcshAlias tcshBuiltins 159hi def link tcshIf tcshBuiltins 160hi def link tcshElse tcshBuiltins 161hi def link tcshWhile tcshBuiltins 162hi def link tcshExprStart tcshBuiltins 163hi def link tcshExprVar tcshUsrVar 164hi def link tcshExprOp tcshOperator 165hi def link tcshExprEnd tcshOperator 166hi def link tcshComment comment 167hi def link tcshCommentTi preproc 168hi def link tcshCommentSp tcshCommentTi 169hi def link tcshSharpBang tcshCommentTi 170hi def link tcshTodo todo 171hi def link tcshSQuote constant 172hi def link tcshDQuote tcshSQuote 173hi def link tcshBQuoteGrp include 174hi def link tcshVarError error 175hi def link tcshUsrVar type 176hi def link tcshArgv tcshUsrVar 177hi def link tcshSubst tcshUsrVar 178hi def link tcshModifier tcshArguement 179hi def link tcshModifierError tcshVarError 180hi def link tcshMeta tcshSubst 181hi def link tcshRedir tcshOperator 182hi def link tcshHereDoc tcshSQuote 183hi def link tcshOperator operator 184hi def link tcshNumber number 185hi def link tcshArguement special 186hi def link tcshSpecial specialchar 187 188let b:current_syntax = "tcsh" 189