aboutsummaryrefslogtreecommitdiff
path: root/editors/code/rust.tmGrammar.json
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/rust.tmGrammar.json')
-rw-r--r--editors/code/rust.tmGrammar.json686
1 files changed, 686 insertions, 0 deletions
diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json
new file mode 100644
index 000000000..ab87cd39f
--- /dev/null
+++ b/editors/code/rust.tmGrammar.json
@@ -0,0 +1,686 @@
1{
2 "name": "Rust",
3 "scopeName": "source.rust",
4 "patterns": [
5 {
6 "comment": "Implementation",
7 "begin": "\\b(impl)\\b",
8 "end": "\\{",
9 "beginCaptures": {
10 "1": {
11 "name": "storage.type.rust"
12 }
13 },
14 "patterns": [
15 {
16 "include": "#block_comment"
17 },
18 {
19 "include": "#line_comment"
20 },
21 {
22 "include": "#sigils"
23 },
24 {
25 "include": "#mut"
26 },
27 {
28 "include": "#dyn"
29 },
30 {
31 "include": "#ref_lifetime"
32 },
33 {
34 "include": "#core_types"
35 },
36 {
37 "include": "#core_marker"
38 },
39 {
40 "include": "#core_traits"
41 },
42 {
43 "include": "#std_types"
44 },
45 {
46 "include": "#std_traits"
47 },
48 {
49 "include": "#type_params"
50 },
51 {
52 "include": "#where"
53 },
54 {
55 "name": "storage.type.rust",
56 "match": "\\bfor\\b"
57 },
58 {
59 "include": "#type"
60 }
61 ]
62 },
63 {
64 "include": "#block_doc_comment"
65 },
66 {
67 "include": "#block_comment"
68 },
69 {
70 "include": "#line_doc_comment"
71 },
72 {
73 "include": "#line_comment"
74 },
75 {
76 "comment": "Attribute",
77 "name": "meta.attribute.rust",
78 "begin": "#\\!?\\[(\\w*)",
79 "end": "\\]",
80 "captures": {
81 "1": {
82 "name": "entity.name.function.attribute.rust"
83 }
84 },
85 "patterns": [
86 {
87 "include": "#string_literal"
88 },
89 {
90 "include": "#block_doc_comment"
91 },
92 {
93 "include": "#block_comment"
94 },
95 {
96 "include": "#line_doc_comment"
97 },
98 {
99 "include": "#line_comment"
100 }
101 ]
102 },
103 {
104 "comment": "Single-quote string literal (character)",
105 "name": "string.quoted.single.rust",
106 "match": "b?'([^'\\\\]|\\\\(x[0-9A-Fa-f]{2}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.))'"
107 },
108 {
109 "include": "#string_literal"
110 },
111 {
112 "include": "#raw_string_literal"
113 },
114 {
115 "comment": "Floating point literal (fraction)",
116 "name": "constant.numeric.float.rust",
117 "match": "\\b[0-9][0-9_]*\\.[0-9][0-9_]*([eE][+-]?[0-9_]+)?(f32|f64)?\\b"
118 },
119 {
120 "comment": "Floating point literal (exponent)",
121 "name": "constant.numeric.float.rust",
122 "match": "\\b[0-9][0-9_]*(\\.[0-9][0-9_]*)?[eE][+-]?[0-9_]+(f32|f64)?\\b"
123 },
124 {
125 "comment": "Floating point literal (typed)",
126 "name": "constant.numeric.float.rust",
127 "match": "\\b[0-9][0-9_]*(\\.[0-9][0-9_]*)?([eE][+-]?[0-9_]+)?(f32|f64)\\b"
128 },
129 {
130 "comment": "Integer literal (decimal)",
131 "name": "constant.numeric.integer.decimal.rust",
132 "match": "\\b[0-9][0-9_]*([ui](8|16|32|64|128|s|size))?\\b"
133 },
134 {
135 "comment": "Integer literal (hexadecimal)",
136 "name": "constant.numeric.integer.hexadecimal.rust",
137 "match": "\\b0x[a-fA-F0-9_]+([ui](8|16|32|64|128|s|size))?\\b"
138 },
139 {
140 "comment": "Integer literal (octal)",
141 "name": "constant.numeric.integer.octal.rust",
142 "match": "\\b0o[0-7_]+([ui](8|16|32|64|128|s|size))?\\b"
143 },
144 {
145 "comment": "Integer literal (binary)",
146 "name": "constant.numeric.integer.binary.rust",
147 "match": "\\b0b[01_]+([ui](8|16|32|64|128|s|size))?\\b"
148 },
149 {
150 "comment": "Static storage modifier",
151 "name": "storage.modifier.static.rust",
152 "match": "\\bstatic\\b"
153 },
154 {
155 "comment": "Boolean constant",
156 "name": "constant.language.boolean.rust",
157 "match": "\\b(true|false)\\b"
158 },
159 {
160 "comment": "Control keyword",
161 "name": "keyword.control.rust",
162 "match": "\\b(async|await|break|continue|else|if|in|for|loop|match|return|try|while)\\b"
163 },
164 {
165 "comment": "Keyword",
166 "name": "keyword.other.rust",
167 "match": "\\b(crate|extern|mod|let|ref|use|super|move|as)\\b"
168 },
169 {
170 "comment": "Reserved keyword",
171 "name": "invalid.deprecated.rust",
172 "match": "\\b(abstract|alignof|become|do|final|macro|offsetof|override|priv|proc|pure|sizeof|typeof|virtual|yield)\\b"
173 },
174 {
175 "include": "#unsafe"
176 },
177 {
178 "include": "#sigils"
179 },
180 {
181 "include": "#self"
182 },
183 {
184 "include": "#mut"
185 },
186 {
187 "include": "#dyn"
188 },
189 {
190 "include": "#impl"
191 },
192 {
193 "include": "#box"
194 },
195 {
196 "include": "#lifetime"
197 },
198 {
199 "include": "#ref_lifetime"
200 },
201 {
202 "include": "#const"
203 },
204 {
205 "include": "#pub"
206 },
207 {
208 "comment": "Miscellaneous operator",
209 "name": "keyword.operator.misc.rust",
210 "match": "(=>|::|\\?)"
211 },
212 {
213 "comment": "Comparison operator",
214 "name": "keyword.operator.comparison.rust",
215 "match": "(&&|\\|\\||==|!=)"
216 },
217 {
218 "comment": "Assignment operator",
219 "name": "keyword.operator.assignment.rust",
220 "match": "(\\+=|-=|/=|\\*=|%=|\\^=|&=|\\|=|<<=|>>=|=)"
221 },
222 {
223 "comment": "Arithmetic operator",
224 "name": "keyword.operator.arithmetic.rust",
225 "match": "(!|\\+|-|/|\\*|%|\\^|&|\\||<<|>>)"
226 },
227 {
228 "comment": "Comparison operator (second group because of regex precedence)",
229 "name": "keyword.operator.comparison.rust",
230 "match": "(<=|>=|<|>)"
231 },
232 {
233 "include": "#core_types"
234 },
235 {
236 "include": "#core_vars"
237 },
238 {
239 "include": "#core_marker"
240 },
241 {
242 "include": "#core_traits"
243 },
244 {
245 "include": "#std_types"
246 },
247 {
248 "include": "#std_traits"
249 },
250 {
251 "comment": "Built-in macro",
252 "name": "support.function.builtin.rust",
253 "match": "\\b(macro_rules|compile_error|format_args|env|option_env|concat_idents|concat|line|column|file|stringify|include|include_str|include_bytes|module_path|cfg)!"
254 },
255 {
256 "comment": "Core macro",
257 "name": "support.function.core.rust",
258 "match": "\\b(panic|assert|assert_eq|assert_ne|debug_assert|debug_assert_eq|debug_assert_ne|try|write|writeln|unreachable|unimplemented)!"
259 },
260 {
261 "comment": "Standard library macro",
262 "name": "support.function.std.rust",
263 "match": "\\b(format|print|println|eprint|eprintln|select|vec)!"
264 },
265 {
266 "comment": "Logging macro",
267 "name": "support.function.log.rust",
268 "match": "\\b(log|error|warn|info|debug|trace|log_enabled)!"
269 },
270 {
271 "comment": "Invokation of a macro",
272 "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*\\!)\\s*[({\\[]",
273 "captures": {
274 "1": {
275 "name": "entity.name.function.macro.rust"
276 }
277 }
278 },
279 {
280 "comment": "Function call",
281 "match": "\\b([A-Za-z][A-Za-z0-9_]*|_[A-Za-z0-9_]+)\\s*\\(",
282 "captures": {
283 "1": {
284 "name": "entity.name.function.rust"
285 }
286 }
287 },
288 {
289 "comment": "Function call with type parameters",
290 "begin": "\\b([A-Za-z][A-Za-z0-9_]*|_[A-Za-z0-9_]+)\\s*(::)(?=\\s*<.*>\\s*\\()",
291 "end": "\\(",
292 "captures": {
293 "1": {
294 "name": "entity.name.function.rust"
295 },
296 "2": {
297 "name": "keyword.operator.misc.rust"
298 }
299 },
300 "patterns": [
301 {
302 "include": "#type_params"
303 }
304 ]
305 },
306 {
307 "comment": "Function definition",
308 "begin": "\\b(fn)\\s+([A-Za-z][A-Za-z0-9_]*|_[A-Za-z0-9_]+)",
309 "end": "[\\{;]",
310 "beginCaptures": {
311 "1": {
312 "name": "keyword.other.fn.rust"
313 },
314 "2": {
315 "name": "entity.name.function.rust"
316 }
317 },
318 "patterns": [
319 {
320 "include": "#block_comment"
321 },
322 {
323 "include": "#line_comment"
324 },
325 {
326 "include": "#sigils"
327 },
328 {
329 "include": "#self"
330 },
331 {
332 "include": "#mut"
333 },
334 {
335 "include": "#dyn"
336 },
337 {
338 "include": "#impl"
339 },
340 {
341 "include": "#ref_lifetime"
342 },
343 {
344 "include": "#core_types"
345 },
346 {
347 "include": "#core_marker"
348 },
349 {
350 "include": "#core_traits"
351 },
352 {
353 "include": "#std_types"
354 },
355 {
356 "include": "#std_traits"
357 },
358 {
359 "include": "#type_params"
360 },
361 {
362 "include": "#const"
363 },
364 {
365 "include": "#where"
366 },
367 {
368 "include": "#unsafe"
369 },
370 {
371 "comment": "Function arguments",
372 "match": "\bfn\b",
373 "name": "keyword.other.fn.rust"
374 }
375 ]
376 },
377 {
378 "comment": "Type declaration",
379 "begin": "\\b(enum|struct|trait|union)\\s+([a-zA-Z_][a-zA-Z0-9_]*)",
380 "end": "[\\{\\(;]",
381 "beginCaptures": {
382 "1": {
383 "name": "storage.type.rust"
384 },
385 "2": {
386 "name": "entity.name.type.rust"
387 }
388 },
389 "patterns": [
390 {
391 "include": "#block_comment"
392 },
393 {
394 "include": "#line_comment"
395 },
396 {
397 "include": "#core_traits"
398 },
399 {
400 "include": "#std_traits"
401 },
402 {
403 "include": "#type_params"
404 },
405 {
406 "include": "#core_types"
407 },
408 {
409 "include": "#pub"
410 },
411 {
412 "include": "#where"
413 }
414 ]
415 },
416 {
417 "comment": "Type alias",
418 "begin": "\\b(type)\\s+([a-zA-Z_][a-zA-Z0-9_]*)",
419 "end": ";",
420 "beginCaptures": {
421 "1": {
422 "name": "storage.type.rust"
423 },
424 "2": {
425 "name": "entity.name.type.rust"
426 }
427 },
428 "patterns": [
429 {
430 "include": "#block_comment"
431 },
432 {
433 "include": "#line_comment"
434 },
435 {
436 "include": "#sigils"
437 },
438 {
439 "include": "#mut"
440 },
441 {
442 "include": "#dyn"
443 },
444 {
445 "include": "#impl"
446 },
447 {
448 "include": "#lifetime"
449 },
450 {
451 "include": "#ref_lifetime"
452 },
453 {
454 "include": "#core_types"
455 },
456 {
457 "include": "#core_marker"
458 },
459 {
460 "include": "#core_traits"
461 },
462 {
463 "include": "#std_types"
464 },
465 {
466 "include": "#std_traits"
467 },
468 {
469 "include": "#type_params"
470 }
471 ]
472 }
473 ],
474 "repository": {
475 "block_doc_comment": {
476 "comment": "Block documentation comment",
477 "name": "comment.block.documentation.rust",
478 "begin": "/\\*[\\*!](?![\\*/])",
479 "end": "\\*/",
480 "patterns": [
481 {
482 "include": "#block_doc_comment"
483 },
484 {
485 "include": "#block_comment"
486 }
487 ]
488 },
489 "block_comment": {
490 "comment": "Block comment",
491 "name": "comment.block.rust",
492 "begin": "/\\*",
493 "end": "\\*/",
494 "patterns": [
495 {
496 "include": "#block_doc_comment"
497 },
498 {
499 "include": "#block_comment"
500 }
501 ]
502 },
503 "line_doc_comment": {
504 "comment": "Single-line documentation comment",
505 "name": "comment.line.documentation.rust",
506 "begin": "//[!/](?=[^/])",
507 "end": "$"
508 },
509 "line_comment": {
510 "comment": "Single-line comment",
511 "name": "comment.line.double-slash.rust",
512 "begin": "//",
513 "end": "$"
514 },
515 "escaped_character": {
516 "name": "constant.character.escape.rust",
517 "match": "\\\\(x[0-9A-Fa-f]{2}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)"
518 },
519 "string_literal": {
520 "comment": "Double-quote string literal",
521 "name": "string.quoted.double.rust",
522 "begin": "b?\"",
523 "end": "\"",
524 "patterns": [
525 {
526 "include": "#escaped_character"
527 }
528 ]
529 },
530 "raw_string_literal": {
531 "comment": "Raw double-quote string literal",
532 "name": "string.quoted.double.raw.rust",
533 "begin": "b?r(#*)\"",
534 "end": "\"\\1"
535 },
536 "sigils": {
537 "comment": "Sigil",
538 "name": "keyword.operator.sigil.rust",
539 "match": "[&*](?=[a-zA-Z0-9_\\(\\[\\|\\\"]+)"
540 },
541 "self": {
542 "comment": "Self variable",
543 "name": "variable.language.rust",
544 "match": "\\bself\\b"
545 },
546 "mut": {
547 "comment": "Mutable storage modifier",
548 "name": "storage.modifier.mut.rust",
549 "match": "\\bmut\\b"
550 },
551 "dyn": {
552 "comment": "Dynamic modifier",
553 "name": "storage.modifier.dyn.rust",
554 "match": "\\bdyn\\b"
555 },
556 "impl": {
557 "comment": "Existential type modifier",
558 "name": "storage.modifier.impl.rust",
559 "match": "\\bimpl\\b"
560 },
561 "box": {
562 "comment": "Box storage modifier",
563 "name": "storage.modifier.box.rust",
564 "match": "\\bbox\\b"
565 },
566 "const": {
567 "comment": "Const storage modifier",
568 "name": "storage.modifier.const.rust",
569 "match": "\\bconst\\b"
570 },
571 "pub": {
572 "comment": "Visibility modifier",
573 "name": "storage.modifier.visibility.rust",
574 "match": "\\bpub\\b"
575 },
576 "unsafe": {
577 "comment": "Unsafe code keyword",
578 "name": "keyword.other.unsafe.rust",
579 "match": "\\bunsafe\\b"
580 },
581 "where": {
582 "comment": "Generic where clause",
583 "name": "keyword.other.where.rust",
584 "match": "\\bwhere\\b"
585 },
586 "lifetime": {
587 "comment": "Named lifetime",
588 "name": "storage.modifier.lifetime.rust",
589 "match": "'([a-zA-Z_][a-zA-Z0-9_]*)\\b"
590 },
591 "ref_lifetime": {
592 "comment": "Reference with named lifetime",
593 "match": "(&)('[a-zA-Z_][a-zA-Z0-9_]*)\\b",
594 "captures": {
595 "1": {
596 "name": "keyword.operator.sigil.rust"
597 },
598 "2": {
599 "name": "storage.modifier.lifetime.rust"
600 }
601 }
602 },
603 "core_types": {
604 "comment": "Built-in/core type",
605 "name": "support.type.primitive.rust",
606 "match": "\\b(bool|char|usize|isize|u8|u16|u32|u64|u128|i8|i16|i32|i64|i128|f32|f64|str|Self)\\b"
607 },
608 "core_vars": {
609 "comment": "Core type variant",
610 "name": "support.constant.core.rust",
611 "match": "\\b(Some|None|Ok|Err)\\b"
612 },
613 "core_marker": {
614 "comment": "Core trait (marker)",
615 "name": "entity.name.type.marker.rust",
616 "match": "\\b(Copy|Send|Sized|Sync)\\b"
617 },
618 "core_traits": {
619 "comment": "Core trait",
620 "name": "entity.name.type.core.rust",
621 "match": "\\b(Drop|Fn|FnMut|FnOnce|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator)\\b"
622 },
623 "std_types": {
624 "comment": "Standard library type",
625 "name": "entity.name.type.class.std.rust",
626 "match": "\\b(Box|String|Vec|Path|PathBuf|Option|Result)\\b"
627 },
628 "std_traits": {
629 "comment": "Standard library trait",
630 "name": "entity.name.type.std.rust",
631 "match": "\\b(ToOwned|ToString)\\b"
632 },
633 "type": {
634 "comment": "A type",
635 "name": "entity.name.type.rust",
636 "match": "\\b([A-Za-z][_A-Za-z0-9]*|_[_A-Za-z0-9]+)\\b"
637 },
638 "type_params": {
639 "comment": "Type parameters",
640 "name": "meta.type_params.rust",
641 "begin": "<(?![=<])",
642 "end": "(?<![-])>",
643 "patterns": [
644 {
645 "include": "#block_comment"
646 },
647 {
648 "include": "#line_comment"
649 },
650 {
651 "include": "#sigils"
652 },
653 {
654 "include": "#mut"
655 },
656 {
657 "include": "#dyn"
658 },
659 {
660 "include": "#impl"
661 },
662 {
663 "include": "#lifetime"
664 },
665 {
666 "include": "#core_types"
667 },
668 {
669 "include": "#core_marker"
670 },
671 {
672 "include": "#core_traits"
673 },
674 {
675 "include": "#std_types"
676 },
677 {
678 "include": "#std_traits"
679 },
680 {
681 "include": "#type_params"
682 }
683 ]
684 }
685 }
686} \ No newline at end of file