3 " Maintainer: Patrick Walton <pcwalton@mozilla.com>
4 " Maintainer: Ben Blum <bblum@cs.cmu.edu>
5 " Last Change: 2012 Jun 14
9 elseif exists("b:current_syntax")
13 syn keyword rustConditional match if else
14 syn keyword rustOperator as
16 syn match rustAssert "\<assert\(\w\)*!"
17 syn match rustFail "\<fail\(\w\)*!"
18 syn keyword rustKeyword break copy do extern
19 syn keyword rustKeyword for if impl let log
20 syn keyword rustKeyword copy do extern
21 syn keyword rustKeyword for impl let log
22 syn keyword rustKeyword loop mod once priv pub
23 syn keyword rustKeyword return
24 syn keyword rustKeyword unsafe while
25 syn keyword rustKeyword use nextgroup=rustModPath skipwhite
26 " FIXME: Scoped impl's name is also fallen in this category
27 syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite
28 syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
29 syn keyword rustStorage const mut ref static
31 syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
32 syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
35 syn keyword rustKeyword be
37 syn keyword rustType int uint float char bool u8 u16 u32 u64 f32
38 syn keyword rustType f64 i8 i16 i32 i64 str Self
39 syn keyword rustType Option Either
42 syn keyword rustType c_float c_double c_void FILE fpos_t
43 syn keyword rustType DIR dirent
44 syn keyword rustType c_char c_schar c_uchar
45 syn keyword rustType c_short c_ushort c_int c_uint c_long c_ulong
46 syn keyword rustType size_t ptrdiff_t clock_t time_t
47 syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t
48 syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t
50 syn keyword rustTrait Const Copy Send Owned Sized " inherent traits
51 syn keyword rustTrait Clone Decodable Encodable IterBytes Rand ToStr
52 syn keyword rustTrait Eq Ord TotalEq TotalOrd Num Ptr
53 syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr
54 syn keyword rustTrait BitXor Shl Shr Index
56 syn keyword rustSelf self
57 syn keyword rustBoolean true false
59 syn keyword rustConstant Some None " option
60 syn keyword rustConstant Left Right " either
61 syn keyword rustConstant Ok Err " result
62 syn keyword rustConstant Success Failure " task
63 syn keyword rustConstant Cons Nil " list
64 " syn keyword rustConstant empty node " tree
67 syn keyword rustConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
68 syn keyword rustConstant EOF SEEK_SET SEEK_CUR SEEK_END _IOFBF _IONBF
69 syn keyword rustConstant _IOLBF BUFSIZ FOPEN_MAX FILENAME_MAX L_tmpnam
70 syn keyword rustConstant TMP_MAX O_RDONLY O_WRONLY O_RDWR O_APPEND O_CREAT
71 syn keyword rustConstant O_EXCL O_TRUNC S_IFIFO S_IFCHR S_IFBLK S_IFDIR
72 syn keyword rustConstant S_IFREG S_IFMT S_IEXEC S_IWRITE S_IREAD S_IRWXU
73 syn keyword rustConstant S_IXUSR S_IWUSR S_IRUSR F_OK R_OK W_OK X_OK
74 syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
76 " If foo::bar changes to foo.bar, change this ("::" to "\.").
77 " If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
78 syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3
79 syn match rustModPath "\w\(\w\)*" contained " only for 'use path;'
80 syn match rustModPathSep "::"
82 syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1
83 syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 " foo::<T>();
85 syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustFail
86 syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustFail
88 syn match rustFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn?]\|\[\^\=.[^]]*\]\)" contained
89 syn match rustFormat display "%%" contained
90 syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat
92 syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving
93 syn region rustDeriving start="deriving(" end=")" contains=rustTrait
96 syn match rustNumber display "\<[0-9][0-9_]*\>"
97 syn match rustNumber display "\<[0-9][0-9_]*\(u\|u8\|u16\|u32\|u64\)\>"
98 syn match rustNumber display "\<[0-9][0-9_]*\(i8\|i16\|i32\|i64\)\>"
100 syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\>"
101 syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(u\|u8\|u16\|u32\|u64\)\>"
102 syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(i8\|i16\|i32\|i64\)\>"
103 syn match rustBinNumber display "\<0b[01_]\+\>"
104 syn match rustBinNumber display "\<0b[01_]\+\(u\|u8\|u16\|u32\|u64\)\>"
105 syn match rustBinNumber display "\<0b[01_]\+\(i8\|i16\|i32\|i64\)\>"
107 syn match rustFloat display "\<[0-9][0-9_]*\(f\|f32\|f64\)\>"
108 syn match rustFloat display "\<[0-9][0-9_]*\([eE][+-]\=[0-9_]\+\)\>"
109 syn match rustFloat display "\<[0-9][0-9_]*\([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
110 syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\>"
111 syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\(f\|f32\|f64\)\>"
112 syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\>"
113 syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9_]\+\)\(f\|f32\|f64\)\>"
115 "rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting
116 syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"
117 syn match rustCharacter "'\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'"
119 syn region rustCommentDoc start="/\*[\*!]" end="\*/"
120 syn region rustCommentDoc start="//[/!]" skip="\\$" end="$" keepend
121 syn match rustComment "/\*\*/"
122 syn region rustComment start="/\*\([^\*!]\|$\)" end="\*/" contains=rustTodo
123 syn region rustComment start="//\([^/!]\|$\)" skip="\\$" end="$" contains=rustTodo keepend
125 syn keyword rustTodo contained TODO FIXME XXX NB
127 hi def link rustHexNumber rustNumber
128 hi def link rustBinNumber rustNumber
129 hi def link rustIdentifierPrime rustIdentifier
130 hi def link rustTrait rustType
132 hi def link rustFormat Special
133 hi def link rustString String
134 hi def link rustCharacter Character
135 hi def link rustNumber Number
136 hi def link rustBoolean Boolean
137 hi def link rustConstant Constant
138 hi def link rustSelf Constant
139 hi def link rustFloat Float
140 hi def link rustOperator Operator
141 hi def link rustKeyword Keyword
142 hi def link rustConditional Conditional
143 hi def link rustIdentifier Identifier
144 hi def link rustModPath Include
145 hi def link rustFuncName Function
146 hi def link rustCommentDoc SpecialComment
147 hi def link rustComment Comment
148 hi def link rustMacro Macro
149 hi def link rustType Type
150 hi def link rustTodo Todo
151 hi def link rustAttribute PreProc
152 hi def link rustDeriving PreProc
153 hi def link rustStorage StorageClass
154 hi def link rustLifetime Special
157 " hi rustAttribute ctermfg=cyan
158 " hi rustDeriving ctermfg=cyan
159 " hi rustAssert ctermfg=yellow
160 " hi rustFail ctermfg=red
161 " hi rustMacro ctermfg=magenta
162 " hi rustModPathSep ctermfg=grey
164 syn sync minlines=200
165 syn sync maxlines=500
167 let b:current_syntax = "rust"