Debian Codegraph @

codemirror-legacy-modes/mode/rust.js

raw
1 import {simpleMode} from "./simple-mode.js"
2
3 export const rust = simpleMode({
4 start: [
5 // string and byte string
6 {regex: /b?"/, token: "string", next: "string"},
7 // raw string and raw byte string
8 {regex: /b?r"/, token: "string", next: "string_raw"},
9 {regex: /b?r#+"/, token: "string", next: "string_raw_hash"},
10 // character
11 {regex: /'(?:[^'\\]|\\(?:[nrt0'"]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\}))'/, token: "string.special"},
12 // byte
13 {regex: /b'(?:[^']|\\(?:['\\nrt0]|x[\da-fA-F]{2}))'/, token: "string.special"},
14
15 {regex: /(?:(?:[0-9][0-9_]*)(?:(?:[Ee][+-]?[0-9_]+)|\.[0-9_]+(?:[Ee][+-]?[0-9_]+)?)(?:f32|f64)?)|(?:0(?:b[01_]+|(?:o[0-7_]+)|(?:x[0-9a-fA-F_]+))|(?:[0-9][0-9_]*))(?:u8|u16|u32|u64|i8|i16|i32|i64|isize|usize)?/,
16 token: "number"},
17 {regex: /(let(?:\s+mut)?|fn|enum|mod|struct|type|union)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/, token: ["keyword", null, "def"]},
18 {regex: /(?:abstract|alignof|as|async|await|box|break|continue|const|crate|do|dyn|else|enum|extern|fn|for|final|if|impl|in|loop|macro|match|mod|move|offsetof|override|priv|proc|pub|pure|ref|return|self|sizeof|static|struct|super|trait|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/, token: "keyword"},
19 {regex: /\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|f16|f32|f64|i8|i16|i32|i64|str|Option)\b/, token: "atom"},
20 {regex: /\b(?:true|false|Some|None|Ok|Err)\b/, token: "builtin"},
21 {regex: /\b(fn)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/,
22 token: ["keyword", null ,"def"]},
23 {regex: /#!?\[.*\]/, token: "meta"},
24 {regex: /\/\/.*/, token: "comment"},
25 {regex: /\/\*/, token: "comment", next: "comment"},
26 {regex: /[-+\/*=<>!]+/, token: "operator"},
27 {regex: /[a-zA-Z_]\w*!/,token: "macroName"},
28 {regex: /[a-zA-Z_]\w*/, token: "variable"},
29 {regex: /[\{\[\(]/, indent: true},
30 {regex: /[\}\]\)]/, dedent: true}
31 ],
32 string: [
33 {regex: /"/, token: "string", next: "start"},
34 {regex: /(?:[^\\"]|\\(?:.|$))*/, token: "string"}
35 ],
36 string_raw: [
37 {regex: /"/, token: "string", next: "start"},
38 {regex: /[^"]*/, token: "string"}
39 ],
40 string_raw_hash: [
41 {regex: /"#+/, token: "string", next: "start"},
42 {regex: /(?:[^"]|"(?!#))*/, token: "string"}
43 ],
44 comment: [
45 {regex: /.*?\*\//, token: "comment", next: "start"},
46 {regex: /.*/, token: "comment"}
47 ],
48 languageData: {
49 name: "rust",
50 dontIndentStates: ["comment"],
51 indentOnInput: /^\s*\}$/,
52 commentTokens: {line: "//", block: {open: "/*", close: "*/"}}
53 }
54 });