Skip to content

Commit b659fe3

Browse files
committed
auto merge of #8951 : chris-morgan/rust/vim-update-highlighting, r=alexcrichton
Several changes with appropriate commit messages to explain them. The final two commits, highlighting everything in the prelude, may be a little controversial. I think it's the sensible way forward with it.
2 parents 64ff315 + 9f61804 commit b659fe3

File tree

2 files changed

+89
-35
lines changed

2 files changed

+89
-35
lines changed

src/etc/vim/ftplugin/rust.vim

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ else
2121
setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://
2222
endif
2323
setlocal commentstring=//%s
24-
setlocal formatoptions-=t formatoptions+=croqnlj
24+
setlocal formatoptions-=t formatoptions+=croqnl
25+
" j was only added in 7.3.541, so stop complaints about its nonexistence
26+
silent! setlocal formatoptions+=j
2527

2628
" This includeexpr isn't perfect, but it's a good start
2729
setlocal includeexpr=substitute(v:fname,'::','/','g')

src/etc/vim/syntax/rust.vim

+86-34
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
" Maintainer: Patrick Walton <[email protected]>
44
" Maintainer: Ben Blum <[email protected]>
55
" Maintainer: Chris Morgan <[email protected]>
6-
" Last Change: 2013 Aug 1
6+
" Last Change: 2013 Sep 4
77

88
if version < 600
99
syntax clear
1010
elseif exists("b:current_syntax")
1111
finish
1212
endif
1313

14+
" Syntax definitions {{{1
15+
" Basic keywords {{{2
1416
syn keyword rustConditional match if else
1517
syn keyword rustOperator as
1618

@@ -32,47 +34,90 @@ syn keyword rustStorage const mut ref static
3234
syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
3335
syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
3436

35-
" reserved
37+
" Reserved (but not yet used) keywords {{{2
3638
syn keyword rustKeyword be yield typeof
3739

