Skip to content

Commit bbb5800

Browse files
authored
fix: Rust identifiers normally recognised now; generics highlight support; doc comments support (#4868)
1 parent 897ee0a commit bbb5800

File tree

3 files changed

+312
-138
lines changed

3 files changed

+312
-138
lines changed

demo/kitchen-sink/docs/rust.rs

+38
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,41 @@ fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
1818
}
1919
return accumulator;
2020
}
21+
22+
struct ConstGenericStruct<const N: usize>([(); N]);
23+
// T constrains by being an argument to GenericTrait.
24+
impl<T> GenericTrait<T> for i32 { /* ... */ }
25+
26+
// T constrains by being an arguement to GenericStruct
27+
impl<T> Trait for GenericStruct<T> { /* ... */ }
28+
29+
// Likewise, N constrains by being an argument to ConstGenericStruct
30+
impl<const N: usize> Trait for ConstGenericStruct<N> { /* ... */ }
31+
32+
// T constrains by being in an associated type in a bound for type `U` which is
33+
// itself a generic parameter constraining the trait.
34+
impl<T, U> GenericTrait<U> for u32 where U: HasAssocType<Ty = T> { /* ... */ }
35+
36+
// Like previous, except the type is `(U, isize)`. `U` appears inside the type
37+
// that includes `T`, and is not the type itself.
38+
impl<T, U> GenericStruct<U> where (U, isize): HasAssocType<Ty = T> { /* ... */ }
39+
40+
//! - Inner line doc
41+
//!! - Still an inner line doc (but with a bang at the beginning)
42+
43+
/*! - Inner block doc */
44+
/*!! - Still an inner block doc (but with a bang at the beginning) */
45+
46+
/** - Outer block doc (exactly) 2 asterisks */
47+
48+
macro_rules! mac_variant {
49+
($vis:vis $name:ident) => {
50+
enum $name {
51+
$vis Unit,
52+
53+
$vis Tuple(u8, u16),
54+
55+
$vis Struct { f: u8 },
56+
}
57+
}
58+
}

src/mode/_test/tokens_rust.json

