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