scala.vim 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. " Vim syntax file
  2. " Language: Scala
  3. " Maintainer: Derek Wyatt
  4. " URL: https://github.com/derekwyatt/vim-scala
  5. " License: Same as Vim
  6. " Last Change: 20 May 2016
  7. " ----------------------------------------------------------------------------
  8. if !exists('main_syntax')
  9. " quit when a syntax file was already loaded
  10. if exists("b:current_syntax")
  11. finish
  12. endif
  13. let main_syntax = 'scala'
  14. endif
  15. scriptencoding utf-8
  16. let b:current_syntax = "scala"
  17. " Allows for embedding, see #59; main_syntax convention instead? Refactor TOP
  18. "
  19. " The @Spell here is a weird hack, it means *exclude* if the first group is
  20. " TOP. Otherwise we get spelling errors highlighted on code elements that
  21. " match scalaBlock, even with `syn spell notoplevel`.
  22. function! s:ContainedGroup()
  23. try
  24. silent syn list @scala
  25. return '@scala,@NoSpell'
  26. catch /E392/
  27. return 'TOP,@Spell'
  28. endtry
  29. endfunction
  30. unlet! b:current_syntax
  31. syn case match
  32. syn sync minlines=200 maxlines=1000
  33. syn keyword scalaKeyword catch do else final finally for forSome if
  34. syn keyword scalaKeyword match return throw try while yield macro
  35. syn keyword scalaKeyword class trait object extends with nextgroup=scalaInstanceDeclaration skipwhite
  36. syn keyword scalaKeyword case nextgroup=scalaKeyword,scalaCaseFollowing skipwhite
  37. syn keyword scalaKeyword val nextgroup=scalaNameDefinition,scalaQuasiQuotes skipwhite
  38. syn keyword scalaKeyword def var nextgroup=scalaNameDefinition skipwhite
  39. hi link scalaKeyword Keyword
  40. exe 'syn region scalaBlock start=/{/ end=/}/ contains=' . s:ContainedGroup() . ' fold'
  41. syn keyword scalaAkkaSpecialWord when goto using startWith initialize onTransition stay become unbecome
  42. hi link scalaAkkaSpecialWord PreProc
  43. syn keyword scalatestSpecialWord shouldBe
  44. syn match scalatestShouldDSLA /^\s\+\zsit should/
  45. syn match scalatestShouldDSLB /\<should\>/
  46. hi link scalatestSpecialWord PreProc
  47. hi link scalatestShouldDSLA PreProc
  48. hi link scalatestShouldDSLB PreProc
  49. syn match scalaSymbol /'[_A-Za-z0-9$]\+/
  50. hi link scalaSymbol Number
  51. syn match scalaChar /'.'/
  52. syn match scalaChar /'\\[\\"'ntbrf]'/ contains=scalaEscapedChar
  53. syn match scalaChar /'\\u[A-Fa-f0-9]\{4}'/ contains=scalaUnicodeChar
  54. syn match scalaEscapedChar /\\[\\"'ntbrf]/
  55. syn match scalaUnicodeChar /\\u[A-Fa-f0-9]\{4}/
  56. hi link scalaChar Character
  57. hi link scalaEscapedChar Function
  58. hi link scalaUnicodeChar Special
  59. syn match scalaOperator "||"
  60. syn match scalaOperator "&&"
  61. syn match scalaOperator "|"
  62. syn match scalaOperator "&"
  63. hi link scalaOperator Special
  64. syn match scalaNameDefinition /\<[_A-Za-z0-9$]\+\>/ contained nextgroup=scalaPostNameDefinition,scalaVariableDeclarationList
  65. syn match scalaNameDefinition /`[^`]\+`/ contained nextgroup=scalaPostNameDefinition
  66. syn match scalaVariableDeclarationList /\s*,\s*/ contained nextgroup=scalaNameDefinition
  67. syn match scalaPostNameDefinition /\_s*:\_s*/ contained nextgroup=scalaTypeDeclaration
  68. hi link scalaNameDefinition Function
  69. syn match scalaInstanceDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaInstanceHash
  70. syn match scalaInstanceDeclaration /`[^`]\+`/ contained
  71. syn match scalaInstanceHash /#/ contained nextgroup=scalaInstanceDeclaration
  72. hi link scalaInstanceDeclaration Special
  73. hi link scalaInstanceHash Type
  74. syn match scalaUnimplemented /???/
  75. hi link scalaUnimplemented ERROR
  76. syn match scalaCapitalWord /\<[A-Z][A-Za-z0-9$]*\>/
  77. hi link scalaCapitalWord Special
  78. " Handle type declarations specially
  79. syn region scalaTypeStatement matchgroup=Keyword start=/\<type\_s\+\ze/ end=/$/ contains=scalaTypeTypeDeclaration,scalaSquareBrackets,scalaTypeTypeEquals,scalaTypeStatement
  80. " Ugh... duplication of all the scalaType* stuff to handle special highlighting
  81. " of `type X =` declarations
  82. syn match scalaTypeTypeDeclaration /(/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals contains=scalaRoundBrackets skipwhite
  83. syn match scalaTypeTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeTypeDeclaration contains=scalaTypeTypeExtension skipwhite
  84. syn match scalaTypeTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals skipwhite
  85. syn match scalaTypeTypeEquals /=\ze[^>]/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
  86. syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeTypeDeclaration skipwhite
  87. syn match scalaTypeTypePostDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypePostExtension skipwhite
  88. syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
  89. hi link scalaTypeTypeDeclaration Type
  90. hi link scalaTypeTypeExtension Keyword
  91. hi link scalaTypeTypePostDeclaration Special
  92. hi link scalaTypeTypePostExtension Keyword
  93. syn match scalaTypeDeclaration /(/ contained nextgroup=scalaTypeExtension contains=scalaRoundBrackets skipwhite
  94. syn match scalaTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeDeclaration contains=scalaTypeExtension skipwhite
  95. syn match scalaTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeExtension skipwhite
  96. syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeDeclaration skipwhite
  97. hi link scalaTypeDeclaration Type
  98. hi link scalaTypeExtension Keyword
  99. hi link scalaTypePostExtension Keyword
  100. syn match scalaTypeAnnotation /\%([_a-zA-Z0-9$\s]:\_s*\)\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration contains=scalaRoundBrackets
  101. syn match scalaTypeAnnotation /)\_s*:\_s*\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration
  102. hi link scalaTypeAnnotation Normal
  103. syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained
  104. syn match scalaCaseFollowing /`[^`]\+`/ contained
  105. hi link scalaCaseFollowing Special
  106. syn keyword scalaKeywordModifier abstract override final lazy implicit implicitly private protected sealed null require super
  107. hi link scalaKeywordModifier Function
  108. syn keyword scalaSpecial this true false ne eq
  109. syn keyword scalaSpecial new nextgroup=scalaInstanceDeclaration skipwhite
  110. syn match scalaSpecial "\%(=>\|⇒\|<-\|←\|->\|→\)"
  111. syn match scalaSpecial /`[^`]\+`/ " Backtick literals
  112. hi link scalaSpecial PreProc
  113. syn keyword scalaExternal package import
  114. hi link scalaExternal Include
  115. syn match scalaStringEmbeddedQuote /\\"/ contained
  116. syn region scalaString start=/"/ end=/"/ contains=scalaStringEmbeddedQuote,scalaEscapedChar,scalaUnicodeChar
  117. hi link scalaString String
  118. hi link scalaStringEmbeddedQuote String
  119. syn region scalaIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"/ skip=/\\"/ end=/"/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
  120. syn region scalaTripleIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"""/ end=/"""\ze\%([^"]\|$\)/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
  121. hi link scalaIString String
  122. hi link scalaTripleIString String
  123. syn match scalaInterpolation /\$[a-zA-Z0-9_$]\+/ contained
  124. exe 'syn region scalaInterpolationB matchgroup=scalaInterpolationBoundary start=/\${/ end=/}/ contained contains=' . s:ContainedGroup()
  125. hi link scalaInterpolation Function
  126. hi link scalaInterpolationB Normal
  127. syn region scalaFString matchgroup=scalaInterpolationBrackets start=/f"/ skip=/\\"/ end=/"/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
  128. syn match scalaFInterpolation /\$[a-zA-Z0-9_$]\+\(%[-A-Za-z0-9\.]\+\)\?/ contained
  129. exe 'syn region scalaFInterpolationB matchgroup=scalaInterpolationBoundary start=/${/ end=/}\(%[-A-Za-z0-9\.]\+\)\?/ contained contains=' . s:ContainedGroup()
  130. hi link scalaFString String
  131. hi link scalaFInterpolation Function
  132. hi link scalaFInterpolationB Normal
  133. syn region scalaTripleString start=/"""/ end=/"""\%([^"]\|$\)/ contains=scalaEscapedChar,scalaUnicodeChar
  134. syn region scalaTripleFString matchgroup=scalaInterpolationBrackets start=/f"""/ end=/"""\%([^"]\|$\)/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
  135. hi link scalaTripleString String
  136. hi link scalaTripleFString String
  137. hi link scalaInterpolationBrackets Special
  138. hi link scalaInterpolationBoundary Function
  139. syn match scalaNumber /\<0[dDfFlL]\?\>/ " Just a bare 0
  140. syn match scalaNumber /\<[1-9]\d*[dDfFlL]\?\>/ " A multi-digit number - octal numbers with leading 0's are deprecated in Scala
  141. syn match scalaNumber /\<0[xX][0-9a-fA-F]\+[dDfFlL]\?\>/ " Hex number
  142. syn match scalaNumber /\%(\<\d\+\.\d*\|\.\d\+\)\%([eE][-+]\=\d\+\)\=[fFdD]\=/ " exponential notation 1
  143. syn match scalaNumber /\<\d\+[eE][-+]\=\d\+[fFdD]\=\>/ " exponential notation 2
  144. syn match scalaNumber /\<\d\+\%([eE][-+]\=\d\+\)\=[fFdD]\>/ " exponential notation 3
  145. hi link scalaNumber Number
  146. syn region scalaRoundBrackets start="(" end=")" skipwhite contained contains=scalaTypeDeclaration,scalaSquareBrackets,scalaRoundBrackets
  147. syn region scalaSquareBrackets matchgroup=scalaSquareBracketsBrackets start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter
  148. syn match scalaTypeOperator /[-+=:<>]\+/ contained
  149. syn match scalaTypeAnnotationParameter /@\<[`_A-Za-z0-9$]\+\>/ contained
  150. hi link scalaSquareBracketsBrackets Type
  151. hi link scalaTypeOperator Keyword
  152. hi link scalaTypeAnnotationParameter Function
  153. syn match scalaShebang "\%^#!.*" display
  154. syn region scalaMultilineComment start="/\*" end="\*/" contains=scalaMultilineComment,scalaDocLinks,scalaParameterAnnotation,scalaCommentAnnotation,scalaTodo,scalaCommentCodeBlock,@Spell keepend fold
  155. syn match scalaCommentAnnotation "@[_A-Za-z0-9$]\+" contained
  156. syn match scalaParameterAnnotation "\%(@tparam\|@param\|@see\)" nextgroup=scalaParamAnnotationValue skipwhite contained
  157. syn match scalaParamAnnotationValue /[.`_A-Za-z0-9$]\+/ contained
  158. syn region scalaDocLinks start="\[\[" end="\]\]" contained
  159. syn region scalaCommentCodeBlock matchgroup=Keyword start="{{{" end="}}}" contained
  160. syn match scalaTodo "\vTODO|FIXME|XXX" contained
  161. hi link scalaShebang Comment
  162. hi link scalaMultilineComment Comment
  163. hi link scalaDocLinks Function
  164. hi link scalaParameterAnnotation Function
  165. hi link scalaParamAnnotationValue Keyword
  166. hi link scalaCommentAnnotation Function
  167. hi link scalaCommentCodeBlockBrackets String
  168. hi link scalaCommentCodeBlock String
  169. hi link scalaTodo Todo
  170. syn match scalaAnnotation /@\<[`_A-Za-z0-9$]\+\>/
  171. hi link scalaAnnotation PreProc
  172. syn match scalaTrailingComment "//.*$" contains=scalaTodo,@Spell
  173. hi link scalaTrailingComment Comment
  174. syn match scalaAkkaFSM /goto([^)]*)\_s\+\<using\>/ contains=scalaAkkaFSMGotoUsing
  175. syn match scalaAkkaFSM /stay\_s\+using/
  176. syn match scalaAkkaFSM /^\s*stay\s*$/
  177. syn match scalaAkkaFSM /when\ze([^)]*)/
  178. syn match scalaAkkaFSM /startWith\ze([^)]*)/
  179. syn match scalaAkkaFSM /initialize\ze()/
  180. syn match scalaAkkaFSM /onTransition/
  181. syn match scalaAkkaFSM /onTermination/
  182. syn match scalaAkkaFSM /whenUnhandled/
  183. syn match scalaAkkaFSMGotoUsing /\<using\>/
  184. syn match scalaAkkaFSMGotoUsing /\<goto\>/
  185. hi link scalaAkkaFSM PreProc
  186. hi link scalaAkkaFSMGotoUsing PreProc
  187. let b:current_syntax = 'scala'
  188. if main_syntax ==# 'scala'
  189. unlet main_syntax
  190. endif
  191. " vim:set sw=2 sts=2 ts=8 et: