Skip to content

Commit c4b180a

Browse files
committed
Highlight everything in the prelude in Vim.
This is a rather more extensive change than the last, but *ever* so much easier to maintain reasonably, as there's then something to track directly.
1 parent afbf908 commit c4b180a

File tree

1 file changed

+78
-26
lines changed

1 file changed

+78
-26
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ 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,27 +34,80 @@ 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 Result Ordering
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 Freeze Send Owned Sized " inherent traits
52-
syn keyword rustTrait Clone DeepClone Decodable Encodable IterBytes Rand ToCStr ToStr ToStrConsume FromStr
53-
syn keyword rustTrait ApproxEq Eq Ord TotalEq TotalOrd Num Ptr Equiv
54-
syn keyword rustTrait Drop Add Sub Mul Div Rem Not 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
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
@@ -62,15 +117,7 @@ syn keyword rustConstant Left Right " either
62117
syn keyword rustConstant Ok Err " result
63118
syn keyword rustConstant Less Equal Greater " Ordering
64119

65-
" Constants from libc
66-
syn keyword rustConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
67-
syn keyword rustConstant EOF SEEK_SET SEEK_CUR SEEK_END _IOFBF _IONBF
68-
syn keyword rustConstant _IOLBF BUFSIZ FOPEN_MAX FILENAME_MAX L_tmpnam
69-
syn keyword rustConstant TMP_MAX O_RDONLY O_WRONLY O_RDWR O_APPEND O_CREAT
70-
syn keyword rustConstant O_EXCL O_TRUNC S_IFIFO S_IFCHR S_IFBLK S_IFDIR
71-
syn keyword rustConstant S_IFREG S_IFMT S_IEXEC S_IWRITE S_IREAD S_IRWXU
72-
syn keyword rustConstant S_IXUSR S_IWUSR S_IRUSR F_OK R_OK W_OK X_OK
73-
syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
120+
" Other syntax {{{2
74121

75122
" If foo::bar changes to foo.bar, change this ("::" to "\.").
76123
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
@@ -142,12 +189,14 @@ syn region rustCommentDoc start="//[/!]" end="$" contains=rustTodo keepend
142189

143190
syn keyword rustTodo contained TODO FIXME XXX NB NOTE
144191

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

199+
" Default highlighting {{{1
151200
hi def link rustHexNumber rustNumber
152201
hi def link rustBinNumber rustNumber
153202
hi def link rustIdentifierPrime rustIdentifier
@@ -161,6 +210,8 @@ 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)