| 1 |
import { r as rest, l as languages } from "../../index-C1_GGQ8y.js"; |
| 2 |
import { b as boolean } from "../../patterns-Cp3h1ylA.js"; |
| 3 |
import { n as nested } from "../../shared-Sq5P6lf6.js"; |
| 4 |
var multilineComment = nested("/\\*(?:[^*/]|\\*(?!/)|/(?!\\*)|<self>)*\\*/", 2); |
| 5 |
var string = { |
| 6 |
pattern: /b?"(?:\\[^]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/g, |
| 7 |
greedy: true |
| 8 |
}; |
| 9 |
var paramsInside = { |
| 10 |
"closure-punctuation": { |
| 11 |
pattern: /^\||\|$/, |
| 12 |
alias: "punctuation" |
| 13 |
} |
| 14 |
}; |
| 15 |
paramsInside[rest] = languages.rust = { |
| 16 |
"comment": { |
| 17 |
pattern: RegExp("//.*|" + multilineComment, "g"), |
| 18 |
greedy: true |
| 19 |
}, |
| 20 |
"string": string, |
| 21 |
"char": { |
| 22 |
pattern: /b?'(?:\\(?:x[0-7][a-fA-F\d]|u\{(?:[a-fA-F\d]_*){1,6}\}|.)|[^\\\n '])'/g, |
| 23 |
greedy: true |
| 24 |
}, |
| 25 |
"attribute": { |
| 26 |
pattern: /#!?\[(?:[^[\]"]|"(?:\\[^]|[^\\"])*")*\]/g, |
| 27 |
greedy: true, |
| 28 |
alias: "attr-name", |
| 29 |
inside: { |
| 30 |
"string": string |
| 31 |
} |
| 32 |
}, |
| 33 |
// Closure params should not be confused with bitwise OR | |
| 34 |
"closure-params": { |
| 35 |
pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/g, |
| 36 |
lookbehind: true, |
| 37 |
greedy: true, |
| 38 |
inside: paramsInside |
| 39 |
}, |
| 40 |
"lifetime-annotation": { |
| 41 |
pattern: /'\w+/, |
| 42 |
alias: "symbol" |
| 43 |
}, |
| 44 |
"fragment-specifier": { |
| 45 |
pattern: /(\$\w+:)[a-z]+/, |
| 46 |
lookbehind: true, |
| 47 |
alias: "punctuation" |
| 48 |
}, |
| 49 |
"variable": /\$\w+/, |
| 50 |
"function-definition": { |
| 51 |
pattern: /(\bfn\s+)\w+/, |
| 52 |
lookbehind: true, |
| 53 |
alias: "function" |
| 54 |
}, |
| 55 |
"type-definition": { |
| 56 |
pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/, |
| 57 |
lookbehind: true, |
| 58 |
alias: "class-name" |
| 59 |
}, |
| 60 |
"module-declaration": [ |
| 61 |
{ |
| 62 |
pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/, |
| 63 |
lookbehind: true, |
| 64 |
alias: "namespace" |
| 65 |
}, |
| 66 |
{ |
| 67 |
pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/, |
| 68 |
lookbehind: true, |
| 69 |
alias: "namespace", |
| 70 |
inside: { |
| 71 |
"punctuation": /::/ |
| 72 |
} |
| 73 |
} |
| 74 |
], |
| 75 |
// https://github.com/rust-lang/reference/blob/master/src/keywords.md |
| 76 |
// primitives and str |
| 77 |
// https://doc.rust-lang.org/stable/rust-by-example/primitives.html |
| 78 |
"keyword": /\b(?:Self|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|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield|bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/, |
| 79 |
// functions can technically start with an upper-case letter, but this will introduce a lot of false positives |
| 80 |
// and Rust's naming conventions recommend snake_case anyway. |
| 81 |
// https://doc.rust-lang.org/1.0.0/style/style/naming/README.html |
| 82 |
"function": /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/, |
| 83 |
"macro": { |
| 84 |
pattern: /\b\w+!/, |
| 85 |
alias: "property" |
| 86 |
}, |
| 87 |
"constant": /\b[A-Z_][A-Z_\d]+\b/, |
| 88 |
"class-name": /\b[A-Z]\w*\b/, |
| 89 |
"namespace": { |
| 90 |
pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/, |
| 91 |
inside: { |
| 92 |
"punctuation": /::/ |
| 93 |
} |
| 94 |
}, |
| 95 |
// Hex, oct, bin, dec numbers with visual separators and type suffix |
| 96 |
"number": /\b(?:0x[a-fA-F\d](?:_?[a-fA-F\d])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/, |
| 97 |
"boolean": boolean, |
| 98 |
"punctuation": /->|\.\.=|\.{1,3}|::|[()[\]{},:;]/, |
| 99 |
"operator": /&&|\|\||=>|>>=?|<<=?|[%&|^!=<>/*+-]=?|[@?]/ |
| 100 |
}; |
| 101 |
//# sourceMappingURL=rust.js.map |