40+
" Built-in types {{{2
3841
syn keyword rustType int uint float char bool u8 u16 u32 u64 f32
3942
syn keyword rustType f64 i8 i16 i32 i64 str Self
40-
syn keyword rustType Option Either
41-
42-
" Types from libc
43-
syn keyword rustType c_float c_double c_void FILE fpos_t
44-
syn keyword rustType DIR dirent
45-
syn keyword rustType c_char c_schar c_uchar
46-
syn keyword rustType c_short c_ushort c_int c_uint c_long c_ulong
47-
syn keyword rustType size_t ptrdiff_t clock_t time_t
48-
syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t
49-
syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t
50-
51-
syn keyword rustTrait Const Copy Send Owned Sized " inherent traits
52-
syn keyword rustTrait Clone Decodable Encodable IterBytes Rand ToStr
53-
syn keyword rustTrait Eq Ord TotalEq TotalOrd Num Ptr
54-
syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr
55-
syn keyword rustTrait BitXor Shl Shr Index
43+
44+
" Things from the prelude (src/libstd/prelude.rs) {{{2
45+
" This section is just straight transformation of the contents of the prelude,
46+
" to make it easy to update.
47+
48+
" Core operators {{{3
49+
syn keyword rustEnum Either
50+
syn keyword rustEnumVariant Left Right
51+
syn keyword rustTrait Sized
52+
syn keyword rustTrait Freeze Send
53+
syn keyword rustTrait Add Sub Mul Div Rem Neg Not
54+
syn keyword rustTrait BitAnd BitOr BitXor
55+
syn keyword rustTrait Drop
56+
syn keyword rustTrait Shl Shr Index
57+
syn keyword rustEnum Option
58+
syn keyword rustEnumVariant Some None
59+
syn keyword rustEnum Result
60+
syn keyword rustEnumVariant Ok Err
61+
62+
" Functions {{{3
63+
"syn keyword rustFunction print println
64+
"syn keyword rustFunction range
65+
66+
" Types and traits {{{3
67+
syn keyword rustTrait ToCStr
68+
syn keyword rustTrait Clone DeepClone
69+
syn keyword rustTrait Eq ApproxEq Ord TotalEq TotalOrd Ordering Equiv
70+
syn keyword rustEnumVariant Less Equal Greater
71+
syn keyword rustTrait Char
72+
syn keyword rustTrait Container Mutable Map MutableMap Set MutableSet
73+
syn keyword rustTrait Hash
74+
syn keyword rustTrait Times
75+
syn keyword rustTrait FromIterator Extendable
76+
syn keyword rustTrait Iterator DoubleEndedIterator RandomAccessIterator ClonableIterator
77+
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator ExactSize
78+
syn keyword rustTrait Num NumCast CheckedAdd CheckedSub CheckedMul
79+
syn keyword rustTrait Orderable Signed Unsigned Round
80+
syn keyword rustTrait Algebraic Trigonometric Exponential Hyperbolic
81+
syn keyword rustTrait Integer Fractional Real RealExt
82+
syn keyword rustTrait Bitwise BitCount Bounded
83+
syn keyword rustTrait Primitive Int Float ToStrRadix
84+
syn keyword rustTrait GenericPath
85+
syn keyword rustTrait Path
86+
syn keyword rustTrait PosixPath
87+
syn keyword rustTrait WindowsPath
88+
syn keyword rustTrait RawPtr
89+
syn keyword rustTrait Ascii AsciiCast OwnedAsciiCast AsciiStr ToBytesConsume
90+
syn keyword rustTrait Str StrVector StrSlice OwnedStr
91+
syn keyword rustTrait FromStr
92+
syn keyword rustTrait IterBytes
93+
syn keyword rustTrait ToStr ToStrConsume
94+
syn keyword rustTrait CopyableTuple ImmutableTuple
95+
syn keyword rustTrait CloneableTuple1 ImmutableTuple1
96+
syn keyword rustTrait CloneableTuple2 CloneableTuple3 CloneableTuple4 CloneableTuple5
97+
syn keyword rustTrait CloneableTuple6 CloneableTuple7 CloneableTuple8 CloneableTuple9
98+
syn keyword rustTrait CloneableTuple10 CloneableTuple11 CloneableTuple12
99+
syn keyword rustTrait ImmutableTuple2 ImmutableTuple3 ImmutableTuple4 ImmutableTuple5
100+
syn keyword rustTrait ImmutableTuple6 ImmutableTuple7 ImmutableTuple8 ImmutableTuple9
101+
syn keyword rustTrait ImmutableTuple10 ImmutableTuple11 ImmutableTuple12
102+
syn keyword rustTrait Vector VectorVector CopyableVector ImmutableVector
103+
syn keyword rustTrait ImmutableEqVector ImmutableTotalOrdVector ImmutableCopyableVector
104+
syn keyword rustTrait OwnedVector OwnedCopyableVector OwnedEqVector MutableVector
105+
syn keyword rustTrait Reader ReaderUtil Writer WriterUtil
106+
syn keyword rustTrait Default
107+
108+
"syn keyword rustFunction stream
109+
syn keyword rustTrait Port Chan GenericChan GenericSmartChan GenericPort Peekable
110+
"syn keyword rustFunction spawn
56111

57112
syn keyword rustSelf self
58113
syn keyword rustBoolean true false
59114

