UNPKG

1.55 kBJavaScriptView Raw
1/* TODO
2 Add support for Markdown notation inside doc comments
3 Add support for nested block comments...
4 Match closure params even when not followed by dash or brace
5 Add better support for macro definition
6*/
7
8Prism.languages.rust = {
9 'comment': [
10 {
11 pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
12 lookbehind: true
13 },
14 {
15 pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/,
16 lookbehind: true
17 }
18 ],
19 'string': [
20 /b?r(#*)"(?:\\?.)*?"\1/,
21 /b?("|')(?:\\?.)*?\1/
22 ],
23 'keyword': /\b(?:abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|match|mod|move|mut|offsetof|once|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\b/,
24
25 'attribute': {
26 pattern: /#!?\[.+?\]/,
27 alias: 'attr-name'
28 },
29
30 'function': [
31 /[a-z0-9_]+(?=\s*\()/i,
32 // Macros can use parens or brackets
33 /[a-z0-9_]+!(?=\s*\(|\[)/i
34 ],
35 'macro-rules': {
36 pattern: /[a-z0-9_]+!/i,
37 alias: 'function'
38 },
39
40 // Hex, oct, bin, dec numbers with visual separators and type suffix
41 '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)?|f32|f64))?\b/,
42
43 // Closure params should not be confused with bitwise OR |
44 'closure-params': {
45 pattern: /\|[^|]*\|(?=\s*[{-])/,
46 inside: {
47 'punctuation': /[\|:,]/,
48 'operator': /[&*]/
49 }
50 },
51 'punctuation': /[{}[\];(),.:]|->/,
52 'operator': /[-+]{1,2}|!=?|<=?|>=?|={1,3}|&&?|\|\|?|\*|\/|\^|%|<<|>>@/
53};
\No newline at end of file