33" Maintainer: Patrick Walton <pcwalton@mozilla.com>
44" Maintainer: Ben Blum <bblum@cs.cmu.edu>
55" Maintainer: Chris Morgan <me@chrismorgan.info>
6- " Last Change: 2013 Oct 29
6+ " Last Change: 2013 Dec 04
77
88if version < 600
99 syntax clear
@@ -28,6 +28,7 @@ syn keyword rustKeyword use nextgroup=rustModPath skipwhite
2828" FIXME: Scoped impl's name is also fallen in this category
2929syn keyword rustKeyword mod trait struct enum type nextgroup =rustIdentifier skipwhite
3030syn keyword rustKeyword fn nextgroup =rustFuncName skipwhite
31+ syn keyword rustKeyword proc
3132syn keyword rustStorage const mut ref static
3233
3334syn match rustIdentifier contains =rustIdentifierPrime " \% ([^[:cntrl:][:space:][:punct:][:digit:]]\| _\)\% ([^[:cntrl:][:punct:][:space:]]\| _\) *" display contained
@@ -89,6 +90,7 @@ syn keyword rustTrait Orderable Signed Unsigned Round
8990syn keyword rustTrait Primitive Int Float ToStrRadix ToPrimitive FromPrimitive
9091syn keyword rustTrait GenericPath Path PosixPath WindowsPath
9192syn keyword rustTrait RawPtr
93+ syn keyword rustTrait Buffer Writer Reader Seek
9294syn keyword rustTrait SendStr SendStrOwned SendStrStatic IntoSendStr
9395syn keyword rustTrait Str StrVector StrSlice OwnedStr
9496syn keyword rustTrait IterBytes
@@ -143,38 +145,29 @@ syn match rustOperator display "&&\|||"
143145syn match rustMacro ' \w\(\w\) *!' contains =rustAssert,rustFail
144146syn match rustMacro ' #\w\(\w\) *' contains =rustAssert,rustFail
145147
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 / \\ ./
148149syn match rustSpecial display contained / \\\( [nrt0\\ '"]\| x\x\{ 2}\| u\x\{ 4}\| U\x\{ 8}\) /
149150syn 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
151152syn region rustString start =' r\z (#*\) "' end =' "\z 1'
152153
153154syn region rustAttribute start =" #\[ " end =" \] " contains =rustString,rustDeriving
154155syn region rustDeriving start =" deriving(" end =" )" contained contains =rustTrait
155156
156157" 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:]]\| _\)\@ !"
178171
179172" For the benefit of delimitMate
180173syn 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=/[
183176
184177" rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
185178syn 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...
192197
193198syn keyword rustTodo contained TODO FIXME XXX NB NOTE
194199
@@ -200,15 +205,16 @@ syn region rustFoldBraces start="{" end="}" transparent fold
200205" It's not enabled by default as it would drive some people mad.
201206
202207" Default highlighting {{{1
208+ hi def link rustDecNumber rustNumber
203209hi def link rustHexNumber rustNumber
204210hi def link rustOctNumber rustNumber
205211hi def link rustBinNumber rustNumber
206212hi def link rustIdentifierPrime rustIdentifier
207213hi def link rustTrait rustType
208214
209215hi def link rustSigil StorageClass
210- hi def link rustFormat Special
211216hi def link rustSpecial Special
217+ hi def link rustSpecialError Error
212218hi def link rustStringContinuation Special
213219hi def link rustString String
214220hi def link rustCharacter Character
@@ -229,10 +235,10 @@ hi def link rustModPathSep Delimiter
229235hi def link rustFunction Function
230236hi def link rustFuncName Function
231237hi 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
236242hi def link rustAssert PreCondit
237243hi def link rustFail PreCondit
238244hi def link rustMacro Macro
0 commit comments