Skip to content

Commit d709ed2

Browse files
committed
Merge pull request #2336 from tychosci/vim-syntax
Vim syntax update
2 parents 95a2b5d + 16848be commit d709ed2

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ if !exists("main_syntax")
1515
endif
1616

1717
syn keyword rustKeyword alt as assert be bind break
18-
syn keyword rustKeyword check claim cont const copy do else enum export fail
19-
syn keyword rustKeyword fn for if iface impl import in inline lambda let log
18+
syn keyword rustKeyword check claim cont const copy do else export fail
19+
syn keyword rustKeyword for if impl import in inline lambda let log
2020
syn keyword rustKeyword loop mod mut mutable native note of prove pure
21-
syn keyword rustKeyword resource ret self syntax to type unchecked
21+
syn keyword rustKeyword ret self syntax to unchecked
2222
syn keyword rustKeyword unsafe use while with
23+
" FIXME: Scoped impl's name is also fallen in this category
24+
syn keyword rustKeyword mod iface resource class enum type nextgroup=rustIdentifier skipwhite
25+
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
26+
27+
syn match rustIdentifier "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
28+
syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
2329

2430
" Reserved words
2531
syn keyword rustKeyword m32 m64 m128 f80 f16 f128 class trait
@@ -33,35 +39,48 @@ syn match rustItemPath "\(\w\|::\)\+"
3339

3440
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+
3541

36-
"integer number, or floating point number without a dot and with "f".
37-
syn case ignore
38-
syn match rustNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
39-
"hex number
40-
syn match rustNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
41-
syn match rustFloat display contained "\d\+f"
42-
"floating point number, with dot, optional exponent
43-
syn match rustFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
44-
"floating point number, starting with a dot, optional exponent
45-
syn match rustFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
46-
"floating point number, without dot, with exponent
47-
syn match rustFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>"
48-
49-
syn case match
42+
" Number literals
43+
syn match rustNumber display "\<[0-9][0-9_]*\>"
44+
syn match rustNumber display "\<[0-9][0-9_]*\(u\|u8\|u16\|u32\|u64\)\>"
45+
syn match rustNumber display "\<[0-9][0-9_]*\(i8\|i16\|i32\|i64\)\>"
46+
47+
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\>"
48+
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(u\|u8\|u16\|u32\|u64\)\>"
49+
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(i8\|i16\|i32\|i64\)\>"
50+
syn match rustBinNumber display "\<0b[01_]\+\>"
51+
syn match rustBinNumber display "\<0b[01_]\+\(u\|u8\|u16\|u32\|u64\)\>"
52+
syn match rustBinNumber display "\<0b[01_]\+\(i8\|i16\|i32\|i64\)\>"
53+
54+
syn match rustFloat display "\<[0-9][0-9_]*\(f\|f32\|f64\)\>"
55+
syn match rustFloat display "\<[0-9][0-9_]*\([eE][+-]\=[0-9_]\+\)\>"
56+
syn match rustFloat display "\<[0-9][0-9_]*\([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
57+
syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\>"
58+
syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\(f\|f32\|f64\)\>"
59+
syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\>"
60+
syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
5061

5162
syn match rustCharacter "'\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'"
5263

53-
syn region rustComment start="/\*" end="\*/" contains=rustComment
54-
syn region rustComment start="//" skip="\\$" end="$" keepend
64+
syn region rustComment start="/\*" end="\*/" contains=rustComment,rustTodo
65+
syn region rustComment start="//" skip="\\$" end="$" contains=rustTodo keepend
66+
67+
syn keyword rustTodo TODO FIXME XXX NB
68+
69+
hi def link rustHexNumber rustNumber
70+
hi def link rustBinNumber rustNumber
5571

5672
hi def link rustString String
5773
hi def link rustCharacter Character
5874
hi def link rustNumber Number
5975
hi def link rustBoolean Boolean
6076
hi def link rustFloat Float
6177
hi def link rustKeyword Keyword
78+
hi def link rustIdentifier Identifier
79+
hi def link rustFuncName Function
6280
hi def link rustComment Comment
6381
hi def link rustMacro Macro
6482
hi def link rustType Type
83+
hi def link rustTodo Todo
6584

6685
syn sync minlines=200
6786
syn sync maxlines=500

0 commit comments

Comments
 (0)