]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/rust.js
1 /*! `rust` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Author: Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
9 Contributors: Roman Shmatov <romanshmatov@gmail.com>, Kasper Andersen <kma_untrusted@protonmail.com>
10 Website: https://www.rust-lang.org
11 Category: common, system
14 /** @type LanguageFn */
17 const regex
= hljs
.regex
;
18 // ============================================
19 // Added to support the r# keyword, which is a raw identifier in Rust.
20 const RAW_IDENTIFIER
= /(r#)?/;
21 const UNDERSCORE_IDENT_RE
= regex
.concat(RAW_IDENTIFIER
, hljs
.UNDERSCORE_IDENT_RE
);
22 const IDENT_RE
= regex
.concat(RAW_IDENTIFIER
, hljs
.IDENT_RE
);
23 // ============================================
24 const FUNCTION_INVOKE
= {
25 className: "title.function.invoke",
29 /(?!let|for|while|if|else|match\b)/,
31 regex
.lookahead(/\s*\(/))
33 const NUMBER_SUFFIX
= '([ui](8|16|32|64|128|size)|f(32|64))\?';
123 "DoubleEndedIterator",
192 $pattern: hljs
.IDENT_RE
+ '!?',
200 hljs
.C_LINE_COMMENT_MODE
,
201 hljs
.COMMENT('/\\*', '\\*/', { contains: [ 'self' ] }),
202 hljs
.inherit(hljs
.QUOTE_STRING_MODE
, {
208 // negative lookahead to avoid matching `'`
209 begin: /'[a-zA-Z_][a-zA-Z0-9_]*(?!')/
214 { begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ },
220 scope: "char.escape",
221 match: /\\('|\w
|x
\w
{2}|u
\w
{4}|U
\w
{8})/
230 { begin: '\\b0b([01_]+)' + NUMBER_SUFFIX
},
231 { begin: '\\b0o([0-7_]+)' + NUMBER_SUFFIX
},
232 { begin: '\\b0x([A-Fa-f0-9_]+)' + NUMBER_SUFFIX
},
233 { begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)'
259 hljs
.BACKSLASH_ESCAPE
277 // must come before impl/for rule later
305 /(?:trait|enum|struct|union|impl|for)/,
315 begin: hljs
.IDENT_RE
+ '::',
323 className: "punctuation",
335 hljs
.registerLanguage('rust', hljsGrammar
);