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
| /*
| Language: Rust
| Author: Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
| Contributors: Roman Shmatov <romanshmatov@gmail.com>, Kasper Andersen <kma_untrusted@protonmail.com>
| Website: https://www.rust-lang.org
| Category: common, system
| */
|
| function rust(hljs) {
| const NUM_SUFFIX = '([ui](8|16|32|64|128|size)|f(32|64))\?';
| const KEYWORDS =
| 'abstract as async await become box break const continue crate do dyn ' +
| 'else enum extern false final fn for if impl in let loop macro match mod ' +
| 'move mut override priv pub ref return self Self static struct super ' +
| 'trait true try type typeof unsafe unsized use virtual where while yield';
| const BUILTINS =
| // functions
| 'drop ' +
| // types
| 'i8 i16 i32 i64 i128 isize ' +
| 'u8 u16 u32 u64 u128 usize ' +
| 'f32 f64 ' +
| 'str char bool ' +
| 'Box Option Result String Vec ' +
| // traits
| 'Copy Send Sized Sync Drop Fn FnMut FnOnce ToOwned Clone Debug ' +
| 'PartialEq PartialOrd Eq Ord AsRef AsMut Into From Default Iterator ' +
| 'Extend IntoIterator DoubleEndedIterator ExactSizeIterator ' +
| 'SliceConcatExt ToString ' +
| // macros
| 'assert! assert_eq! bitflags! bytes! cfg! col! concat! concat_idents! ' +
| 'debug_assert! debug_assert_eq! env! panic! file! format! format_args! ' +
| 'include_bin! include_str! line! local_data_key! module_path! ' +
| 'option_env! print! println! select! stringify! try! unimplemented! ' +
| 'unreachable! vec! write! writeln! macro_rules! assert_ne! debug_assert_ne!';
| return {
| name: 'Rust',
| aliases: [ 'rs' ],
| keywords: {
| $pattern: hljs.IDENT_RE + '!?',
| keyword:
| KEYWORDS,
| literal:
| 'true false Some None Ok Err',
| built_in:
| BUILTINS
| },
| illegal: '</',
| contains: [
| hljs.C_LINE_COMMENT_MODE,
| hljs.COMMENT('/\\*', '\\*/', {
| contains: [ 'self' ]
| }),
| hljs.inherit(hljs.QUOTE_STRING_MODE, {
| begin: /b?"/,
| illegal: null
| }),
| {
| className: 'string',
| variants: [
| {
| begin: /r(#*)"(.|\n)*?"\1(?!#)/
| },
| {
| begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/
| }
| ]
| },
| {
| className: 'symbol',
| begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
| },
| {
| className: 'number',
| variants: [
| {
| begin: '\\b0b([01_]+)' + NUM_SUFFIX
| },
| {
| begin: '\\b0o([0-7_]+)' + NUM_SUFFIX
| },
| {
| begin: '\\b0x([A-Fa-f0-9_]+)' + NUM_SUFFIX
| },
| {
| begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)' +
| NUM_SUFFIX
| }
| ],
| relevance: 0
| },
| {
| className: 'function',
| beginKeywords: 'fn',
| end: '(\\(|<)',
| excludeEnd: true,
| contains: [ hljs.UNDERSCORE_TITLE_MODE ]
| },
| {
| className: 'meta',
| begin: '#!?\\[',
| end: '\\]',
| contains: [
| {
| className: 'meta-string',
| begin: /"/,
| end: /"/
| }
| ]
| },
| {
| className: 'class',
| beginKeywords: 'type',
| end: ';',
| contains: [
| hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {
| endsParent: true
| })
| ],
| illegal: '\\S'
| },
| {
| className: 'class',
| beginKeywords: 'trait enum struct union',
| end: /\{/,
| contains: [
| hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {
| endsParent: true
| })
| ],
| illegal: '[\\w\\d]'
| },
| {
| begin: hljs.IDENT_RE + '::',
| keywords: {
| built_in: BUILTINS
| }
| },
| {
| begin: '->'
| }
| ]
| };
| }
|
| module.exports = rust;
|
|