all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/rust/rust.js (view raw)

 1// CodeMirror, copyright (c) by Marijn Haverbeke and others
 2// Distributed under an MIT license: https://codemirror.net/LICENSE
 3
 4(function(mod) {
 5  if (typeof exports == "object" && typeof module == "object") // CommonJS
 6    mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
 7  else if (typeof define == "function" && define.amd) // AMD
 8    define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
 9  else // Plain browser env
10    mod(CodeMirror);
11})(function(CodeMirror) {
12"use strict";
13
14CodeMirror.defineSimpleMode("rust",{
15  start: [
16    // string and byte string
17    {regex: /b?"/, token: "string", next: "string"},
18    // raw string and raw byte string
19    {regex: /b?r"/, token: "string", next: "string_raw"},
20    {regex: /b?r#+"/, token: "string", next: "string_raw_hash"},
21    // character
22    {regex: /'(?:[^'\\]|\\(?:[nrt0'"]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\}))'/, token: "string-2"},
23    // byte
24    {regex: /b'(?:[^']|\\(?:['\\nrt0]|x[\da-fA-F]{2}))'/, token: "string-2"},
25
26    {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)?/,
27     token: "number"},
28    {regex: /(let(?:\s+mut)?|fn|enum|mod|struct|type|union)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/, token: ["keyword", null, "def"]},
29    {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"},
30    {regex: /\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|f16|f32|f64|i8|i16|i32|i64|str|Option)\b/, token: "atom"},
31    {regex: /\b(?:true|false|Some|None|Ok|Err)\b/, token: "builtin"},
32    {regex: /\b(fn)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/,
33     token: ["keyword", null ,"def"]},
34    {regex: /#!?\[.*\]/, token: "meta"},
35    {regex: /\/\/.*/, token: "comment"},
36    {regex: /\/\*/, token: "comment", next: "comment"},
37    {regex: /[-+\/*=<>!]+/, token: "operator"},
38    {regex: /[a-zA-Z_]\w*!/,token: "variable-3"},
39    {regex: /[a-zA-Z_]\w*/, token: "variable"},
40    {regex: /[\{\[\(]/, indent: true},
41    {regex: /[\}\]\)]/, dedent: true}
42  ],
43  string: [
44    {regex: /"/, token: "string", next: "start"},
45    {regex: /(?:[^\\"]|\\(?:.|$))*/, token: "string"}
46  ],
47  string_raw: [
48    {regex: /"/, token: "string", next: "start"},
49    {regex: /[^"]*/, token: "string"}
50  ],
51  string_raw_hash: [
52    {regex: /"#+/, token: "string", next: "start"},
53    {regex: /(?:[^"]|"(?!#))*/, token: "string"}
54  ],
55  comment: [
56    {regex: /.*?\*\//, token: "comment", next: "start"},
57    {regex: /.*/, token: "comment"}
58  ],
59  meta: {
60    dontIndentStates: ["comment"],
61    electricInput: /^\s*\}$/,
62    blockCommentStart: "/*",
63    blockCommentEnd: "*/",
64    lineComment: "//",
65    fold: "brace"
66  }
67});
68
69
70CodeMirror.defineMIME("text/x-rustsrc", "rust");
71CodeMirror.defineMIME("text/rust", "rust");
72});