vim: add custom pom.xml indentation, shift width, etc.
[cmccabe-etc] / .vim / syntax / scala.vim
1 if version < 600
2   syntax clear
3 elseif exists("b:current_syntax")
4   finish
5 endif
6
7 let b:current_syntax = "scala"
8
9 syn case match
10 syn sync minlines=200 maxlines=1000
11
12 syn keyword scalaKeyword catch do else final finally for forSome if
13 syn keyword scalaKeyword match return throw try while yield macro
14 syn keyword scalaKeyword class trait object extends with nextgroup=scalaInstanceDeclaration skipwhite
15 syn keyword scalaKeyword case nextgroup=scalaKeyword,scalaCaseFollowing skipwhite
16 syn keyword scalaKeyword val nextgroup=scalaNameDefinition,scalaQuasiQuotes skipwhite
17 syn keyword scalaKeyword def var nextgroup=scalaNameDefinition skipwhite
18 hi link scalaKeyword Keyword
19
20 syn region scalaBlock start=/{/ end=/}/ contains=TOP fold
21
22 syn keyword scalaAkkaSpecialWord when goto using startWith initialize onTransition stay become unbecome
23 hi link scalaAkkaSpecialWord PreProc
24
25 syn match scalaSymbol /'[_A-Za-z0-9$]\+/
26 hi link scalaSymbol Number
27
28 syn match scalaChar /'.'/
29 syn match scalaEscapedChar /\\[\\ntbrf]/
30 syn match scalaUnicodeChar /\\u[A-Fa-f0-9]\{4}/
31 hi link scalaChar Character
32 hi link scalaEscapedChar Function
33 hi link scalaUnicodeChar Special
34
35 syn match scalaOperator "||"
36 syn match scalaOperator "&&"
37 hi link scalaOperator Special
38
39 syn match scalaNameDefinition /\<[_A-Za-z0-9$]\+\>/ contained nextgroup=scalaPostNameDefinition
40 syn match scalaNameDefinition /`[^`]\+`/ contained nextgroup=scalaPostNameDefinition
41 syn match scalaPostNameDefinition /\_s*:\_s*/ contained nextgroup=scalaTypeDeclaration
42 hi link scalaNameDefinition Function
43
44 syn match scalaInstanceDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaInstanceHash
45 syn match scalaInstanceDeclaration /`[^`]\+`/ contained
46 syn match scalaInstanceHash /#/ contained nextgroup=scalaInstanceDeclaration
47 hi link scalaInstanceDeclaration Special
48 hi link scalaInstanceHash Type
49
50 syn match scalaCapitalWord /\<[A-Z][A-Za-z0-9$]*\>/
51 hi link scalaCapitalWord Special
52
53 " Handle type declarations specially
54 syn region scalaTypeStatement matchgroup=Keyword start=/\<type\_s\+\ze/ end=/$/ contains=scalaTypeTypeDeclaration,scalaSquareBrackets,scalaTypeTypeEquals,scalaTypeStatement
55
56 " Ugh... duplication of all the scalaType* stuff to handle special highlighting
57 " of `type X =` declarations
58 syn match scalaTypeTypeDeclaration /(/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals contains=scalaRoundBrackets skipwhite
59 syn match scalaTypeTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeTypeDeclaration contains=scalaTypeTypeExtension skipwhite
60 syn match scalaTypeTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals skipwhite
61 syn match scalaTypeTypeEquals /=\ze[^>]/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
62 syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeTypeDeclaration skipwhite
63 syn match scalaTypeTypePostDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypePostExtension skipwhite
64 syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
65 hi link scalaTypeTypeDeclaration Type
66 hi link scalaTypeTypeExtension Keyword
67 hi link scalaTypeTypePostDeclaration Special
68 hi link scalaTypeTypePostExtension Keyword
69
70 syn match scalaTypeDeclaration /(/ contained nextgroup=scalaTypeExtension contains=scalaRoundBrackets skipwhite
71 syn match scalaTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeDeclaration contains=scalaTypeExtension skipwhite
72 syn match scalaTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeExtension skipwhite
73 syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeDeclaration skipwhite
74 hi link scalaTypeDeclaration Type
75 hi link scalaTypeExtension Keyword
76 hi link scalaTypePostExtension Keyword
77
78 syn match scalaTypeAnnotation /\%([_a-zA-Z0-9$\s]:\_s*\)\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration contains=scalaRoundBrackets
79 syn match scalaTypeAnnotation /)\_s*:\_s*\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration
80 hi link scalaTypeAnnotation Normal
81
82 syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained
83 syn match scalaCaseFollowing /`[^`]\+`/ contained
84 hi link scalaCaseFollowing Special
85
86 syn keyword scalaKeywordModifier abstract override final lazy implicit implicitly private protected sealed null require super
87 hi link scalaKeywordModifier Function
88
89 syn keyword scalaSpecial this true false package import ne eq
90 syn keyword scalaSpecial new nextgroup=scalaInstanceDeclaration skipwhite
91 syn match scalaSpecial "\%(=>\|⇒\|<-\|←\|->\|→\)"
92 syn match scalaSpecial /`[^`]*`/  " Backtick literals
93 hi link scalaSpecial PreProc
94
95 syn match scalaStringEmbeddedQuote /\\"/ contained
96 syn region scalaString start=/"/ end=/"/ contains=scalaStringEmbeddedQuote,scalaEscapedChar,scalaUnicodeChar
97 hi link scalaString String
98 hi link scalaStringEmbeddedQuote String
99
100 syn region scalaIString matchgroup=Special start=/\<[a-zA-Z][a-zA-Z0-9_]*"/ skip=/\\"/ end=/"/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
101 syn region scalaTripleIString matchgroup=Special start=/\<[a-zA-Z][a-zA-Z0-9_]*"""/ end=/"""\%([^"]\|$\)/ contains=scalaInterpolation,scalaInterpolationB,scalaEscapedChar,scalaUnicodeChar
102 hi link scalaIString String
103 hi link scalaTripleIString String
104
105 syn match scalaInterpolation /\$[a-zA-Z0-9_$]\+/ contained
106 syn region scalaInterpolationB matchgroup=scalaInterpolation start=/\${/ end=/}/ contained contains=TOP
107 hi link scalaInterpolation Function
108 hi link scalaInterpolationB Normal
109
110 syn region scalaFString matchgroup=Special start=/f"/ skip=/\\"/ end=/"/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
111 syn match scalaFInterpolation /\$[a-zA-Z0-9_$]\+\(%[-A-Za-z0-9\.]\+\)\?/ contained
112 syn region scalaFInterpolationB matchgroup=scalaFInterpolation start=/${/ end=/}\(%[-A-Za-z0-9\.]\+\)\?/ contained contains=TOP
113 hi link scalaFString String
114 hi link scalaFInterpolation Function
115 hi link scalaFInterpolationB Normal
116
117 syn region scalaTripleString start=/"""/ end=/"""\%([^"]\|$\)/ contains=scalaEscapedChar,scalaUnicodeChar
118 syn region scalaTripleFString matchgroup=Special start=/f"""/ end=/"""\%([^"]\|$\)/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
119 hi link scalaTripleString String
120 hi link scalaTripleFString String
121
122 syn match scalaNumber /\<0[dDfFlL]\?\>/ " Just a bare 0
123 syn match scalaNumber /\<[1-9]\d*[dDfFlL]\?\>/  " A multi-digit number - octal numbers with leading 0's are deprecated in Scala
124 syn match scalaNumber /\<0[xX][0-9a-fA-F]\+[dDfFlL]\?\>/ " Hex number
125 syn match scalaNumber /\%(\<\d\+\.\d*\|\.\d\+\)\%([eE][-+]\=\d\+\)\=[fFdD]\=/ " exponential notation 1
126 syn match scalaNumber /\<\d\+[eE][-+]\=\d\+[fFdD]\=\>/ " exponential notation 2
127 syn match scalaNumber /\<\d\+\%([eE][-+]\=\d\+\)\=[fFdD]\>/ " exponential notation 3
128 hi link scalaNumber Number
129
130 syn region scalaRoundBrackets start="(" end=")" skipwhite contained contains=scalaTypeDeclaration,scalaSquareBrackets,scalaRoundBrackets
131
132 syn region scalaSquareBrackets matchgroup=Type start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter
133 syn match scalaTypeOperator /[-+=:<>]\+/ contained
134 syn match scalaTypeAnnotationParameter /@\<[`_A-Za-z0-9$]\+\>/ contained
135 hi link scalaTypeOperator Keyword
136 hi link scalaTypeAnnotationParameter Function
137
138 syn region scalaMultilineComment start="/\*" end="\*/" contains=scalaMultilineComment,scalaDocLinks,scalaParameterAnnotation,scalaCommentAnnotation,scalaCommentCodeBlock,@scalaHtml keepend
139 syn match scalaCommentAnnotation "@[_A-Za-z0-9$]\+" contained
140 syn match scalaParameterAnnotation "@param" nextgroup=scalaParamAnnotationValue skipwhite contained
141 syn match scalaParamAnnotationValue /[`_A-Za-z0-9$]\+/ contained
142 syn region scalaDocLinks start="\[\[" end="\]\]" contained
143 syn region scalaCommentCodeBlock matchgroup=Keyword start="{{{" end="}}}" contained
144 hi link scalaMultilineComment Comment
145 hi link scalaDocLinks Function
146 hi link scalaParameterAnnotation Function
147 hi link scalaParamAnnotationValue Keyword
148 hi link scalaCommentAnnotation Function
149 hi link scalaCommentCodeBlock String
150
151 syn match scalaAnnotation /@\<[`_A-Za-z0-9$]\+\>/
152 hi link scalaAnnotation PreProc
153
154 syn match scalaTrailingComment "//.*$"
155 hi link scalaTrailingComment Comment
156
157 syn match scalaAkkaFSM /goto([^)]*)\_s\+\<using\>/ contains=scalaAkkaFSMGotoUsing
158 syn match scalaAkkaFSM /stay\_s\+using/
159 syn match scalaAkkaFSM /^\s*stay\s*$/
160 syn match scalaAkkaFSM /when\ze([^)]*)/
161 syn match scalaAkkaFSM /startWith\ze([^)]*)/
162 syn match scalaAkkaFSM /initialize\ze()/
163 syn match scalaAkkaFSM /onTransition/
164 syn match scalaAkkaFSM /onTermination/
165 syn match scalaAkkaFSM /whenUnhandled/
166 syn match scalaAkkaFSMGotoUsing /\<using\>/
167 syn match scalaAkkaFSMGotoUsing /\<goto\>/
168 hi link scalaAkkaFSM PreProc
169 hi link scalaAkkaFSMGotoUsing PreProc