blob: c5a175fd77ce62efcc8eb5edd8a70ddcbae08074 [file] [log] [blame]
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +02001" 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')
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020010 " quit when a syntax file was already loaded
11 if exists("b:current_syntax")
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +020012 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 "&&"
Bram Moolenaar036986f2017-03-16 17:41:02 +010074syn match scalaOperator "|"
75syn match scalaOperator "&"
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +020076hi link scalaOperator Special
77
78syn match scalaNameDefinition /\<[_A-Za-z0-9$]\+\>/ contained nextgroup=scalaPostNameDefinition,scalaVariableDeclarationList
79syn match scalaNameDefinition /`[^`]\+`/ contained nextgroup=scalaPostNameDefinition
80syn match scalaVariableDeclarationList /\s*,\s*/ contained nextgroup=scalaNameDefinition
81syn match scalaPostNameDefinition /\_s*:\_s*/ contained nextgroup=scalaTypeDeclaration
82hi link scalaNameDefinition Function
83
84syn match scalaInstanceDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaInstanceHash
85syn match scalaInstanceDeclaration /`[^`]\+`/ contained
86syn match scalaInstanceHash /#/ contained nextgroup=scalaInstanceDeclaration
87hi link scalaInstanceDeclaration Special
88hi link scalaInstanceHash Type
89
90syn match scalaUnimplemented /???/
91hi link scalaUnimplemented ERROR
92
93syn match scalaCapitalWord /\<[A-Z][A-Za-z0-9$]*\>/
94hi link scalaCapitalWord Special
95
96" Handle type declarations specially
97syn 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
101syn match scalaTypeTypeDeclaration /(/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals contains=scalaRoundBrackets skipwhite
102syn match scalaTypeTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeTypeDeclaration contains=scalaTypeTypeExtension skipwhite
103syn match scalaTypeTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals skipwhite
104syn match scalaTypeTypeEquals /=\ze[^>]/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
105syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeTypeDeclaration skipwhite
106syn match scalaTypeTypePostDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypePostExtension skipwhite
107syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
108hi link scalaTypeTypeDeclaration Type
109hi link scalaTypeTypeExtension Keyword
110hi link scalaTypeTypePostDeclaration Special
111hi link scalaTypeTypePostExtension Keyword
112
113syn match scalaTypeDeclaration /(/ contained nextgroup=scalaTypeExtension contains=scalaRoundBrackets skipwhite
114syn match scalaTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeDeclaration contains=scalaTypeExtension skipwhite
115syn match scalaTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeExtension skipwhite
116syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeDeclaration skipwhite
117hi link scalaTypeDeclaration Type
118hi link scalaTypeExtension Keyword
119hi link scalaTypePostExtension Keyword
120
121syn match scalaTypeAnnotation /\%([_a-zA-Z0-9$\s]:\_s*\)\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration contains=scalaRoundBrackets
122syn match scalaTypeAnnotation /)\_s*:\_s*\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration
123hi link scalaTypeAnnotation Normal
124
125syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained
126syn match scalaCaseFollowing /`[^`]\+`/ contained
127hi link scalaCaseFollowing Special
128
129syn keyword scalaKeywordModifier abstract override final lazy implicit implicitly private protected sealed null require super
130hi link scalaKeywordModifier Function
131
132syn keyword scalaSpecial this true false ne eq
133syn keyword scalaSpecial new nextgroup=scalaInstanceDeclaration skipwhite
134syn match scalaSpecial "\%(=>\|⇒\|<-\|←\|->\|→\)"
135syn match scalaSpecial /`[^`]\+`/ " Backtick literals
136hi link scalaSpecial PreProc
137
138syn keyword scalaExternal package import
139hi link scalaExternal Include
140
141syn match scalaStringEmbeddedQuote /\\"/ contained
142syn region scalaString start=/"/ end=/"/ contains=scalaStringEmbeddedQuote,scalaEscapedChar,scalaUnicodeChar
143hi link scalaString String
144hi link scalaStringEmbeddedQuote String
145
146syn region scalaIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"/ skip=/\\"/ end=/"/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
Bram Moolenaar036986f2017-03-16 17:41:02 +0100147syn region scalaTripleIString matchgroup=scalaInterpolationBrackets start=/\<[a-zA-Z][a-zA-Z0-9_]*"""/ end=/"""\ze\%([^"]\|$\)/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +0200148hi link scalaIString String
149hi link scalaTripleIString String
150
151syn match scalaInterpolation /\$[a-zA-Z0-9_$]\+/ contained
152exe 'syn region scalaInterpolationB matchgroup=scalaInterpolationBoundary start=/\${/ end=/}/ contained contains=' . s:ContainedGroup()
153hi link scalaInterpolation Function
154hi link scalaInterpolationB Normal
155
156syn region scalaFString matchgroup=scalaInterpolationBrackets start=/f"/ skip=/\\"/ end=/"/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
157syn match scalaFInterpolation /\$[a-zA-Z0-9_$]\+\(%[-A-Za-z0-9\.]\+\)\?/ contained
158exe 'syn region scalaFInterpolationB matchgroup=scalaInterpolationBoundary start=/${/ end=/}\(%[-A-Za-z0-9\.]\+\)\?/ contained contains=' . s:ContainedGroup()
159hi link scalaFString String
160hi link scalaFInterpolation Function
161hi link scalaFInterpolationB Normal
162
163syn region scalaTripleString start=/"""/ end=/"""\%([^"]\|$\)/ contains=scalaEscapedChar,scalaUnicodeChar
164syn region scalaTripleFString matchgroup=scalaInterpolationBrackets start=/f"""/ end=/"""\%([^"]\|$\)/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
165hi link scalaTripleString String
166hi link scalaTripleFString String
167
168hi link scalaInterpolationBrackets Special
169hi link scalaInterpolationBoundary Function
170
171syn match scalaNumber /\<0[dDfFlL]\?\>/ " Just a bare 0
172syn match scalaNumber /\<[1-9]\d*[dDfFlL]\?\>/ " A multi-digit number - octal numbers with leading 0's are deprecated in Scala
173syn match scalaNumber /\<0[xX][0-9a-fA-F]\+[dDfFlL]\?\>/ " Hex number
174syn match scalaNumber /\%(\<\d\+\.\d*\|\.\d\+\)\%([eE][-+]\=\d\+\)\=[fFdD]\=/ " exponential notation 1
175syn match scalaNumber /\<\d\+[eE][-+]\=\d\+[fFdD]\=\>/ " exponential notation 2
176syn match scalaNumber /\<\d\+\%([eE][-+]\=\d\+\)\=[fFdD]\>/ " exponential notation 3
177hi link scalaNumber Number
178
179syn region scalaRoundBrackets start="(" end=")" skipwhite contained contains=scalaTypeDeclaration,scalaSquareBrackets,scalaRoundBrackets
180
181syn region scalaSquareBrackets matchgroup=scalaSquareBracketsBrackets start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter
182syn match scalaTypeOperator /[-+=:<>]\+/ contained
183syn match scalaTypeAnnotationParameter /@\<[`_A-Za-z0-9$]\+\>/ contained
184hi link scalaSquareBracketsBrackets Type
185hi link scalaTypeOperator Keyword
186hi link scalaTypeAnnotationParameter Function
187
188syn match scalaShebang "\%^#!.*" display
189syn region scalaMultilineComment start="/\*" end="\*/" contains=scalaMultilineComment,scalaDocLinks,scalaParameterAnnotation,scalaCommentAnnotation,scalaTodo,scalaCommentCodeBlock,@Spell keepend fold
190syn match scalaCommentAnnotation "@[_A-Za-z0-9$]\+" contained
191syn match scalaParameterAnnotation "\%(@tparam\|@param\|@see\)" nextgroup=scalaParamAnnotationValue skipwhite contained
192syn match scalaParamAnnotationValue /[.`_A-Za-z0-9$]\+/ contained
193syn region scalaDocLinks start="\[\[" end="\]\]" contained
194syn region scalaCommentCodeBlock matchgroup=Keyword start="{{{" end="}}}" contained
195syn match scalaTodo "\vTODO|FIXME|XXX" contained
196hi link scalaShebang Comment
197hi link scalaMultilineComment Comment
198hi link scalaDocLinks Function
199hi link scalaParameterAnnotation Function
200hi link scalaParamAnnotationValue Keyword
201hi link scalaCommentAnnotation Function
202hi link scalaCommentCodeBlockBrackets String
203hi link scalaCommentCodeBlock String
204hi link scalaTodo Todo
205
206syn match scalaAnnotation /@\<[`_A-Za-z0-9$]\+\>/
207hi link scalaAnnotation PreProc
208
209syn match scalaTrailingComment "//.*$" contains=scalaTodo,@Spell
210hi link scalaTrailingComment Comment
211
212syn match scalaAkkaFSM /goto([^)]*)\_s\+\<using\>/ contains=scalaAkkaFSMGotoUsing
213syn match scalaAkkaFSM /stay\_s\+using/
214syn match scalaAkkaFSM /^\s*stay\s*$/
215syn match scalaAkkaFSM /when\ze([^)]*)/
216syn match scalaAkkaFSM /startWith\ze([^)]*)/
217syn match scalaAkkaFSM /initialize\ze()/
218syn match scalaAkkaFSM /onTransition/
219syn match scalaAkkaFSM /onTermination/
220syn match scalaAkkaFSM /whenUnhandled/
221syn match scalaAkkaFSMGotoUsing /\<using\>/
222syn match scalaAkkaFSMGotoUsing /\<goto\>/
223hi link scalaAkkaFSM PreProc
224hi link scalaAkkaFSMGotoUsing PreProc
225
226let b:current_syntax = 'scala'
227
228if main_syntax ==# 'scala'
229 unlet main_syntax
230endif
231
232" vim:set sw=2 sts=2 ts=8 et: