UNPKG

1.81 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: /(^|[^\\])\/\*[\s\S]*?\*\//,
12 lookbehind: true
13 },
14 {
15 pattern: /(^|[^\\:])\/\/.*/,
16 lookbehind: true
17 }
18 ],
19 'string': [
20 {
21 pattern: /b?r(#*)"(?:\\.|(?!"\1)[^\\\r\n])*"\1/,
22 greedy: true
23 },
24 {
25 pattern: /b?"(?:\\.|[^\\\r\n"])*"/,
26 greedy: true
27 }
28 ],
29 'char': {
30 pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u{(?:[\da-fA-F]_*){1,6}|.)|[^\\\r\n\t'])'/,
31 alias: 'string'
32 },
33 'lifetime-annotation': {
34 pattern: /'[^\s>']+/,
35 alias: 'symbol'
36 },
37 '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/,
38
39 'attribute': {
40 pattern: /#!?\[.+?\]/,
41 greedy: true,
42 alias: 'attr-name'
43 },
44
45 'function': [
46 /\w+(?=\s*\()/,
47 // Macros can use parens or brackets
48 /\w+!(?=\s*\(|\[)/
49 ],
50 'macro-rules': {
51 pattern: /\w+!/,
52 alias: 'function'
53 },
54
55 // Hex, oct, bin, dec numbers with visual separators and type suffix
56 '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)?|f32|f64))?\b/,
57
58 // Closure params should not be confused with bitwise OR |
59 'closure-params': {
60 pattern: /\|[^|]*\|(?=\s*[{-])/,
61 inside: {
62 'punctuation': /[|:,]/,
63 'operator': /[&*]/
64 }
65 },
66 'punctuation': /[{}[\];(),:]|\.+|->/,
67 'operator': /[-+*\/%!^]=?|=[=>]?|@|&[&=]?|\|[|=]?|<<?=?|>>?=?/
68};
\No newline at end of file