-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRustSyntaxHighLight.mtsx
306 lines (296 loc) · 9.46 KB
/
RustSyntaxHighLight.mtsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
{
// @author: A4-Tacks
// @email: wdsjxhno1001@163.com
// @last-edit-date: ...
// @repo: https://github.com/A4-Tacks/Rust-SyntaxHighLight-For-MT-Manager
name: ["Rust", ".rs"],
hide: false,
colors: [
"preproc" > "label",
"funcname" > "tagName",
"typename" > "type",
"path-delim" > "operator",
],
// default format comment
comment: {
startsWith: "//",
insertSpace: true,
addToContains: false, // 不高亮
},
// long comment
comment: {
startsWith: "/*",
endsWith: "*/",
insertSpace: false,
addToContains: false, // 不高亮
},
defines: [
"ident-continue": /[^\x00-\x20!"#$%&'()*+,\-.\/:;<=>?@\[\]^`{|}~]/
"norm-ident": /(?:\b_/+include("ident-continue")+/+\b|\b(?![\d_])/+include("ident-continue")+/+\b)/
"ident": /(?:r#)?/ + include("norm-ident")
"rust-derive-trait": {match: keywordsToRegex(
"Clone Hash RustcEncodable RustcDecodable Encodable Decodable"
"PartialEq Eq PartialOrd Ord Rand Show Debug Default"
"FromPrimitive Send Sync Copy"
), 0: "variable"}
"attribute-proc-macro-item": [
{include: "comments"}
{include: "strings"}
{
start: {match: /derive\(/}
end: {match: /\)/}
contains: [
{include: "attribute-proc-macro-item"}
{include: "rust-derive-trait"}
]
}
{
start: {match: /\(/}
end: {match: /\)|(?=[\]}])/}
contains: [{include: "attribute-proc-macro-item"}]
}
{
start: {match: /\[/}
end: {match: /\]|(?=[)}])/}
contains: [{include: "attribute-proc-macro-item"}]
}
{
start: {match: /\{/}
end: {match: /\}|(?=[)\]])/}
contains: [{include: "attribute-proc-macro-item"}]
}
{include: "decl-macro-meta"}
]
"comments": [
{ // doc comment
match: /\/\/[!\/].*(?:\n|$)/,
0: "namespace",
},
{ // comment
match: /\/\/.*(?:\n|$)/,
0: "comment",
},
{ // zero length long comment
match: /\/\*\*\//,
0: "comment",
},
{ // long doc comment
start: {match: /\/\*[*!]/},
end: {match: /\*\//},
color: "namespace",
},
{ // long comment
start: {match: /\/\*/},
end: {match: /\*\//},
color: "comment",
},
]
"strings": [
{ // double quoted string
start: {match: /[bc]?"/},
end: {match: /"/},
color: "string",
contains: [
{
match: /(?:(\\(?:u\{(?:[_a-fA-F\d]_*){1,6}\}/
+ /|x[a-fA-F\d]{2}|[nrt\\0"']))|(\\.))/,
1: "strEscape",
2: "error",
},
],
},
{ // raw string
start: {match: /b?r"/},
end: {match: /"/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r#"/},
end: {match: /"#/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r##"/},
end: {match: /"##/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r###"/},
end: {match: /"###/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r####"/},
end: {match: /"####/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r#####"/},
end: {match: /"#####/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r######"/},
end: {match: /"######/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r#######"/},
end: {match: /"#######/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r########"/},
end: {match: /"########/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r#########"/},
end: {match: /"#########/},
color: "string",
},
{ // raw string tag......
start: {match: /b?r##########"/},
end: {match: /"##########/},
color: "string",
},
{ // char
match: /b?'(?:(\\(?:u\{(?:[_a-fA-F\d]_*){1,6}\}|x[a-fA-F\d]{2}|[nrt\\0"']))|(\\.)|[^\\])'/,
0: "string",
1: "strEscape",
2: "error",
},
]
"decl-macro-meta": [
{ // macro meta var
match: /\$/ + include("ident"),
0: "preproc",
},
{ // macro meta braces
match: /\$(?=[({])/,
0: "preproc",
},
]
]
contains: [
{ // rust shebang
match: /^#![^\[\r\n][^\r\n]*/,
0: "comment"
}
{include: "comments"}
{include: "strings"}
{ // number
match: /\b(?:0(?:x[_a-fA-F\d]+|o[_0-7]+|b[_01]+)/
+ /(?:[iu](?:8|16|32|64|128|size))?/
+ /|\d[_\d]*(?:\.\d[_\d]*)?/
+ /(?:f(?:32|64)|[iu](?:8|16|32|64|128|size))?/
+ /)\b/,
0: "number",
},
{ // raw ident
match: /r#/ + include("norm-ident") + /(?!::|[!\(])/
}
{ // function define
match: /(fn)\s+(/+include("ident")+/)/,
1: "keyword",
2: "funcname",
},
{ // weak keywords
match: /(union)\s+(/+include("ident")+/)/,
1: "keyword",
2: "typename",
},
{ // reserved keywords
match: keywordsToRegex(
"abstract become box do final override"
"priv typeof unsized virtual"
),
0: "error",
},
{ // strict keywords
match: keywordsToRegex(
"as break const continue crate dyn"
"else enum extern false fn for"
"if impl in let loop match"
"mod move mut pub ref return"
"static struct super trait"
"true type unsafe use where while"
"async await macro try yield"),
0: "keyword",
},
{ // type
match: keywordsToRegex(
"bool char"
"fn"
"str"
"f32 f64"
"i8 i16 i32 i64 i128 isize"
"u8 u16 u32 u64 u128 usize"),
0: "type",
},
{ // 被预导入的结构体与特征等 (取材自 Rust 2021 edition)
match: keywordsToRegex(
"Send Sized Sync Unpin Drop Fn FnMut FnOnce AsMut AsRef"
"From Into DoubleEndedIterator ExactSizeIterator Extend"
"IntoIterator Iterator Clone Copy Default Eq Ord PartialEq"
"PartialOrd ToOwned ToString TryFrom TryInto FromIterator"
"Box String Vec Option None Some Result Err Ok"
),
0: "variable",
},
{ // Self type
match: /\bSelf\b/,
0: "variable",
},
{ // self value
match: /\bself\b/,
0: "constant",
},
{ // path-delim
match: /::/,
0: "path-delim",
},
{ // module like path (type)
match: include("ident") + /(?=::[^<])/,
0: "namespace",
},
{ // call function and Turbofish
match: include("ident") + /(?=::<|\()/,
0: "funcname",
},
{ // call macro
match: include("ident") + /!/,
0: "preproc",
},
{include: "decl-macro-meta"}
{ // attribute proc-macro ident
match: /#/ + include("ident"),
0: "preproc",
},
{ // attribute proc-macro
start: {match: /#!?\[/},
end: {match: /\]/},
color: "preproc",
contains: [
{include: "attribute-proc-macro-item"},
]
},
{ // loop label
match: /'/+include("norm-ident")+/:/,
0: "label"
},
{ // lifetime
match: /'(?:/+include("norm-ident")+/|_\b)(?!')/,
0: "meta"
},
{ // 一些突出符号
match: /([?]|&&|\|\|(?![ \t]*(?:\{|->))(?<!(?:[=(|,;]|\bmove|=>) ?\|\|)|\.(?=await))|([<>@|](?!=)|[=\-]>)/,
1: "keyword",
2: "operator",
},
{ // 一些前导符号
match: /([&~@*])(?![)= \s])/,
1: "operator",
},
],
}