1 | (function (Prism) {
|
2 |
|
3 | var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
|
4 | for (var i = 0; i < 2; i++) {
|
5 |
|
6 | multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
|
7 | }
|
8 | multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
|
9 |
|
10 |
|
11 | Prism.languages.rust = {
|
12 | 'comment': [
|
13 | {
|
14 | pattern: RegExp(/(^|[^\\])/.source + multilineComment),
|
15 | lookbehind: true,
|
16 | greedy: true
|
17 | },
|
18 | {
|
19 | pattern: /(^|[^\\:])\/\/.*/,
|
20 | lookbehind: true,
|
21 | greedy: true
|
22 | }
|
23 | ],
|
24 | 'string': {
|
25 | pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
|
26 | greedy: true
|
27 | },
|
28 | 'char': {
|
29 | pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,
|
30 | greedy: true,
|
31 | alias: 'string'
|
32 | },
|
33 | 'attribute': {
|
34 | pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
|
35 | greedy: true,
|
36 | alias: 'attr-name',
|
37 | inside: {
|
38 | 'string': null
|
39 | }
|
40 | },
|
41 |
|
42 |
|
43 | 'closure-params': {
|
44 | pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
|
45 | lookbehind: true,
|
46 | greedy: true,
|
47 | inside: {
|
48 | 'closure-punctuation': {
|
49 | pattern: /^\||\|$/,
|
50 | alias: 'punctuation'
|
51 | },
|
52 | rest: null
|
53 | }
|
54 | },
|
55 |
|
56 | 'lifetime-annotation': {
|
57 | pattern: /'\w+/,
|
58 | alias: 'symbol'
|
59 | },
|
60 |
|
61 | 'fragment-specifier': {
|
62 | pattern: /(\$\w+:)[a-z]+/,
|
63 | lookbehind: true,
|
64 | alias: 'punctuation'
|
65 | },
|
66 | 'variable': /\$\w+/,
|
67 |
|
68 | 'function-definition': {
|
69 | pattern: /(\bfn\s+)\w+/,
|
70 | lookbehind: true,
|
71 | alias: 'function'
|
72 | },
|
73 | 'type-definition': {
|
74 | pattern: /(\b(?:enum|struct|union)\s+)\w+/,
|
75 | lookbehind: true,
|
76 | alias: 'class-name'
|
77 | },
|
78 | 'module-declaration': [
|
79 | {
|
80 | pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
|
81 | lookbehind: true,
|
82 | alias: 'namespace'
|
83 | },
|
84 | {
|
85 | pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
|
86 | lookbehind: true,
|
87 | alias: 'namespace',
|
88 | inside: {
|
89 | 'punctuation': /::/
|
90 | }
|
91 | }
|
92 | ],
|
93 | 'keyword': [
|
94 |
|
95 | /\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,
|
96 |
|
97 |
|
98 | /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/
|
99 | ],
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
|
105 | 'macro': {
|
106 | pattern: /\w+!/,
|
107 | alias: 'property'
|
108 | },
|
109 | 'constant': /\b[A-Z_][A-Z_\d]+\b/,
|
110 | 'class-name': /\b[A-Z]\w*\b/,
|
111 |
|
112 | 'namespace': {
|
113 | pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
|
114 | inside: {
|
115 | 'punctuation': /::/
|
116 | }
|
117 | },
|
118 |
|
119 |
|
120 | 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,
|
121 | 'boolean': /\b(?:false|true)\b/,
|
122 | 'punctuation': /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
|
123 | 'operator': /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
|
124 | };
|
125 |
|
126 | Prism.languages.rust['closure-params'].inside.rest = Prism.languages.rust;
|
127 | Prism.languages.rust['attribute'].inside['string'] = Prism.languages.rust['string'];
|
128 |
|
129 | }(Prism));
|