Skip to content

Commit fcf3617

Browse files
committed
Add rules for assert, fail, and deriving to vim syntax file. Also highlight the mod path in "use module;" properly.
1 parent c17ff80 commit fcf3617

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Rust
33
" Maintainer: Patrick Walton <[email protected]>
44
" Maintainer: Ben Blum <[email protected]>
5-
" Last Change: 2012 Dec 25
5+
" Last Change: 2012 Jun 14
66

77
if version < 600
88
syntax clear
@@ -13,13 +13,16 @@ endif
1313
syn keyword rustConditional match if else
1414
syn keyword rustOperator as
1515

16+
syn match rustAssert "\<assert\(\w\)*!"
17+
syn match rustFail "\<fail\(\w\)*!"
1618
syn keyword rustKeyword break copy do drop extern
1719
syn keyword rustKeyword for if impl let log
1820
syn keyword rustKeyword copy do extern
1921
syn keyword rustKeyword for impl let log
2022
syn keyword rustKeyword loop mod once priv pub
2123
syn keyword rustKeyword return
22-
syn keyword rustKeyword unsafe use while
24+
syn keyword rustKeyword unsafe while
25+
syn keyword rustKeyword use nextgroup=rustModPath skipwhite
2326
" FIXME: Scoped impl's name is also fallen in this category
2427
syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite
2528
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
@@ -45,7 +48,8 @@ syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t
4548
syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t
4649

4750
syn keyword rustTrait Const Copy Send Owned Sized " inherent traits
48-
syn keyword rustTrait Eq Ord Num Ptr
51+
syn keyword rustTrait Clone Decodable Encodable IterBytes Rand ToStr
52+
syn keyword rustTrait Eq Ord TotalEq TotalOrd Num Ptr
4953
syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr
5054
syn keyword rustTrait BitXor Shl Shr Index
5155

@@ -72,19 +76,21 @@ syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
7276
" If foo::bar changes to foo.bar, change this ("::" to "\.").
7377
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
7478
syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3
79+
syn match rustModPath "\w\(\w\)*" contained " only for 'use path;'
7580
syn match rustModPathSep "::"
7681

7782
syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1
7883
syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 " foo::<T>();
7984

80-
syn match rustMacro '\w\(\w\)*!'
81-
syn match rustMacro '#\w\(\w\)*'
85+
syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustFail
86+
syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustFail
8287

8388
syn match rustFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn?]\|\[\^\=.[^]]*\]\)" contained
8489
syn match rustFormat display "%%" contained
8590
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat
8691

87-
syn region rustAttribute start="#\[" end="\]" contains=rustString
92+
syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving
93+
syn region rustDeriving start="deriving(" end=")" contains=rustTrait
8894

8995
" Number literals
9096
syn match rustNumber display "\<[0-9][0-9_]*\>"
@@ -143,11 +149,17 @@ hi def link rustMacro Macro
143149
hi def link rustType Type
144150
hi def link rustTodo Todo
145151
hi def link rustAttribute PreProc
152+
hi def link rustDeriving PreProc
146153
hi def link rustStorage StorageClass
147154
hi def link rustLifetime Special
148155

149156
" Other Suggestions:
157+
" hi rustAttribute ctermfg=cyan
158+
" hi rustDeriving ctermfg=cyan
159+
" hi rustAssert ctermfg=yellow
160+
" hi rustFail ctermfg=red
150161
" hi rustMacro ctermfg=magenta
162+
" hi rustModPathSep ctermfg=grey
151163

152164
syn sync minlines=200
153165
syn sync maxlines=500

0 commit comments

Comments
 (0)