Mercurial > vim
comparison runtime/syntax/rust.vim @ 33255:555fede66c30
runtime(rust): sync rust runtime files with upstream (#13075)
Commit: https://github.com/vim/vim/commit/fc93594d562dbbd9da03c89754538f91efd0c7ca
Author: Gregory Anders <8965202+gpanders@users.noreply.github.com>
Date: Tue Sep 12 13:23:38 2023 -0500
runtime(rust): sync rust runtime files with upstream (https://github.com/vim/vim/issues/13075)
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Sep 2023 20:30:07 +0200 |
parents | 146a1e213b60 |
children |
comparison
equal
deleted
inserted
replaced
33254:d4a558720faf | 33255:555fede66c30 |
---|---|
1 " Vim syntax file | 1 " Vim syntax file |
2 " Language: Rust | 2 " Language: Rust |
3 " Maintainer: Patrick Walton <pcwalton@mozilla.com> | 3 " Maintainer: Patrick Walton <pcwalton@mozilla.com> |
4 " Maintainer: Ben Blum <bblum@cs.cmu.edu> | 4 " Maintainer: Ben Blum <bblum@cs.cmu.edu> |
5 " Maintainer: Chris Morgan <me@chrismorgan.info> | 5 " Maintainer: Chris Morgan <me@chrismorgan.info> |
6 " Last Change: Feb 24, 2016 | 6 " Last Change: 2023-09-11 |
7 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim | 7 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim |
8 | 8 |
9 if version < 600 | 9 if version < 600 |
10 syntax clear | 10 syntax clear |
11 elseif exists("b:current_syntax") | 11 elseif exists("b:current_syntax") |
12 finish | 12 finish |
13 endif | 13 endif |
14 | 14 |
15 " Syntax definitions {{{1 | 15 " Syntax definitions {{{1 |
16 " Basic keywords {{{2 | 16 " Basic keywords {{{2 |
17 syn keyword rustConditional match if else | 17 syn keyword rustConditional match if else |
18 syn keyword rustRepeat for loop while | 18 syn keyword rustRepeat loop while |
19 " `:syn match` must be used to prioritize highlighting `for` keyword. | |
20 syn match rustRepeat /\<for\>/ | |
21 " Highlight `for` keyword in `impl ... for ... {}` statement. This line must | |
22 " be put after previous `syn match` line to overwrite it. | |
23 syn match rustKeyword /\%(\<impl\>.\+\)\@<=\<for\>/ | |
24 syn keyword rustRepeat in | |
19 syn keyword rustTypedef type nextgroup=rustIdentifier skipwhite skipempty | 25 syn keyword rustTypedef type nextgroup=rustIdentifier skipwhite skipempty |
20 syn keyword rustStructure struct enum nextgroup=rustIdentifier skipwhite skipempty | 26 syn keyword rustStructure struct enum nextgroup=rustIdentifier skipwhite skipempty |
21 syn keyword rustUnion union nextgroup=rustIdentifier skipwhite skipempty contained | 27 syn keyword rustUnion union nextgroup=rustIdentifier skipwhite skipempty contained |
22 syn match rustUnionContextual /\<union\_s\+\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*/ transparent contains=rustUnion | 28 syn match rustUnionContextual /\<union\_s\+\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*/ transparent contains=rustUnion |
23 syn keyword rustOperator as | 29 syn keyword rustOperator as |
30 syn keyword rustExistential existential nextgroup=rustTypedef skipwhite skipempty contained | |
31 syn match rustExistentialContextual /\<existential\_s\+type/ transparent contains=rustExistential,rustTypedef | |
24 | 32 |
25 syn match rustAssert "\<assert\(\w\)*!" contained | 33 syn match rustAssert "\<assert\(\w\)*!" contained |
26 syn match rustPanic "\<panic\(\w\)*!" contained | 34 syn match rustPanic "\<panic\(\w\)*!" contained |
35 syn match rustAsync "\<async\%(\s\|\n\)\@=" | |
27 syn keyword rustKeyword break | 36 syn keyword rustKeyword break |
28 syn keyword rustKeyword box nextgroup=rustBoxPlacement skipwhite skipempty | 37 syn keyword rustKeyword box |
29 syn keyword rustKeyword continue | 38 syn keyword rustKeyword continue |
39 syn keyword rustKeyword crate | |
30 syn keyword rustKeyword extern nextgroup=rustExternCrate,rustObsoleteExternMod skipwhite skipempty | 40 syn keyword rustKeyword extern nextgroup=rustExternCrate,rustObsoleteExternMod skipwhite skipempty |
31 syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite skipempty | 41 syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite skipempty |
32 syn keyword rustKeyword in impl let | 42 syn keyword rustKeyword impl let |
43 syn keyword rustKeyword macro | |
33 syn keyword rustKeyword pub nextgroup=rustPubScope skipwhite skipempty | 44 syn keyword rustKeyword pub nextgroup=rustPubScope skipwhite skipempty |
34 syn keyword rustKeyword return | 45 syn keyword rustKeyword return |
46 syn keyword rustKeyword yield | |
35 syn keyword rustSuper super | 47 syn keyword rustSuper super |
36 syn keyword rustKeyword unsafe where | 48 syn keyword rustKeyword where |
49 syn keyword rustUnsafeKeyword unsafe | |
37 syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty | 50 syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty |
38 " FIXME: Scoped impl's name is also fallen in this category | 51 " FIXME: Scoped impl's name is also fallen in this category |
39 syn keyword rustKeyword mod trait nextgroup=rustIdentifier skipwhite skipempty | 52 syn keyword rustKeyword mod trait nextgroup=rustIdentifier skipwhite skipempty |
40 syn keyword rustStorage move mut ref static const | 53 syn keyword rustStorage move mut ref static const |
41 syn match rustDefault /\<default\ze\_s\+\(impl\|fn\|type\|const\)\>/ | 54 syn match rustDefault /\<default\ze\_s\+\(impl\|fn\|type\|const\)\>/ |
42 | 55 syn keyword rustAwait await |
43 syn keyword rustInvalidBareKeyword crate | 56 syn match rustKeyword /\<try\>!\@!/ display |
44 | 57 |
45 syn keyword rustPubScopeCrate crate contained | 58 syn keyword rustPubScopeCrate crate contained |
46 syn match rustPubScopeDelim /[()]/ contained | 59 syn match rustPubScopeDelim /[()]/ contained |
47 syn match rustPubScope /([^()]*)/ contained contains=rustPubScopeDelim,rustPubScopeCrate,rustSuper,rustModPath,rustModPathSep,rustSelf transparent | 60 syn match rustPubScope /([^()]*)/ contained contains=rustPubScopeDelim,rustPubScopeCrate,rustSuper,rustModPath,rustModPathSep,rustSelf transparent |
48 | 61 |
50 " This is to get the `bar` part of `extern crate "foo" as bar;` highlighting. | 63 " This is to get the `bar` part of `extern crate "foo" as bar;` highlighting. |
51 syn match rustExternCrateString /".*"\_s*as/ contained nextgroup=rustIdentifier skipwhite transparent skipempty contains=rustString,rustOperator | 64 syn match rustExternCrateString /".*"\_s*as/ contained nextgroup=rustIdentifier skipwhite transparent skipempty contains=rustString,rustOperator |
52 syn keyword rustObsoleteExternMod mod contained nextgroup=rustIdentifier skipwhite skipempty | 65 syn keyword rustObsoleteExternMod mod contained nextgroup=rustIdentifier skipwhite skipempty |
53 | 66 |
54 syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained | 67 syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained |
55 syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained | 68 syn match rustFuncName "\%(r#\)\=\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained |
56 | 69 |
57 syn region rustBoxPlacement matchgroup=rustBoxPlacementParens start="(" end=")" contains=TOP contained | 70 syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end="),\=[*+]" contains=TOP |
58 " Ideally we'd have syntax rules set up to match arbitrary expressions. Since | |
59 " we don't, we'll just define temporary contained rules to handle balancing | |
60 " delimiters. | |
61 syn region rustBoxPlacementBalance start="(" end=")" containedin=rustBoxPlacement transparent | |
62 syn region rustBoxPlacementBalance start="\[" end="\]" containedin=rustBoxPlacement transparent | |
63 " {} are handled by rustFoldBraces | |
64 | |
65 syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end=")" contains=TOP nextgroup=rustMacroRepeatCount | |
66 syn match rustMacroRepeatCount ".\?[*+]" contained | |
67 syn match rustMacroVariable "$\w\+" | 71 syn match rustMacroVariable "$\w\+" |
72 syn match rustRawIdent "\<r#\h\w*" contains=NONE | |
68 | 73 |
69 " Reserved (but not yet used) keywords {{{2 | 74 " Reserved (but not yet used) keywords {{{2 |
70 syn keyword rustReservedKeyword alignof become do offsetof priv pure sizeof typeof unsized yield abstract virtual final override macro | 75 syn keyword rustReservedKeyword become do priv typeof unsized abstract virtual final override |
71 | 76 |
72 " Built-in types {{{2 | 77 " Built-in types {{{2 |
73 syn keyword rustType isize usize char bool u8 u16 u32 u64 u128 f32 | 78 syn keyword rustType isize usize char bool u8 u16 u32 u64 u128 f32 |
74 syn keyword rustType f64 i8 i16 i32 i64 i128 str Self | 79 syn keyword rustType f64 i8 i16 i32 i64 i128 str Self |
75 | 80 |
136 syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustPanic | 141 syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustPanic |
137 syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustPanic | 142 syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustPanic |
138 | 143 |
139 syn match rustEscapeError display contained /\\./ | 144 syn match rustEscapeError display contained /\\./ |
140 syn match rustEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/ | 145 syn match rustEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/ |
141 syn match rustEscapeUnicode display contained /\\u{\x\{1,6}}/ | 146 syn match rustEscapeUnicode display contained /\\u{\%(\x_*\)\{1,6}}/ |
142 syn match rustStringContinuation display contained /\\\n\s*/ | 147 syn match rustStringContinuation display contained /\\\n\s*/ |
143 syn region rustString start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation | 148 syn region rustString matchgroup=rustStringDelimiter start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation |
144 syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell | 149 syn region rustString matchgroup=rustStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell |
145 syn region rustString start='b\?r\z(#*\)"' end='"\z1' contains=@Spell | 150 syn region rustString matchgroup=rustStringDelimiter start='b\?r\z(#*\)"' end='"\z1' contains=@Spell |
146 | 151 |
147 syn region rustAttribute start="#!\?\[" end="\]" contains=rustString,rustDerive,rustCommentLine,rustCommentBlock,rustCommentLineDocError,rustCommentBlockDocError | 152 " Match attributes with either arbitrary syntax or special highlighting for |
153 " derives. We still highlight strings and comments inside of the attribute. | |
154 syn region rustAttribute start="#!\?\[" end="\]" contains=@rustAttributeContents,rustAttributeParenthesizedParens,rustAttributeParenthesizedCurly,rustAttributeParenthesizedBrackets,rustDerive | |
155 syn region rustAttributeParenthesizedParens matchgroup=rustAttribute start="\w\%(\w\)*("rs=e end=")"re=s transparent contained contains=rustAttributeBalancedParens,@rustAttributeContents | |
156 syn region rustAttributeParenthesizedCurly matchgroup=rustAttribute start="\w\%(\w\)*{"rs=e end="}"re=s transparent contained contains=rustAttributeBalancedCurly,@rustAttributeContents | |
157 syn region rustAttributeParenthesizedBrackets matchgroup=rustAttribute start="\w\%(\w\)*\["rs=e end="\]"re=s transparent contained contains=rustAttributeBalancedBrackets,@rustAttributeContents | |
158 syn region rustAttributeBalancedParens matchgroup=rustAttribute start="("rs=e end=")"re=s transparent contained contains=rustAttributeBalancedParens,@rustAttributeContents | |
159 syn region rustAttributeBalancedCurly matchgroup=rustAttribute start="{"rs=e end="}"re=s transparent contained contains=rustAttributeBalancedCurly,@rustAttributeContents | |
160 syn region rustAttributeBalancedBrackets matchgroup=rustAttribute start="\["rs=e end="\]"re=s transparent contained contains=rustAttributeBalancedBrackets,@rustAttributeContents | |
161 syn cluster rustAttributeContents contains=rustString,rustCommentLine,rustCommentBlock,rustCommentLineDocError,rustCommentBlockDocError | |
148 syn region rustDerive start="derive(" end=")" contained contains=rustDeriveTrait | 162 syn region rustDerive start="derive(" end=")" contained contains=rustDeriveTrait |
149 " This list comes from src/libsyntax/ext/deriving/mod.rs | 163 " This list comes from src/libsyntax/ext/deriving/mod.rs |
150 " Some are deprecated (Encodable, Decodable) or to be removed after a new snapshot (Show). | 164 " Some are deprecated (Encodable, Decodable) or to be removed after a new snapshot (Show). |
151 syn keyword rustDeriveTrait contained Clone Hash RustcEncodable RustcDecodable Encodable Decodable PartialEq Eq PartialOrd Ord Rand Show Debug Default FromPrimitive Send Sync Copy | 165 syn keyword rustDeriveTrait contained Clone Hash RustcEncodable RustcDecodable Encodable Decodable PartialEq Eq PartialOrd Ord Rand Show Debug Default FromPrimitive Send Sync Copy |
166 | |
167 " dyn keyword: It's only a keyword when used inside a type expression, so | |
168 " we make effort here to highlight it only when Rust identifiers follow it | |
169 " (not minding the case of pre-2018 Rust where a path starting with :: can | |
170 " follow). | |
171 " | |
172 " This is so that uses of dyn variable names such as in 'let &dyn = &2' | |
173 " and 'let dyn = 2' will not get highlighted as a keyword. | |
174 syn match rustKeyword "\<dyn\ze\_s\+\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)" contains=rustDynKeyword | |
175 syn keyword rustDynKeyword dyn contained | |
152 | 176 |
153 " Number literals | 177 " Number literals |
154 syn match rustDecNumber display "\<[0-9][0-9_]*\%([iu]\%(size\|8\|16\|32\|64\|128\)\)\=" | 178 syn match rustDecNumber display "\<[0-9][0-9_]*\%([iu]\%(size\|8\|16\|32\|64\|128\)\)\=" |
155 syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\%([iu]\%(size\|8\|16\|32\|64\|128\)\)\=" | 179 syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\%([iu]\%(size\|8\|16\|32\|64\|128\)\)\=" |
156 syn match rustOctNumber display "\<0o[0-7_]\+\%([iu]\%(size\|8\|16\|32\|64\|128\)\)\=" | 180 syn match rustOctNumber display "\<0o[0-7_]\+\%([iu]\%(size\|8\|16\|32\|64\|128\)\)\=" |
166 syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)\=" | 190 syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)\=" |
167 syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\(f32\|f64\)\=" | 191 syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\(f32\|f64\)\=" |
168 syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)" | 192 syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)" |
169 | 193 |
170 " For the benefit of delimitMate | 194 " For the benefit of delimitMate |
171 syn region rustLifetimeCandidate display start=/&'\%(\([^'\\]\|\\\(['nrt0\\\"]\|x\x\{2}\|u{\x\{1,6}}\)\)'\)\@!/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime | 195 syn region rustLifetimeCandidate display start=/&'\%(\([^'\\]\|\\\(['nrt0\\\"]\|x\x\{2}\|u{\%(\x_*\)\{1,6}}\)\)'\)\@!/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime |
172 syn region rustGenericRegion display start=/<\%('\|[^[cntrl:][:space:][:punct:]]\)\@=')\S\@=/ end=/>/ contains=rustGenericLifetimeCandidate | 196 syn region rustGenericRegion display start=/<\%('\|[^[:cntrl:][:space:][:punct:]]\)\@=')\S\@=/ end=/>/ contains=rustGenericLifetimeCandidate |
173 syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime | 197 syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime |
174 | 198 |
175 "rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting | 199 "rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting |
176 syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" | 200 syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" |
177 syn match rustLabel display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*:" | 201 syn match rustLabel display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*:" |
202 syn match rustLabel display "\%(\<\%(break\|continue\)\s*\)\@<=\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" | |
178 syn match rustCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/ | 203 syn match rustCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/ |
179 " The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII). | 204 " The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII). |
180 syn match rustCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/ | 205 syn match rustCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/ |
181 syn match rustCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError,rustCharacterInvalid,rustCharacterInvalidUnicode | 206 syn match rustCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError,rustCharacterInvalid,rustCharacterInvalidUnicode |
182 syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u{\x\{1,6}}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid | 207 syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u{\%(\x_*\)\{1,6}}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid |
183 | 208 |
184 syn match rustShebang /\%^#![^[].*/ | 209 syn match rustShebang /\%^#![^[].*/ |
185 syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell | 210 syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell |
186 syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell | 211 syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell |
187 syn region rustCommentLineDocError start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell contained | 212 syn region rustCommentLineDocError start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell contained |
188 syn region rustCommentBlock matchgroup=rustCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell | 213 syn region rustCommentBlock matchgroup=rustCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell |
189 syn region rustCommentBlockDoc matchgroup=rustCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell | 214 syn region rustCommentBlockDoc matchgroup=rustCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNest,rustCommentBlockDocRustCode,@Spell |
190 syn region rustCommentBlockDocError matchgroup=rustCommentBlockDocError start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNestError,@Spell contained | 215 syn region rustCommentBlockDocError matchgroup=rustCommentBlockDocError start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNestError,@Spell contained |
191 syn region rustCommentBlockNest matchgroup=rustCommentBlock start="/\*" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell contained transparent | 216 syn region rustCommentBlockNest matchgroup=rustCommentBlock start="/\*" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell contained transparent |
192 syn region rustCommentBlockDocNest matchgroup=rustCommentBlockDoc start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell contained transparent | 217 syn region rustCommentBlockDocNest matchgroup=rustCommentBlockDoc start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell contained transparent |
193 syn region rustCommentBlockDocNestError matchgroup=rustCommentBlockDocError start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNestError,@Spell contained transparent | 218 syn region rustCommentBlockDocNestError matchgroup=rustCommentBlockDocError start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNestError,@Spell contained transparent |
219 | |
194 " FIXME: this is a really ugly and not fully correct implementation. Most | 220 " FIXME: this is a really ugly and not fully correct implementation. Most |
195 " importantly, a case like ``/* */*`` should have the final ``*`` not being in | 221 " importantly, a case like ``/* */*`` should have the final ``*`` not being in |
196 " a comment, but in practice at present it leaves comments open two levels | 222 " a comment, but in practice at present it leaves comments open two levels |
197 " deep. But as long as you stay away from that particular case, I *believe* | 223 " deep. But as long as you stay away from that particular case, I *believe* |
198 " the highlighting is correct. Due to the way Vim's syntax engine works | 224 " the highlighting is correct. Due to the way Vim's syntax engine works |
201 " Oh you who would fix it, don't bother with things like duplicating the Block | 227 " Oh you who would fix it, don't bother with things like duplicating the Block |
202 " rules and putting ``\*\@<!`` at the start of them; it makes it worse, as | 228 " rules and putting ``\*\@<!`` at the start of them; it makes it worse, as |
203 " then you must deal with cases like ``/*/**/*/``. And don't try making it | 229 " then you must deal with cases like ``/*/**/*/``. And don't try making it |
204 " worse with ``\%(/\@<!\*\)\@<!``, either... | 230 " worse with ``\%(/\@<!\*\)\@<!``, either... |
205 | 231 |
206 syn keyword rustTodo contained TODO FIXME XXX NB NOTE | 232 syn keyword rustTodo contained TODO FIXME XXX NB NOTE SAFETY |
233 | |
234 " asm! macro {{{2 | |
235 syn region rustAsmMacro matchgroup=rustMacro start="\<asm!\s*(" end=")" contains=rustAsmDirSpec,rustAsmSym,rustAsmConst,rustAsmOptionsGroup,rustComment.*,rustString.* | |
236 | |
237 " Clobbered registers | |
238 syn keyword rustAsmDirSpec in out lateout inout inlateout contained nextgroup=rustAsmReg skipwhite skipempty | |
239 syn region rustAsmReg start="(" end=")" contained contains=rustString | |
240 | |
241 " Symbol operands | |
242 syn keyword rustAsmSym sym contained nextgroup=rustAsmSymPath skipwhite skipempty | |
243 syn region rustAsmSymPath start="\S" end=",\|)"me=s-1 contained contains=rustComment.*,rustIdentifier | |
244 | |
245 " Const | |
246 syn region rustAsmConstBalancedParens start="("ms=s+1 end=")" contained contains=@rustAsmConstExpr | |
247 syn cluster rustAsmConstExpr contains=rustComment.*,rust.*Number,rustString,rustAsmConstBalancedParens | |
248 syn region rustAsmConst start="const" end=",\|)"me=s-1 contained contains=rustStorage,@rustAsmConstExpr | |
249 | |
250 " Options | |
251 syn region rustAsmOptionsGroup start="options\s*(" end=")" contained contains=rustAsmOptions,rustAsmOptionsKey | |
252 syn keyword rustAsmOptionsKey options contained | |
253 syn keyword rustAsmOptions pure nomem readonly preserves_flags noreturn nostack att_syntax contained | |
207 | 254 |
208 " Folding rules {{{2 | 255 " Folding rules {{{2 |
209 " Trivial folding rules to begin with. | 256 " Trivial folding rules to begin with. |
210 " FIXME: use the AST to make really good folding | 257 " FIXME: use the AST to make really good folding |
211 syn region rustFoldBraces start="{" end="}" transparent fold | 258 syn region rustFoldBraces start="{" end="}" transparent fold |
259 | |
260 if !exists("b:current_syntax_embed") | |
261 let b:current_syntax_embed = 1 | |
262 syntax include @RustCodeInComment <sfile>:p:h/rust.vim | |
263 unlet b:current_syntax_embed | |
264 | |
265 " Currently regions marked as ```<some-other-syntax> will not get | |
266 " highlighted at all. In the future, we can do as vim-markdown does and | |
267 " highlight with the other syntax. But for now, let's make sure we find | |
268 " the closing block marker, because the rules below won't catch it. | |
269 syn region rustCommentLinesDocNonRustCode matchgroup=rustCommentDocCodeFence start='^\z(\s*//[!/]\s*```\).\+$' end='^\z1$' keepend contains=rustCommentLineDoc | |
270 | |
271 " We borrow the rules from rust’s src/librustdoc/html/markdown.rs, so that | |
272 " we only highlight as Rust what it would perceive as Rust (almost; it’s | |
273 " possible to trick it if you try hard, and indented code blocks aren’t | |
274 " supported because Markdown is a menace to parse and only mad dogs and | |
275 " Englishmen would try to handle that case correctly in this syntax file). | |
276 syn region rustCommentLinesDocRustCode matchgroup=rustCommentDocCodeFence start='^\z(\s*//[!/]\s*```\)[^A-Za-z0-9_-]*\%(\%(should_panic\|no_run\|ignore\|allow_fail\|rust\|test_harness\|compile_fail\|E\d\{4}\|edition201[58]\)\%([^A-Za-z0-9_-]\+\|$\)\)*$' end='^\z1$' keepend contains=@RustCodeInComment,rustCommentLineDocLeader | |
277 syn region rustCommentBlockDocRustCode matchgroup=rustCommentDocCodeFence start='^\z(\%(\s*\*\)\?\s*```\)[^A-Za-z0-9_-]*\%(\%(should_panic\|no_run\|ignore\|allow_fail\|rust\|test_harness\|compile_fail\|E\d\{4}\|edition201[58]\)\%([^A-Za-z0-9_-]\+\|$\)\)*$' end='^\z1$' keepend contains=@RustCodeInComment,rustCommentBlockDocStar | |
278 " Strictly, this may or may not be correct; this code, for example, would | |
279 " mishighlight: | |
280 " | |
281 " /** | |
282 " ```rust | |
283 " println!("{}", 1 | |
284 " * 1); | |
285 " ``` | |
286 " */ | |
287 " | |
288 " … but I don’t care. Balance of probability, and all that. | |
289 syn match rustCommentBlockDocStar /^\s*\*\s\?/ contained | |
290 syn match rustCommentLineDocLeader "^\s*//\%(//\@!\|!\)" contained | |
291 endif | |
212 | 292 |
213 " Default highlighting {{{1 | 293 " Default highlighting {{{1 |
214 hi def link rustDecNumber rustNumber | 294 hi def link rustDecNumber rustNumber |
215 hi def link rustHexNumber rustNumber | 295 hi def link rustHexNumber rustNumber |
216 hi def link rustOctNumber rustNumber | 296 hi def link rustOctNumber rustNumber |
217 hi def link rustBinNumber rustNumber | 297 hi def link rustBinNumber rustNumber |
218 hi def link rustIdentifierPrime rustIdentifier | 298 hi def link rustIdentifierPrime rustIdentifier |
219 hi def link rustTrait rustType | 299 hi def link rustTrait rustType |
220 hi def link rustDeriveTrait rustTrait | 300 hi def link rustDeriveTrait rustTrait |
221 | 301 |
222 hi def link rustMacroRepeatCount rustMacroRepeatDelimiters | |
223 hi def link rustMacroRepeatDelimiters Macro | 302 hi def link rustMacroRepeatDelimiters Macro |
224 hi def link rustMacroVariable Define | 303 hi def link rustMacroVariable Define |
225 hi def link rustSigil StorageClass | 304 hi def link rustSigil StorageClass |
226 hi def link rustEscape Special | 305 hi def link rustEscape Special |
227 hi def link rustEscapeUnicode rustEscape | 306 hi def link rustEscapeUnicode rustEscape |
228 hi def link rustEscapeError Error | 307 hi def link rustEscapeError Error |
229 hi def link rustStringContinuation Special | 308 hi def link rustStringContinuation Special |
230 hi def link rustString String | 309 hi def link rustString String |
310 hi def link rustStringDelimiter String | |
231 hi def link rustCharacterInvalid Error | 311 hi def link rustCharacterInvalid Error |
232 hi def link rustCharacterInvalidUnicode rustCharacterInvalid | 312 hi def link rustCharacterInvalidUnicode rustCharacterInvalid |
233 hi def link rustCharacter Character | 313 hi def link rustCharacter Character |
234 hi def link rustNumber Number | 314 hi def link rustNumber Number |
235 hi def link rustBoolean Boolean | 315 hi def link rustBoolean Boolean |
239 hi def link rustSelf Constant | 319 hi def link rustSelf Constant |
240 hi def link rustFloat Float | 320 hi def link rustFloat Float |
241 hi def link rustArrowCharacter rustOperator | 321 hi def link rustArrowCharacter rustOperator |
242 hi def link rustOperator Operator | 322 hi def link rustOperator Operator |
243 hi def link rustKeyword Keyword | 323 hi def link rustKeyword Keyword |
324 hi def link rustDynKeyword rustKeyword | |
244 hi def link rustTypedef Keyword " More precise is Typedef, but it doesn't feel right for Rust | 325 hi def link rustTypedef Keyword " More precise is Typedef, but it doesn't feel right for Rust |
245 hi def link rustStructure Keyword " More precise is Structure | 326 hi def link rustStructure Keyword " More precise is Structure |
246 hi def link rustUnion rustStructure | 327 hi def link rustUnion rustStructure |
328 hi def link rustExistential rustKeyword | |
247 hi def link rustPubScopeDelim Delimiter | 329 hi def link rustPubScopeDelim Delimiter |
248 hi def link rustPubScopeCrate rustKeyword | 330 hi def link rustPubScopeCrate rustKeyword |
249 hi def link rustSuper rustKeyword | 331 hi def link rustSuper rustKeyword |
332 hi def link rustUnsafeKeyword Exception | |
250 hi def link rustReservedKeyword Error | 333 hi def link rustReservedKeyword Error |
251 hi def link rustRepeat Conditional | 334 hi def link rustRepeat Conditional |
252 hi def link rustConditional Conditional | 335 hi def link rustConditional Conditional |
253 hi def link rustIdentifier Identifier | 336 hi def link rustIdentifier Identifier |
254 hi def link rustCapsIdent rustIdentifier | 337 hi def link rustCapsIdent rustIdentifier |
258 hi def link rustFuncName Function | 341 hi def link rustFuncName Function |
259 hi def link rustFuncCall Function | 342 hi def link rustFuncCall Function |
260 hi def link rustShebang Comment | 343 hi def link rustShebang Comment |
261 hi def link rustCommentLine Comment | 344 hi def link rustCommentLine Comment |
262 hi def link rustCommentLineDoc SpecialComment | 345 hi def link rustCommentLineDoc SpecialComment |
346 hi def link rustCommentLineDocLeader rustCommentLineDoc | |
263 hi def link rustCommentLineDocError Error | 347 hi def link rustCommentLineDocError Error |
264 hi def link rustCommentBlock rustCommentLine | 348 hi def link rustCommentBlock rustCommentLine |
265 hi def link rustCommentBlockDoc rustCommentLineDoc | 349 hi def link rustCommentBlockDoc rustCommentLineDoc |
350 hi def link rustCommentBlockDocStar rustCommentBlockDoc | |
266 hi def link rustCommentBlockDocError Error | 351 hi def link rustCommentBlockDocError Error |
352 hi def link rustCommentDocCodeFence rustCommentLineDoc | |
267 hi def link rustAssert PreCondit | 353 hi def link rustAssert PreCondit |
268 hi def link rustPanic PreCondit | 354 hi def link rustPanic PreCondit |
269 hi def link rustMacro Macro | 355 hi def link rustMacro Macro |
270 hi def link rustType Type | 356 hi def link rustType Type |
271 hi def link rustTodo Todo | 357 hi def link rustTodo Todo |
274 hi def link rustDefault StorageClass | 360 hi def link rustDefault StorageClass |
275 hi def link rustStorage StorageClass | 361 hi def link rustStorage StorageClass |
276 hi def link rustObsoleteStorage Error | 362 hi def link rustObsoleteStorage Error |
277 hi def link rustLifetime Special | 363 hi def link rustLifetime Special |
278 hi def link rustLabel Label | 364 hi def link rustLabel Label |
279 hi def link rustInvalidBareKeyword Error | |
280 hi def link rustExternCrate rustKeyword | 365 hi def link rustExternCrate rustKeyword |
281 hi def link rustObsoleteExternMod Error | 366 hi def link rustObsoleteExternMod Error |
282 hi def link rustBoxPlacementParens Delimiter | |
283 hi def link rustQuestionMark Special | 367 hi def link rustQuestionMark Special |
368 hi def link rustAsync rustKeyword | |
369 hi def link rustAwait rustKeyword | |
370 hi def link rustAsmDirSpec rustKeyword | |
371 hi def link rustAsmSym rustKeyword | |
372 hi def link rustAsmOptions rustKeyword | |
373 hi def link rustAsmOptionsKey rustAttribute | |
284 | 374 |
285 " Other Suggestions: | 375 " Other Suggestions: |
286 " hi rustAttribute ctermfg=cyan | 376 " hi rustAttribute ctermfg=cyan |
287 " hi rustDerive ctermfg=cyan | 377 " hi rustDerive ctermfg=cyan |
288 " hi rustAssert ctermfg=yellow | 378 " hi rustAssert ctermfg=yellow |
291 | 381 |
292 syn sync minlines=200 | 382 syn sync minlines=200 |
293 syn sync maxlines=500 | 383 syn sync maxlines=500 |
294 | 384 |
295 let b:current_syntax = "rust" | 385 let b:current_syntax = "rust" |
386 | |
387 " vim: set et sw=4 sts=4 ts=8: |