+90-48
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
["keyword.source.rust","use"],
44
["text"," "],
55
["support.constant","core::rand::"],
6-
["text","RngUtil"],
6+
["identifier","RngUtil"],
77
["punctuation.operator",";"]
88
],[
99
"start"
@@ -31,31 +31,36 @@
3131
["string.quoted.double.source.rust","\"Carol\""],
3232
["paren.rparen","]"],
3333
["punctuation.operator","."],
34-
["text","each "],
34+
["identifier","each"],
35+
["text"," "],
3536
["keyword.operator","|&"],
36-
["text","name"],
37+
["identifier","name"],
3738
["keyword.operator","|"],
3839
["text"," "],
3940
["paren.lparen","{"]
4041
],[
4142
"start",
4243
["text"," "],
4344
["keyword.source.rust","do"],
44-
["text"," spawn "],
45+
["text"," "],
46+
["identifier","spawn"],
47+
["text"," "],
4548
["paren.lparen","{"]
4649
],[
4750
"start",
4851
["text"," "],
4952
["keyword.source.rust","let"],
50-
["text"," v "],
53+
["text"," "],
54+
["identifier","v"],
55+
["text"," "],
5156
["keyword.operator","="],
5257
["text"," "],
5358
["support.constant","rand::"],
54-
["text","Rng"],
59+
["identifier","Rng"],
5560
["paren.lparen","("],
5661
["paren.rparen",")"],
5762
["punctuation.operator","."],
58-
["text","shuffle"],
63+
["identifier","shuffle"],
5964
["paren.lparen","(["],
6065
["constant.numeric.source.rust","1"],
6166
["punctuation.operator",","],
@@ -70,28 +75,34 @@
7075
"start",
7176
["text"," "],
7277
["keyword.source.rust","for"],
73-
["text"," v"],
78+
["text"," "],
79+
["identifier","v"],
7480
["punctuation.operator","."],
75-
["text","each "],
81+
["identifier","each"],
82+
["text"," "],
7683
["keyword.operator","|&"],
77-
["text","num"],
84+
["identifier","num"],
7885
["keyword.operator","|"],
7986
["text"," "],
8087
["paren.lparen","{"]
8188
],[
8289
"start",
83-
["text"," print"],
90+
["text"," "],
91+
["identifier","print"],
8492
["paren.lparen","("],
85-
["text","fmt"],
93+
["identifier","fmt"],
8694
["keyword.operator","!"],
8795
["paren.lparen","("],
8896
["string.quoted.double.source.rust","\"%s says: '%d'"],
89-
["constant.character.escape.source.rust","\\n\\\\"],
97+
["constant.character.escape.source.rust","\\n"],
9098
["string.quoted.double.source.rust","\""],
9199
["punctuation.operator",","],
92-
["text"," name"],
100+
["text"," "],
101+
["identifier","name"],
93102
["punctuation.operator",","],
94-
["text"," num "],
103+
["text"," "],
104+
["identifier","num"],
105+
["text"," "],
95106
["keyword.operator","+"],
96107
["text"," "],
97108
["constant.numeric.source.rust","1"],
@@ -112,20 +123,31 @@
112123
"start"
113124
],[
114125
"start",
126+
["text"," "],
115127
["keyword.source.rust","let"],
116-
["text"," _ "],
128+
["text"," "],
129+
["identifier","_"],
117130
["punctuation.operator",":"],
131+
["text"," "],
118132
["storage.type.source.rust","i128"],
119-
["keyword.operator","=-"],
133+
["text"," "],
134+
["keyword.operator","="],
135+
["text"," "],
136+
["keyword.operator","-"],
120137
["constant.numeric.source.rust","42i128"],
121138
["punctuation.operator",";"]
122139
],[
123140
"start",
141+
["text"," "],
124142
["keyword.source.rust","let"],
125-
["text"," _ "],
143+
["text"," "],
144+
["identifier","_"],
126145
["punctuation.operator",":"],
146+
["text"," "],
127147
["storage.type.source.rust","u128"],
148+
["text"," "],
128149
["keyword.operator","="],
150+
["text"," "],
129151
["constant.numeric.source.rust","42u128"],
130152
["punctuation.operator",";"]
131153
],[
@@ -152,41 +174,44 @@
152174
["keyword.source.rust","fn"],
153175
["text"," "],
154176
["entity.name.function.source.rust","map"],
155-
["keyword.operator","<"],
156-
["text","T"],
177+
["punctuation","<"],
178+
["identifier","T"],
157179
["punctuation.operator",","],
158-
["text"," U"],
159-
["keyword.operator",">"],
180+
["text"," "],
181+
["identifier","U"],
182+
["punctuation",">"],
160183
["paren.lparen","("],
161-
["text","vector"],
184+
["identifier","vector"],
162185
["punctuation.operator",":"],
163186
["text"," "],
164187
["keyword.operator","&"],
165188
["paren.lparen","["],
166-
["text","T"],
189+
["identifier","T"],
167190
["paren.rparen","]"],
168191
["punctuation.operator",","],
169-
["text"," function"],
192+
["text"," "],
193+
["identifier","function"],
170194
["punctuation.operator",":"],
171195
["text"," "],
172196
["keyword.operator","&"],
173-
["text","fn"],
197+
["identifier","fn"],
174198
["paren.lparen","("],
175-
["text","v"],
199+
["identifier","v"],
176200
["punctuation.operator",":"],
177201
["text"," "],
178202
["keyword.operator","&"],
179-
["text","T"],
203+
["identifier","T"],
180204
["paren.rparen",")"],
181205
["text"," "],
182206
["keyword.operator","->"],
183-
["text"," U"],
207+
["text"," "],
208+
["identifier","U"],
184209
["paren.rparen",")"],
185210
["text"," "],
186211
["keyword.operator","->"],
187212
["text"," ~"],
188213
["paren.lparen","["],
189-
["text","U"],
214+
["identifier","U"],
190215
["paren.rparen","]"],
191216
["text"," "],
192217
["paren.lparen","{"]
@@ -196,7 +221,9 @@
196221
["keyword.source.rust","let"],
197222
["text"," "],
198223
["keyword.source.rust","mut"],
199-
["text"," accumulator "],
224+
["text"," "],
225+
["identifier","accumulator"],
226+
["text"," "],
200227
["keyword.operator","="],
201228
["text"," ~"],
202229
["paren.lparen","["],
@@ -208,25 +235,26 @@
208235
["keyword.source.rust","for"],
209236
["text"," "],
210237
["support.constant","vec::"],
211-
["text","each"],
238+
["identifier","each"],
212239
["paren.lparen","("],
213-
["text","vector"],
240+
["identifier","vector"],
214241
["paren.rparen",")"],
215242
["text"," "],
216243
["keyword.operator","|"],
217-
["text","element"],
244+
["identifier","element"],
218245
["keyword.operator","|"],
219246
["text"," "],
220247
["paren.lparen","{"]
221248
],[
222249
"start",
223-
["text"," accumulator"],
250+
["text"," "],
251+
["identifier","accumulator"],
224252
["punctuation.operator","."],
225-
["text","push"],
253+
["identifier","push"],
226254
["paren.lparen","("],
227-
["text","function"],
255+
["identifier","function"],
228256
["paren.lparen","("],
229-
["text","element"],
257+
["identifier","element"],
230258
["paren.rparen","))"],
231259
["punctuation.operator",";"]
232260
],[
@@ -237,7 +265,8 @@
237265
"start",
238266
["text"," "],
239267
["keyword.source.rust","return"],
240-
["text"," accumulator"],
268+
["text"," "],
269+
["identifier","accumulator"],
241270
["punctuation.operator",";"]
242271
],[
243272
"start",
@@ -276,24 +305,37 @@
276305
"start",
277306
["constant.numeric.source.rust","14"],
278307
["punctuation.operator","."],
279-
["text","_E"],
308+
["identifier","_E"],
280309
["keyword.operator","-"],
281310
["constant.numeric.source.rust","111_f64"],
282311
["punctuation.operator",";"],
283-
["text","0xi32"],
312+
["text"," 0"],
313+
["identifier","xi32"],
284314
["punctuation.operator",";"],
285-
["text","0b777u"]
315+
["text"," 0"],
316+
["identifier","b777u"]
317+
],[
318+
"start"
319+
],[
320+
"start",
321+
["comment.line.double-dash.source.rust","// identifiers ending in constant.numeric"]
286322
],[
287323
"start",
288-
["text","foo1"],
324+
["identifier","foo1"],
289325
["punctuation.operator",";"],
290-
["text","foo1u32"],
326+
["text"," "],
327+
["identifier","foo1u32"],
291328
["punctuation.operator",";"],
292-
["text","foo1f32"],
329+
["text"," "],
330+
["identifier","foo1f32"],
293331
["punctuation.operator",";"],
294-
["text","foo0xF"],
332+
["text"," "],
333+
["identifier","foo0xF"],
295334
["punctuation.operator",";"],
296-
["text","foo1"],
335+
["text"," "],
336+
["identifier","foo1"],
297337
["punctuation.operator","."],
298338
["constant.numeric.source.rust","0"]
299-
]]
339+
],[
340+
"start"
341+
]]

0 commit comments

Comments
 (0)