| 776 |
lars |
1 |
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
|
2 |
// Distributed under an MIT license: http://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 |
|
|
|
14 |
CodeMirror.defineSimpleMode("rust",{
|
|
|
15 |
start:[
|
|
|
16 |
// string and byte string
|
|
|
17 |
{regex: /b?"(?:[^\\]|\\.)*?"/, token: "string"},
|
|
|
18 |
// raw string and raw byte string
|
|
|
19 |
{regex: /(b?r)(#*)(".*?)("\2)/, token: ["string", "string", "string", "string"]},
|
|
|
20 |
// character
|
|
|
21 |
{regex: /'(?:[^'\\]|\\(?:[nrt0'"]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\}))'/, token: "string-2"},
|
|
|
22 |
// byte
|
|
|
23 |
{regex: /b'(?:[^']|\\(?:['\\nrt0]|x[\da-fA-F]{2}))'/, token: "string-2"},
|
|
|
24 |
|
|
|
25 |
{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)?/,
|
|
|
26 |
token: "number"},
|
|
|
27 |
{regex: /(let(?:\s+mut)?|fn|enum|mod|struct|type)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/, token: ["keyword", null, "def"]},
|
|
|
28 |
{regex: /(?:abstract|alignof|as|box|break|continue|const|crate|do|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|unsafe|unsized|use|virtual|where|while|yield)\b/, token: "keyword"},
|
|
|
29 |
{regex: /\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|f16|f32|f64|i8|i16|i32|i64|str|Option)\b/, token: "atom"},
|
|
|
30 |
{regex: /\b(?:true|false|Some|None|Ok|Err)\b/, token: "builtin"},
|
|
|
31 |
{regex: /\b(fn)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/,
|
|
|
32 |
token: ["keyword", null ,"def"]},
|
|
|
33 |
{regex: /#!?\[.*\]/, token: "meta"},
|
|
|
34 |
{regex: /\/\/.*/, token: "comment"},
|
|
|
35 |
{regex: /\/\*/, token: "comment", next: "comment"},
|
|
|
36 |
{regex: /[-+\/*=<>!]+/, token: "operator"},
|
|
|
37 |
{regex: /[a-zA-Z_]\w*!/,token: "variable-3"},
|
|
|
38 |
{regex: /[a-zA-Z_]\w*/, token: "variable"},
|
|
|
39 |
{regex: /[\{\[\(]/, indent: true},
|
|
|
40 |
{regex: /[\}\]\)]/, dedent: true}
|
|
|
41 |
],
|
|
|
42 |
comment: [
|
|
|
43 |
{regex: /.*?\*\//, token: "comment", next: "start"},
|
|
|
44 |
{regex: /.*/, token: "comment"}
|
|
|
45 |
],
|
|
|
46 |
meta: {
|
|
|
47 |
dontIndentStates: ["comment"],
|
|
|
48 |
electricInput: /^\s*\}$/,
|
|
|
49 |
blockCommentStart: "/*",
|
|
|
50 |
blockCommentEnd: "*/",
|
|
|
51 |
lineComment: "//",
|
|
|
52 |
fold: "brace"
|
|
|
53 |
}
|
|
|
54 |
});
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
CodeMirror.defineMIME("text/x-rustsrc", "rust");
|
|
|
58 |
});
|