3
3
" Maintainer: Patrick Walton <[email protected] >
4
4
" Maintainer: Ben Blum <[email protected] >
5
5
" Maintainer: Chris Morgan <[email protected] >
6
- " Last Change: 2013 Oct 29
6
+ " Last Change: 2013 Dec 04
7
7
8
8
if version < 600
9
9
syntax clear
@@ -28,6 +28,7 @@ syn keyword rustKeyword use nextgroup=rustModPath skipwhite
28
28
" FIXME: Scoped impl's name is also fallen in this category
29
29
syn keyword rustKeyword mod trait struct enum type nextgroup =rustIdentifier skipwhite
30
30
syn keyword rustKeyword fn nextgroup =rustFuncName skipwhite
31
+ syn keyword rustKeyword proc
31
32
syn keyword rustStorage const mut ref static
32
33
33
34
syn match rustIdentifier contains =rustIdentifierPrime " \% ([^[:cntrl:][:space:][:punct:][:digit:]]\| _\)\% ([^[:cntrl:][:punct:][:space:]]\| _\) *" display contained
@@ -89,6 +90,7 @@ syn keyword rustTrait Orderable Signed Unsigned Round
89
90
syn keyword rustTrait Primitive Int Float ToStrRadix ToPrimitive FromPrimitive
90
91
syn keyword rustTrait GenericPath Path PosixPath WindowsPath
91
92
syn keyword rustTrait RawPtr
93
+ syn keyword rustTrait Buffer Writer Reader Seek
92
94
syn keyword rustTrait SendStr SendStrOwned SendStrStatic IntoSendStr
93
95
syn keyword rustTrait Str StrVector StrSlice OwnedStr
94
96
syn keyword rustTrait IterBytes
@@ -143,38 +145,29 @@ syn match rustOperator display "&&\|||"
143
145
syn match rustMacro ' \w\(\w\) *!' contains =rustAssert,rustFail
144
146
syn match rustMacro ' #\w\(\w\) *' contains =rustAssert,rustFail
145
147
146
- syn match rustFormat display " %\(\d\+\$\)\= [-+' #0*]*\(\d *\|\*\|\*\d\+\$\)\(\.\(\d *\|\*\|\*\d\+\$\)\)\=\( [hlLjzt]\| ll\| hh\)\=\( [aAbdiuoxXDOUfFeEgGcCsSpn?]\|\[\^\= .[^]]*\]\) " contained
147
- syn match rustFormat display " %%" contained
148
+ syn match rustSpecialError display contained / \\ ./
148
149
syn match rustSpecial display contained / \\\( [nrt0\\ '"]\| x\x\{ 2}\| u\x\{ 4}\| U\x\{ 8}\) /
149
150
syn match rustStringContinuation display contained / \\\n\s */
150
- syn region rustString start =+ "+ skip =+ \\\\\|\\ "+ end =+ "+ contains =rustTodo,rustFormat, rustSpecial,rustStringContinuation
151
+ syn region rustString start =+ "+ skip =+ \\\\\|\\ "+ end =+ "+ contains =rustSpecial,rustSpecialError ,rustStringContinuation
151
152
syn region rustString start =' r\z (#*\) "' end =' "\z 1'
152
153
153
154
syn region rustAttribute start =" #\[ " end =" \] " contains =rustString,rustDeriving
154
155
syn region rustDeriving start =" deriving(" end =" )" contained contains =rustTrait
155
156
156
157
" Number literals
157
- syn match rustNumber display " \< [0-9][0-9_]*\> "
158
- syn match rustNumber display " \< [0-9][0-9_]*\( u\| u8\| u16\| u32\| u64\)\> "
159
- syn match rustNumber display " \< [0-9][0-9_]*\( i\| i8\| i16\| i32\| i64\)\> "
160
-
161
- syn match rustHexNumber display " \< 0x[a-fA-F0-9_]\+\> "
162
- syn match rustHexNumber display " \< 0x[a-fA-F0-9_]\+\( u\| u8\| u16\| u32\| u64\)\> "
163
- syn match rustHexNumber display " \< 0x[a-fA-F0-9_]\+\( i8\| i16\| i32\| i64\)\> "
164
- syn match rustOctNumber display " \< 0o[0-7_]\+\> "
165
- syn match rustOctNumber display " \< 0o[0-7_]\+\( u\| u8\| u16\| u32\| u64\)\> "
166
- syn match rustOctNumber display " \< 0o[0-7_]\+\( i8\| i16\| i32\| i64\)\> "
167
- syn match rustBinNumber display " \< 0b[01_]\+\> "
168
- syn match rustBinNumber display " \< 0b[01_]\+\( u\| u8\| u16\| u32\| u64\)\> "
169
- syn match rustBinNumber display " \< 0b[01_]\+\( i8\| i16\| i32\| i64\)\> "
170
-
171
- syn match rustFloat display " \< [0-9][0-9_]*\( f\| f32\| f64\)\> "
172
- syn match rustFloat display " \< [0-9][0-9_]*\( [eE][+-]\= [0-9_]\+\)\> "
173
- syn match rustFloat display " \< [0-9][0-9_]*\( [eE][+-]\= [0-9_]\+\)\( f\| f32\| f64\)\> "
174
- syn match rustFloat display " \< [0-9][0-9_]*\. [0-9_]\+\> "
175
- syn match rustFloat display " \< [0-9][0-9_]*\. [0-9_]\+\( f\| f32\| f64\)\> "
176
- syn match rustFloat display " \< [0-9][0-9_]*\. [0-9_]\+\% ([eE][+-]\= [0-9_]\+\)\> "
177
- syn match rustFloat display " \< [0-9][0-9_]*\. [0-9_]\+\% ([eE][+-]\= [0-9_]\+\)\( f\| f32\| f64\)\> "
158
+ syn match rustDecNumber display " \< [0-9][0-9_]*\% ([iu]\% (8\| 16\| 32\| 64\)\=\)\= "
159
+ syn match rustHexNumber display " \< 0x[a-fA-F0-9_]\+\% ([iu]\% (8\| 16\| 32\| 64\)\=\)\= "
160
+ syn match rustOctNumber display " \< 0o[0-7_]\+\% ([iu]\% (8\| 16\| 32\| 64\)\=\)\= "
161
+ syn match rustBinNumber display " \< 0b[01_]\+\% ([iu]\% (8\| 16\| 32\| 64\)\=\)\= "
162
+
163
+ " To mark it as a float, it must have at least one of the three things integral values don't have:
164
+ " a decimal point and more numbers; an exponent; and a type suffix.
165
+ syn match rustFloat display " \< [0-9][0-9_]*\% (\. [0-9][0-9_]*\)\% ([eE][+-]\= [0-9_]\+\)\=\( f32\| f64\)\= "
166
+ syn match rustFloat display " \< [0-9][0-9_]*\% (\. [0-9][0-9_]*\)\=\% ([eE][+-]\= [0-9_]\+\)\( f32\| f64\)\= "
167
+ syn match rustFloat display " \< [0-9][0-9_]*\% (\. [0-9][0-9_]*\)\=\% ([eE][+-]\= [0-9_]\+\)\=\( f32\| f64\) "
168
+ " Special case for numbers of the form "1." which are float literals, unless followed by
169
+ " an identifier, which makes them integer literals with a method call or field access.
170
+ syn match rustFloat display " \< [0-9][0-9_]*\.\% ([^[:cntrl:][:space:][:punct:][:digit:]]\| _\)\@ !"
178
171
179
172
" For the benefit of delimitMate
180
173
syn region rustLifetimeCandidate display start =/ &'\% (\( [^'\\ ]\|\\\( ['nrt0\\\" ]\| x\x\{ 2}\| u\x\{ 4}\| U\x\{ 8}\)\) '\)\@ !/ end =/ [[:cntrl:][:space:][:punct:]]\@ =\| $/ contains =rustSigil,rustLifetime
@@ -183,12 +176,24 @@ syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[
183
176
184
177
" rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
185
178
syn match rustLifetime display " \'\% ([^[:cntrl:][:space:][:punct:][:digit:]]\| _\)\% ([^[:cntrl:][:punct:][:space:]]\| _\) *"
186
- syn match rustCharacter / '\( [^'\\ ]\|\\\( [nrt0\\ '"]\| x\x\{ 2}\| u\x\{ 4}\| U\x\{ 8}\)\) '/ contains =rustSpecial
187
-
188
- syn region rustCommentML start =" /\* " end =" \* /" contains =rustTodo
189
- syn region rustComment start =" //" end =" $" contains =rustTodo keepend
190
- syn region rustCommentMLDoc start =" /\*\% (!\|\* [*/]\@ !\) " end =" \* /" contains =rustTodo
191
- syn region rustCommentDoc start =" //\% (//\@ !\| !\) " end =" $" contains =rustTodo keepend
179
+ syn match rustCharacter / '\( [^'\\ ]\|\\\( .\| x\x\{ 2}\| u\x\{ 4}\| U\x\{ 8}\)\) '/ contains =rustSpecial,rustSpecialError
180
+
181
+ syn cluster rustComment contains =rustCommentLine,rustCommentLineDoc,rustCommentBlock,rustCommentBlockDoc
182
+ syn region rustCommentLine start =" //" end =" $" contains =rustTodo
183
+ syn region rustCommentLineDoc start =" //\% (//\@ !\| !\) " end =" $" contains =rustTodo
184
+ syn region rustCommentBlock matchgroup =rustCommentBlock start =" /\*\% (!\|\* [*/]\@ !\)\@ !" end =" \* /" contains =rustTodo,@rustComment keepend extend
185
+ syn region rustCommentBlockDoc matchgroup =rustCommentBlockDoc start =" /\*\% (!\|\* [*/]\@ !\) " end =" \* /" contains =rustTodo,@rustComment keepend extend
186
+ " FIXME: this is a really ugly and not fully correct implementation. Most
187
+ " importantly, a case like ``/* */*`` should have the final ``*`` not being in
188
+ " a comment, but in practice at present it leaves comments open two levels
189
+ " deep. But as long as you stay away from that particular case, I *believe*
190
+ " the highlighting is correct. Due to the way Vim's syntax engine works
191
+ " (greedy for start matches, unlike Rust's tokeniser which is searching for
192
+ " the earliest-starting match, start or end), I believe this cannot be solved.
193
+ " Oh you who would fix it, don't bother with things like duplicating the Block
194
+ " rules and putting ``\*\@<!`` at the start of them; it makes it worse, as
195
+ " then you must deal with cases like ``/*/**/*/``. And don't try making it
196
+ " worse with ``\%(/\@<!\*\)\@<!``, either...
192
197
193
198
syn keyword rustTodo contained TODO FIXME XXX NB NOTE
194
199
@@ -200,15 +205,16 @@ syn region rustFoldBraces start="{" end="}" transparent fold
200
205
" It's not enabled by default as it would drive some people mad.
201
206
202
207
" Default highlighting {{{1
208
+ hi def link rustDecNumber rustNumber
203
209
hi def link rustHexNumber rustNumber
204
210
hi def link rustOctNumber rustNumber
205
211
hi def link rustBinNumber rustNumber
206
212
hi def link rustIdentifierPrime rustIdentifier
207
213
hi def link rustTrait rustType
208
214
209
215
hi def link rustSigil StorageClass
210
- hi def link rustFormat Special
211
216
hi def link rustSpecial Special
217
+ hi def link rustSpecialError Error
212
218
hi def link rustStringContinuation Special
213
219
hi def link rustString String
214
220
hi def link rustCharacter Character
@@ -229,10 +235,10 @@ hi def link rustModPathSep Delimiter
229
235
hi def link rustFunction Function
230
236
hi def link rustFuncName Function
231
237
hi def link rustFuncCall Function
232
- hi def link rustCommentMLDoc rustCommentDoc
233
- hi def link rustCommentDoc SpecialComment
234
- hi def link rustCommentML rustComment
235
- hi def link rustComment Comment
238
+ hi def link rustCommentLine Comment
239
+ hi def link rustCommentLineDoc SpecialComment
240
+ hi def link rustCommentBlock rustCommentLine
241
+ hi def link rustCommentBlockDoc rustCommentLineDoc
236
242
hi def link rustAssert PreCondit
237
243
hi def link rustFail PreCondit
238
244
hi def link rustMacro Macro
0 commit comments