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