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