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