PageRenderTime 169ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/runtime/syntax/zsh.vim

https://github.com/Brijen/macvim
Vim Script | 213 lines | 173 code | 31 blank | 9 comment | 9 complexity | 35f5f77eed9977bda8730571a6813982 MD5 | raw file
  1. " Vim syntax file
  2. " Language: Zsh shell script
  3. " Maintainer: Nikolai Weibull <now@bitwi.se>
  4. " Latest Revision: 2010-01-23
  5. if exists("b:current_syntax")
  6. finish
  7. endif
  8. let s:cpo_save = &cpo
  9. set cpo&vim
  10. setlocal iskeyword+=-
  11. syn keyword zshTodo contained TODO FIXME XXX NOTE
  12. syn region zshComment oneline start='\%(^\|\s\)#' end='$'
  13. \ contains=zshTodo,@Spell
  14. syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$'
  15. syn match zshQuoted '\\.'
  16. syn region zshString matchgroup=zshStringDelimiter start=+"+ end=+"+
  17. \ contains=zshQuoted,@zshDerefs,@zshSubst
  18. syn region zshString matchgroup=zshStringDelimiter start=+'+ end=+'+
  19. " XXX: This should probably be more precise, but Zsh seems a bit confused about it itself
  20. syn region zshPOSIXString matchgroup=zshStringDelimiter start=+\$'+
  21. \ end=+'+ contains=zshQuoted
  22. syn match zshJobSpec '%\(\d\+\|?\=\w\+\|[%+-]\)'
  23. syn keyword zshPrecommand noglob nocorrect exec command builtin - time
  24. syn keyword zshDelimiter do done
  25. syn keyword zshConditional if then elif else fi case in esac select
  26. syn keyword zshRepeat while until repeat
  27. syn keyword zshRepeat for foreach nextgroup=zshVariable skipwhite
  28. syn keyword zshException always
  29. syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite
  30. syn match zshKSHFunction contained '\k\+'
  31. syn match zshFunction '^\s*\k\+\ze\s*()'
  32. syn match zshOperator '||\|&&\|;\|&!\='
  33. syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
  34. syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
  35. syn match zshRedir '|&\='
  36. syn region zshHereDoc matchgroup=zshRedir
  37. \ start='<\@<!<<\s*\z([^<]\S*\)'
  38. \ end='^\z1\>'
  39. \ contains=@zshSubst
  40. syn region zshHereDoc matchgroup=zshRedir
  41. \ start='<\@<!<<\s*\\\z(\S\+\)'
  42. \ end='^\z1\>'
  43. \ contains=@zshSubst
  44. syn region zshHereDoc matchgroup=zshRedir
  45. \ start='<\@<!<<-\s*\\\=\z(\S\+\)'
  46. \ end='^\s*\z1\>'
  47. \ contains=@zshSubst
  48. syn region zshHereDoc matchgroup=zshRedir
  49. \ start=+<\@<!<<\s*\(["']\)\z(\S\+\)\1+
  50. \ end='^\z1\>'
  51. syn region zshHereDoc matchgroup=zshRedir
  52. \ start=+<\@<!<<-\s*\(["']\)\z(\S\+\)\1+
  53. \ end='^\s*\z1\>'
  54. syn match zshVariable '\<\h\w*' contained
  55. syn match zshVariableDef '\<\h\w*\ze+\=='
  56. " XXX: how safe is this?
  57. syn region zshVariableDef oneline
  58. \ start='\$\@<!\<\h\w*\[' end='\]\ze+\=='
  59. \ contains=@zshSubst
  60. syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref
  61. if !exists("g:zsh_syntax_variables")
  62. let s:zsh_syntax_variables = 'all'
  63. else
  64. let s:zsh_syntax_variables = g:zsh_syntax_variables
  65. endif
  66. if s:zsh_syntax_variables =~ 'short\|all'
  67. syn match zshShortDeref '\$[!#$*@?_-]\w\@!'
  68. syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>'
  69. endif
  70. if s:zsh_syntax_variables =~ 'long\|all'
  71. syn match zshLongDeref '\$\%(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)'
  72. syn match zshLongDeref '\$\%(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)'
  73. syn match zshLongDeref '\$\%(TRY_BLOCK_ERROR\|TTY\|TTYIDLE\|UID\|USERNAME\|VENDOR\|ZSH_NAME\|ZSH_VERSION\|REPLY\|reply\|TERM\)'
  74. endif
  75. if s:zsh_syntax_variables =~ 'all'
  76. syn match zshDeref '\$[=^~]*[#+]*\h\w*\>'
  77. else
  78. syn match zshDeref transparent contains=NONE '\$[=^~]*[#+]*\h\w*\>'
  79. endif
  80. syn match zshCommands '\%(^\|\s\)[.:]\ze\s'
  81. syn keyword zshCommands alias autoload bg bindkey break bye cap cd
  82. \ chdir clone comparguments compcall compctl
  83. \ compdescribe compfiles compgroups compquote
  84. \ comptags comptry compvalues continue dirs
  85. \ disable disown echo echotc echoti emulate
  86. \ enable eval exec exit export false fc fg
  87. \ functions getcap getln getopts hash history
  88. \ jobs kill let limit log logout popd print
  89. \ printf pushd pushln pwd r read readonly
  90. \ rehash return sched set setcap setopt shift
  91. \ source stat suspend test times trap true
  92. \ ttyctl type ulimit umask unalias unfunction
  93. \ unhash unlimit unset unsetopt vared wait
  94. \ whence where which zcompile zformat zftp zle
  95. \ zmodload zparseopts zprof zpty zregexparse
  96. \ zsocket zstyle ztcp
  97. syn keyword zshTypes float integer local typeset declare
  98. " XXX: this may be too much
  99. " syn match zshSwitches '\s\zs--\=[a-zA-Z0-9-]\+'
  100. syn match zshNumber '[+-]\=\<\d\+\>'
  101. syn match zshNumber '[+-]\=\<0x\x\+\>'
  102. syn match zshNumber '[+-]\=\<0\o\+\>'
  103. syn match zshNumber '[+-]\=\d\+#[-+]\=\w\+\>'
  104. syn match zshNumber '[+-]\=\d\+\.\d\+\>'
  105. " TODO: $[...] is the same as $((...)), so add that as well.
  106. syn cluster zshSubst contains=zshSubst,zshOldSubst,zshMathSubst
  107. syn region zshSubst matchgroup=zshSubstDelim transparent
  108. \ start='\$(' skip='\\)' end=')' contains=TOP
  109. syn region zshParentheses transparent start='(' skip='\\)' end=')'
  110. syn region zshMathSubst matchgroup=zshSubstDelim transparent
  111. \ start='\$((' skip='\\)'
  112. \ matchgroup=zshSubstDelim end='))'
  113. \ contains=zshParentheses,@zshSubst,zshNumber,
  114. \ @zshDerefs,zshString
  115. syn region zshBrackets contained transparent start='{' skip='\\}'
  116. \ end='}'
  117. syn region zshSubst matchgroup=zshSubstDelim start='\${' skip='\\}'
  118. \ end='}' contains=@zshSubst,zshBrackets,zshQuoted,zshString
  119. syn region zshOldSubst matchgroup=zshSubstDelim start=+`+ skip=+\\`+
  120. \ end=+`+ contains=TOP,zshOldSubst
  121. syn sync minlines=50
  122. syn sync match zshHereDocSync grouphere NONE '<<-\=\s*\%(\\\=\S\+\|\(["']\)\S\+\1\)'
  123. syn sync match zshHereDocEndSync groupthere NONE '^\s*EO\a\+\>'
  124. hi def link zshTodo Todo
  125. hi def link zshComment Comment
  126. hi def link zshPreProc PreProc
  127. hi def link zshQuoted SpecialChar
  128. hi def link zshString String
  129. hi def link zshStringDelimiter zshString
  130. hi def link zshPOSIXString zshString
  131. hi def link zshJobSpec Special
  132. hi def link zshPrecommand Special
  133. hi def link zshDelimiter Keyword
  134. hi def link zshConditional Conditional
  135. hi def link zshException Exception
  136. hi def link zshRepeat Repeat
  137. hi def link zshKeyword Keyword
  138. hi def link zshFunction None
  139. hi def link zshKSHFunction zshFunction
  140. hi def link zshHereDoc String
  141. if 0
  142. hi def link zshOperator Operator
  143. else
  144. hi def link zshOperator None
  145. endif
  146. if 1
  147. hi def link zshRedir Operator
  148. else
  149. hi def link zshRedir None
  150. endif
  151. hi def link zshVariable None
  152. hi def link zshVariableDef zshVariable
  153. hi def link zshDereferencing PreProc
  154. if s:zsh_syntax_variables =~ 'short\|all'
  155. hi def link zshShortDeref zshDereferencing
  156. else
  157. hi def link zshShortDeref None
  158. endif
  159. if s:zsh_syntax_variables =~ 'long\|all'
  160. hi def link zshLongDeref zshDereferencing
  161. else
  162. hi def link zshLongDeref None
  163. endif
  164. if s:zsh_syntax_variables =~ 'all'
  165. hi def link zshDeref zshDereferencing
  166. else
  167. hi def link zshDeref None
  168. endif
  169. hi def link zshCommands Keyword
  170. hi def link zshTypes Type
  171. hi def link zshSwitches Special
  172. hi def link zshNumber Number
  173. hi def link zshSubst PreProc
  174. hi def link zshMathSubst zshSubst
  175. hi def link zshOldSubst zshSubst
  176. hi def link zshSubstDelim zshSubst
  177. let b:current_syntax = "zsh"
  178. let &cpo = s:cpo_save
  179. unlet s:cpo_save