60115
syn keyword rustConstant Some None " option
61116
syn keyword rustConstant Left Right " either
62117
syn keyword rustConstant Ok Err " result
63-
syn keyword rustConstant Success Failure " task
64-
syn keyword rustConstant Cons Nil " list
65-
" syn keyword rustConstant empty node " tree
66-
67-
" Constants from libc
68-
syn keyword rustConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
69-
syn keyword rustConstant EOF SEEK_SET SEEK_CUR SEEK_END _IOFBF _IONBF
70-
syn keyword rustConstant _IOLBF BUFSIZ FOPEN_MAX FILENAME_MAX L_tmpnam
71-
syn keyword rustConstant TMP_MAX O_RDONLY O_WRONLY O_RDWR O_APPEND O_CREAT
72-
syn keyword rustConstant O_EXCL O_TRUNC S_IFIFO S_IFCHR S_IFBLK S_IFDIR
73-
syn keyword rustConstant S_IFREG S_IFMT S_IEXEC S_IWRITE S_IREAD S_IRWXU
74-
syn keyword rustConstant S_IXUSR S_IWUSR S_IRUSR F_OK R_OK W_OK X_OK
75-
syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
118+
syn keyword rustConstant Less Equal Greater " Ordering
119+
120+
" Other syntax {{{2
76121

77122
" If foo::bar changes to foo.bar, change this ("::" to "\.").
78123
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
@@ -102,7 +147,8 @@ syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustFail
102147
syn match rustFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn?]\|\[\^\=.[^]]*\]\)" contained
103148
syn match rustFormat display "%%" contained
104149
syn match rustSpecial display contained /\\\([nrt\\'"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)/
105-
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat,rustSpecial
150+
syn match rustStringContinuation display contained /\\\n\s*/
151+
syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat,rustSpecial,rustStringContinuation
106152

107153
syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving
108154
syn region rustDeriving start="deriving(" end=")" contained contains=rustTrait
@@ -137,18 +183,20 @@ syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit
137183
syn match rustCharacter /'\([^'\\]\|\\\([nrt\\'"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'/ contains=rustSpecial
138184

139185
syn region rustCommentML start="/\*" end="\*/" contains=rustTodo
140-
syn region rustComment start="//" skip="\\$" end="$" contains=rustTodo keepend
186+
syn region rustComment start="//" end="$" contains=rustTodo keepend
141187
syn region rustCommentMLDoc start="/\*\%(!\|\*/\@!\)" end="\*/" contains=rustTodo
142-
syn region rustCommentDoc start="//[/!]" skip="\\$" end="$" contains=rustTodo keepend
188+
syn region rustCommentDoc start="//[/!]" end="$" contains=rustTodo keepend
143189

144190
syn keyword rustTodo contained TODO FIXME XXX NB NOTE
145191

192+
" Folding rules {{{2
146193
" Trivial folding rules to begin with.
147194
" TODO: use the AST to make really good folding
148195
syn region rustFoldBraces start="{" end="}" transparent fold
149196
" If you wish to enable this, setlocal foldmethod=syntax
150197
" It's not enabled by default as it would drive some people mad.
151198

199+
" Default highlighting {{{1
152200
hi def link rustHexNumber rustNumber
153201
hi def link rustBinNumber rustNumber
154202
hi def link rustIdentifierPrime rustIdentifier
@@ -157,10 +205,13 @@ hi def link rustTrait rustType
157205
hi def link rustSigil StorageClass
158206
hi def link rustFormat Special
159207
hi def link rustSpecial Special
208+
hi def link rustStringContinuation Special
160209
hi def link rustString String
161210
hi def link rustCharacter Character
162211
hi def link rustNumber Number
163212
hi def link rustBoolean Boolean
213+
hi def link rustEnum rustType
214+
hi def link rustEnumVariant rustConstant
164215
hi def link rustConstant Constant
165216
hi def link rustSelf Constant
166217
hi def link rustFloat Float
@@ -171,6 +222,7 @@ hi def link rustIdentifier Identifier
171222
hi def link rustCapsIdent rustIdentifier
172223
hi def link rustModPath Include
173224
hi def link rustModPathSep Delimiter
225+
hi def link rustFunction Function
174226
hi def link rustFuncName Function
175227
hi def link rustFuncCall Function
176228
hi def link rustCommentMLDoc rustCommentDoc

0 commit comments

Comments
 (0)