comparison runtime/syntax/scala.vim @ 9975:03fa8a51e9dc

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