codemirror-rails 5.5 → 5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror.js +54 -20
- data/vendor/assets/javascripts/codemirror/addons/display/autorefresh.js +47 -0
- data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +6 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +1 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/html-lint.js +46 -0
- data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +8 -2
- data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +2 -2
- data/vendor/assets/javascripts/codemirror/addons/search/search.js +11 -0
- data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +6 -5
- data/vendor/assets/javascripts/codemirror/modes/css.js +26 -10
- data/vendor/assets/javascripts/codemirror/modes/cypher.js +2 -2
- data/vendor/assets/javascripts/codemirror/modes/dockerfile.js +4 -1
- data/vendor/assets/javascripts/codemirror/modes/go.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +1 -6
- data/vendor/assets/javascripts/codemirror/modes/php.js +6 -5
- data/vendor/assets/javascripts/codemirror/modes/rust.js +39 -432
- data/vendor/assets/javascripts/codemirror/modes/stylus.js +10 -9
- data/vendor/assets/stylesheets/codemirror.css +12 -10
- data/vendor/assets/stylesheets/codemirror/themes/3024-day.css +20 -20
- data/vendor/assets/stylesheets/codemirror/themes/3024-night.css +20 -20
- data/vendor/assets/stylesheets/codemirror/themes/abcdef.css +32 -0
- data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +7 -9
- data/vendor/assets/stylesheets/codemirror/themes/base16-dark.css +24 -24
- data/vendor/assets/stylesheets/codemirror/themes/base16-light.css +24 -24
- data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +5 -5
- data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +4 -4
- data/vendor/assets/stylesheets/codemirror/themes/colorforth.css +3 -3
- data/vendor/assets/stylesheets/codemirror/themes/dracula.css +25 -71
- data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +21 -21
- data/vendor/assets/stylesheets/codemirror/themes/elegant.css +12 -12
- data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +4 -4
- data/vendor/assets/stylesheets/codemirror/themes/icecoder.css +29 -29
- data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +14 -14
- data/vendor/assets/stylesheets/codemirror/themes/liquibyte.css +5 -5
- data/vendor/assets/stylesheets/codemirror/themes/material.css +28 -80
- data/vendor/assets/stylesheets/codemirror/themes/mbo.css +23 -23
- data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +6 -6
- data/vendor/assets/stylesheets/codemirror/themes/midnight.css +22 -24
- data/vendor/assets/stylesheets/codemirror/themes/monokai.css +21 -21
- data/vendor/assets/stylesheets/codemirror/themes/neat.css +3 -3
- data/vendor/assets/stylesheets/codemirror/themes/neo.css +7 -7
- data/vendor/assets/stylesheets/codemirror/themes/night.css +4 -4
- data/vendor/assets/stylesheets/codemirror/themes/paraiso-dark.css +24 -24
- data/vendor/assets/stylesheets/codemirror/themes/paraiso-light.css +24 -24
- data/vendor/assets/stylesheets/codemirror/themes/pastel-on-dark.css +3 -3
- data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +3 -3
- data/vendor/assets/stylesheets/codemirror/themes/seti.css +25 -69
- data/vendor/assets/stylesheets/codemirror/themes/solarized.css +7 -9
- data/vendor/assets/stylesheets/codemirror/themes/the-matrix.css +21 -21
- data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-bright.css +24 -24
- data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-eighties.css +24 -24
- data/vendor/assets/stylesheets/codemirror/themes/ttcn.css +45 -46
- data/vendor/assets/stylesheets/codemirror/themes/twilight.css +7 -7
- data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +9 -9
- data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +20 -20
- data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +18 -18
- data/vendor/assets/stylesheets/codemirror/themes/yeti.css +24 -66
- data/vendor/assets/stylesheets/codemirror/themes/zenburn.css +3 -3
- metadata +5 -2
@@ -12,13 +12,16 @@
|
|
12
12
|
"use strict";
|
13
13
|
|
14
14
|
CodeMirror.defineMode("css", function(config, parserConfig) {
|
15
|
+
var provided = parserConfig;
|
15
16
|
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
|
17
|
+
parserConfig.inline = provided.inline;
|
16
18
|
|
17
19
|
var indentUnit = config.indentUnit,
|
18
20
|
tokenHooks = parserConfig.tokenHooks,
|
19
21
|
documentTypes = parserConfig.documentTypes || {},
|
20
22
|
mediaTypes = parserConfig.mediaTypes || {},
|
21
23
|
mediaFeatures = parserConfig.mediaFeatures || {},
|
24
|
+
mediaValueKeywords = parserConfig.mediaValueKeywords || {},
|
22
25
|
propertyKeywords = parserConfig.propertyKeywords || {},
|
23
26
|
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
|
24
27
|
fontProperties = parserConfig.fontProperties || {},
|
@@ -267,6 +270,8 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
267
270
|
override = "attribute";
|
268
271
|
else if (mediaFeatures.hasOwnProperty(word))
|
269
272
|
override = "property";
|
273
|
+
else if (mediaValueKeywords.hasOwnProperty(word))
|
274
|
+
override = "keyword";
|
270
275
|
else if (propertyKeywords.hasOwnProperty(word))
|
271
276
|
override = "property";
|
272
277
|
else if (nonStandardPropertyKeywords.hasOwnProperty(word))
|
@@ -338,9 +343,9 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
338
343
|
return {
|
339
344
|
startState: function(base) {
|
340
345
|
return {tokenize: null,
|
341
|
-
state: "top",
|
346
|
+
state: parserConfig.inline ? "block" : "top",
|
342
347
|
stateArg: null,
|
343
|
-
context: new Context("top", base || 0, null)};
|
348
|
+
context: new Context(parserConfig.inline ? "block" : "top", base || 0, null)};
|
344
349
|
},
|
345
350
|
|
346
351
|
token: function(stream, state) {
|
@@ -401,9 +406,16 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
401
406
|
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
|
402
407
|
"max-color", "color-index", "min-color-index", "max-color-index",
|
403
408
|
"monochrome", "min-monochrome", "max-monochrome", "resolution",
|
404
|
-
"min-resolution", "max-resolution", "scan", "grid"
|
409
|
+
"min-resolution", "max-resolution", "scan", "grid", "orientation",
|
410
|
+
"device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio",
|
411
|
+
"pointer", "any-pointer", "hover", "any-hover"
|
405
412
|
], mediaFeatures = keySet(mediaFeatures_);
|
406
413
|
|
414
|
+
var mediaValueKeywords_ = [
|
415
|
+
"landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover",
|
416
|
+
"interlace", "progressive"
|
417
|
+
], mediaValueKeywords = keySet(mediaValueKeywords_);
|
418
|
+
|
407
419
|
var propertyKeywords_ = [
|
408
420
|
"align-content", "align-items", "align-self", "alignment-adjust",
|
409
421
|
"alignment-baseline", "anchor-point", "animation", "animation-delay",
|
@@ -555,7 +567,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
555
567
|
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
|
556
568
|
"cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
|
557
569
|
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
|
558
|
-
"col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
|
570
|
+
"col-resize", "collapse", "column", "column-reverse", "compact", "condensed", "contain", "content",
|
559
571
|
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
|
560
572
|
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "dashed", "decimal",
|
561
573
|
"decimal-leading-zero", "default", "default-button", "destination-atop",
|
@@ -571,7 +583,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
571
583
|
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
|
572
584
|
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
|
573
585
|
"ethiopic-numeric", "ew-resize", "expanded", "extends", "extra-condensed",
|
574
|
-
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "footnotes",
|
586
|
+
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
|
575
587
|
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
|
576
588
|
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
|
577
589
|
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
|
@@ -608,7 +620,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
608
620
|
"relative", "repeat", "repeating-linear-gradient",
|
609
621
|
"repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
|
610
622
|
"rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
|
611
|
-
"rotateZ", "round", "row-resize", "rtl", "run-in", "running",
|
623
|
+
"rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running",
|
612
624
|
"s-resize", "sans-serif", "scale", "scale3d", "scaleX", "scaleY", "scaleZ",
|
613
625
|
"scroll", "scrollbar", "se-resize", "searchfield",
|
614
626
|
"searchfield-cancel-button", "searchfield-decoration",
|
@@ -618,7 +630,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
618
630
|
"skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
|
619
631
|
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
|
620
632
|
"small", "small-caps", "small-caption", "smaller", "solid", "somali",
|
621
|
-
"source-atop", "source-in", "source-out", "source-over", "space", "spell-out", "square",
|
633
|
+
"source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "spell-out", "square",
|
622
634
|
"square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
|
623
635
|
"subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table",
|
624
636
|
"table-caption", "table-cell", "table-column", "table-column-group",
|
@@ -635,12 +647,13 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
635
647
|
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
|
636
648
|
"var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
|
637
649
|
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
|
638
|
-
"window", "windowframe", "windowtext", "words", "x-large", "x-small", "xor",
|
650
|
+
"window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor",
|
639
651
|
"xx-large", "xx-small"
|
640
652
|
], valueKeywords = keySet(valueKeywords_);
|
641
653
|
|
642
|
-
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(
|
643
|
-
.concat(
|
654
|
+
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_)
|
655
|
+
.concat(propertyKeywords_).concat(nonStandardPropertyKeywords_).concat(colorKeywords_)
|
656
|
+
.concat(valueKeywords_);
|
644
657
|
CodeMirror.registerHelper("hintWords", "css", allWords);
|
645
658
|
|
646
659
|
function tokenCComment(stream, state) {
|
@@ -659,6 +672,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
659
672
|
documentTypes: documentTypes,
|
660
673
|
mediaTypes: mediaTypes,
|
661
674
|
mediaFeatures: mediaFeatures,
|
675
|
+
mediaValueKeywords: mediaValueKeywords,
|
662
676
|
propertyKeywords: propertyKeywords,
|
663
677
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
664
678
|
fontProperties: fontProperties,
|
@@ -678,6 +692,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
678
692
|
CodeMirror.defineMIME("text/x-scss", {
|
679
693
|
mediaTypes: mediaTypes,
|
680
694
|
mediaFeatures: mediaFeatures,
|
695
|
+
mediaValueKeywords: mediaValueKeywords,
|
681
696
|
propertyKeywords: propertyKeywords,
|
682
697
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
683
698
|
colorKeywords: colorKeywords,
|
@@ -719,6 +734,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
|
|
719
734
|
CodeMirror.defineMIME("text/x-less", {
|
720
735
|
mediaTypes: mediaTypes,
|
721
736
|
mediaFeatures: mediaFeatures,
|
737
|
+
mediaValueKeywords: mediaValueKeywords,
|
722
738
|
propertyKeywords: propertyKeywords,
|
723
739
|
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
724
740
|
colorKeywords: colorKeywords,
|
@@ -61,8 +61,8 @@
|
|
61
61
|
var indentUnit = config.indentUnit;
|
62
62
|
var curPunc;
|
63
63
|
var funcs = wordRegexp(["abs", "acos", "allShortestPaths", "asin", "atan", "atan2", "avg", "ceil", "coalesce", "collect", "cos", "cot", "count", "degrees", "e", "endnode", "exp", "extract", "filter", "floor", "haversin", "head", "id", "keys", "labels", "last", "left", "length", "log", "log10", "lower", "ltrim", "max", "min", "node", "nodes", "percentileCont", "percentileDisc", "pi", "radians", "rand", "range", "reduce", "rel", "relationship", "relationships", "replace", "right", "round", "rtrim", "shortestPath", "sign", "sin", "split", "sqrt", "startnode", "stdev", "stdevp", "str", "substring", "sum", "tail", "tan", "timestamp", "toFloat", "toInt", "trim", "type", "upper"]);
|
64
|
-
var preds = wordRegexp(["all", "and", "any", "has", "in", "none", "not", "or", "single", "xor"]);
|
65
|
-
var keywords = wordRegexp(["as", "asc", "ascending", "assert", "by", "case", "commit", "constraint", "create", "csv", "cypher", "delete", "desc", "descending", "distinct", "drop", "else", "end", "explain", "false", "fieldterminator", "foreach", "from", "headers", "in", "index", "is", "limit", "load", "match", "merge", "null", "on", "optional", "order", "periodic", "profile", "remove", "return", "scan", "set", "skip", "start", "then", "true", "union", "unique", "unwind", "using", "when", "where", "with"]);
|
64
|
+
var preds = wordRegexp(["all", "and", "any", "has", "in", "none", "not", "or", "single", "xor", "like", "ilike", "exists"]);
|
65
|
+
var keywords = wordRegexp(["as", "asc", "ascending", "assert", "by", "case", "commit", "constraint", "create", "csv", "cypher", "delete", "desc", "descending", "distinct", "drop", "else", "end", "explain", "false", "fieldterminator", "foreach", "from", "headers", "in", "index", "is", "join", "limit", "load", "match", "merge", "null", "on", "optional", "order", "periodic", "profile", "remove", "return", "scan", "set", "skip", "start", "then", "true", "union", "unique", "unwind", "using", "when", "where", "with"]);
|
66
66
|
var operatorChars = /[*+\-<>=&|~%^]/;
|
67
67
|
|
68
68
|
return {
|
@@ -86,7 +86,7 @@ CodeMirror.defineMode("go", function(config) {
|
|
86
86
|
var escaped = false, next, end = false;
|
87
87
|
while ((next = stream.next()) != null) {
|
88
88
|
if (next == quote && !escaped) {end = true; break;}
|
89
|
-
escaped = !escaped && next == "\\";
|
89
|
+
escaped = !escaped && quote != "`" && next == "\\";
|
90
90
|
}
|
91
91
|
if (end || !(escaped || quote == "`"))
|
92
92
|
state.tokenize = tokenBase;
|
@@ -36,7 +36,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
36
36
|
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
37
37
|
"in": operator, "typeof": operator, "instanceof": operator,
|
38
38
|
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
39
|
-
"this": kw("this"), "
|
39
|
+
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
|
40
40
|
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C
|
41
41
|
};
|
42
42
|
|
@@ -347,7 +347,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
347
347
|
if (type == "default") return cont(expect(":"));
|
348
348
|
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
349
349
|
statement, poplex, popcontext);
|
350
|
-
if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex);
|
351
350
|
if (type == "class") return cont(pushlex("form"), className, poplex);
|
352
351
|
if (type == "export") return cont(pushlex("form"), afterExport, poplex);
|
353
352
|
if (type == "import") return cont(pushlex("form"), afterImport, poplex);
|
@@ -572,10 +571,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
572
571
|
cx.marked = "property";
|
573
572
|
return cont();
|
574
573
|
}
|
575
|
-
function afterModule(type, value) {
|
576
|
-
if (type == "string") return cont(statement);
|
577
|
-
if (type == "variable") { register(value); return cont(maybeFrom); }
|
578
|
-
}
|
579
574
|
function afterExport(_type, value) {
|
580
575
|
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
581
576
|
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
@@ -105,14 +105,15 @@
|
|
105
105
|
return "variable-2";
|
106
106
|
},
|
107
107
|
"<": function(stream, state) {
|
108
|
-
|
109
|
-
|
108
|
+
var before;
|
109
|
+
if (before = stream.match(/<<\s*/)) {
|
110
|
+
var quoted = stream.eat(/['"]/);
|
110
111
|
stream.eatWhile(/[\w\.]/);
|
111
|
-
var delim = stream.current().slice(
|
112
|
-
if (
|
112
|
+
var delim = stream.current().slice(before[0].length + (quoted ? 2 : 1));
|
113
|
+
if (quoted) stream.eat(quoted);
|
113
114
|
if (delim) {
|
114
115
|
(state.tokStack || (state.tokStack = [])).push(delim, 0);
|
115
|
-
state.tokenize = phpString(delim,
|
116
|
+
state.tokenize = phpString(delim, quoted != "'");
|
116
117
|
return "string";
|
117
118
|
}
|
118
119
|
}
|
@@ -3,449 +3,56 @@
|
|
3
3
|
|
4
4
|
(function(mod) {
|
5
5
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6
|
-
mod(require("../../lib/codemirror"));
|
6
|
+
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
|
7
7
|
else if (typeof define == "function" && define.amd) // AMD
|
8
|
-
define(["../../lib/codemirror"], mod);
|
8
|
+
define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
|
9
9
|
else // Plain browser env
|
10
10
|
mod(CodeMirror);
|
11
11
|
})(function(CodeMirror) {
|
12
12
|
"use strict";
|
13
13
|
|
14
|
-
CodeMirror.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
return state.tokenize(stream, state);
|
50
|
-
}
|
51
|
-
if (ch == "'") {
|
52
|
-
tcat = "atom";
|
53
|
-
if (stream.eat("\\")) {
|
54
|
-
if (stream.skipTo("'")) { stream.next(); return "string"; }
|
55
|
-
else { return "error"; }
|
56
|
-
} else {
|
57
|
-
stream.next();
|
58
|
-
return stream.eat("'") ? "string" : "error";
|
59
|
-
}
|
60
|
-
}
|
61
|
-
if (ch == "/") {
|
62
|
-
if (stream.eat("/")) { stream.skipToEnd(); return "comment"; }
|
63
|
-
if (stream.eat("*")) {
|
64
|
-
state.tokenize = tokenComment(1);
|
65
|
-
return state.tokenize(stream, state);
|
66
|
-
}
|
67
|
-
}
|
68
|
-
if (ch == "#") {
|
69
|
-
if (stream.eat("[")) { tcat = "open-attr"; return null; }
|
70
|
-
stream.eatWhile(/\w/);
|
71
|
-
return r("macro", "meta");
|
72
|
-
}
|
73
|
-
if (ch == ":" && stream.match(":<")) {
|
74
|
-
return r("op", null);
|
75
|
-
}
|
76
|
-
if (ch.match(/\d/) || (ch == "." && stream.eat(/\d/))) {
|
77
|
-
var flp = false;
|
78
|
-
if (!stream.match(/^x[\da-f]+/i) && !stream.match(/^b[01]+/)) {
|
79
|
-
stream.eatWhile(/\d/);
|
80
|
-
if (stream.eat(".")) { flp = true; stream.eatWhile(/\d/); }
|
81
|
-
if (stream.match(/^e[+\-]?\d+/i)) { flp = true; }
|
82
|
-
}
|
83
|
-
if (flp) stream.match(/^f(?:32|64)/);
|
84
|
-
else stream.match(/^[ui](?:8|16|32|64)/);
|
85
|
-
return r("atom", "number");
|
86
|
-
}
|
87
|
-
if (ch.match(/[()\[\]{}:;,]/)) return r(ch, null);
|
88
|
-
if (ch == "-" && stream.eat(">")) return r("->", null);
|
89
|
-
if (ch.match(operatorChar)) {
|
90
|
-
stream.eatWhile(operatorChar);
|
91
|
-
return r("op", null);
|
92
|
-
}
|
93
|
-
stream.eatWhile(/\w/);
|
94
|
-
content = stream.current();
|
95
|
-
if (stream.match(/^::\w/)) {
|
96
|
-
stream.backUp(1);
|
97
|
-
return r("prefix", "variable-2");
|
98
|
-
}
|
99
|
-
if (state.keywords.propertyIsEnumerable(content))
|
100
|
-
return r(state.keywords[content], content.match(/true|false/) ? "atom" : "keyword");
|
101
|
-
return r("name", "variable");
|
102
|
-
}
|
103
|
-
|
104
|
-
function tokenString(stream, state) {
|
105
|
-
var ch, escaped = false;
|
106
|
-
while (ch = stream.next()) {
|
107
|
-
if (ch == '"' && !escaped) {
|
108
|
-
state.tokenize = tokenBase;
|
109
|
-
return r("atom", "string");
|
110
|
-
}
|
111
|
-
escaped = !escaped && ch == "\\";
|
112
|
-
}
|
113
|
-
// Hack to not confuse the parser when a string is split in
|
114
|
-
// pieces.
|
115
|
-
return r("op", "string");
|
116
|
-
}
|
117
|
-
|
118
|
-
function tokenComment(depth) {
|
119
|
-
return function(stream, state) {
|
120
|
-
var lastCh = null, ch;
|
121
|
-
while (ch = stream.next()) {
|
122
|
-
if (ch == "/" && lastCh == "*") {
|
123
|
-
if (depth == 1) {
|
124
|
-
state.tokenize = tokenBase;
|
125
|
-
break;
|
126
|
-
} else {
|
127
|
-
state.tokenize = tokenComment(depth - 1);
|
128
|
-
return state.tokenize(stream, state);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
if (ch == "*" && lastCh == "/") {
|
132
|
-
state.tokenize = tokenComment(depth + 1);
|
133
|
-
return state.tokenize(stream, state);
|
134
|
-
}
|
135
|
-
lastCh = ch;
|
136
|
-
}
|
137
|
-
return "comment";
|
138
|
-
};
|
139
|
-
}
|
140
|
-
|
141
|
-
// Parser
|
142
|
-
|
143
|
-
var cx = {state: null, stream: null, marked: null, cc: null};
|
144
|
-
function pass() {
|
145
|
-
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
146
|
-
}
|
147
|
-
function cont() {
|
148
|
-
pass.apply(null, arguments);
|
149
|
-
return true;
|
150
|
-
}
|
151
|
-
|
152
|
-
function pushlex(type, info) {
|
153
|
-
var result = function() {
|
154
|
-
var state = cx.state;
|
155
|
-
state.lexical = {indented: state.indented, column: cx.stream.column(),
|
156
|
-
type: type, prev: state.lexical, info: info};
|
157
|
-
};
|
158
|
-
result.lex = true;
|
159
|
-
return result;
|
160
|
-
}
|
161
|
-
function poplex() {
|
162
|
-
var state = cx.state;
|
163
|
-
if (state.lexical.prev) {
|
164
|
-
if (state.lexical.type == ")")
|
165
|
-
state.indented = state.lexical.indented;
|
166
|
-
state.lexical = state.lexical.prev;
|
167
|
-
}
|
168
|
-
}
|
169
|
-
function typecx() { cx.state.keywords = typeKeywords; }
|
170
|
-
function valcx() { cx.state.keywords = valKeywords; }
|
171
|
-
poplex.lex = typecx.lex = valcx.lex = true;
|
172
|
-
|
173
|
-
function commasep(comb, end) {
|
174
|
-
function more(type) {
|
175
|
-
if (type == ",") return cont(comb, more);
|
176
|
-
if (type == end) return cont();
|
177
|
-
return cont(more);
|
178
|
-
}
|
179
|
-
return function(type) {
|
180
|
-
if (type == end) return cont();
|
181
|
-
return pass(comb, more);
|
182
|
-
};
|
183
|
-
}
|
184
|
-
|
185
|
-
function stat_of(comb, tag) {
|
186
|
-
return cont(pushlex("stat", tag), comb, poplex, block);
|
187
|
-
}
|
188
|
-
function block(type) {
|
189
|
-
if (type == "}") return cont();
|
190
|
-
if (type == "let") return stat_of(letdef1, "let");
|
191
|
-
if (type == "fn") return stat_of(fndef);
|
192
|
-
if (type == "type") return cont(pushlex("stat"), tydef, endstatement, poplex, block);
|
193
|
-
if (type == "enum") return stat_of(enumdef);
|
194
|
-
if (type == "mod") return stat_of(mod);
|
195
|
-
if (type == "iface") return stat_of(iface);
|
196
|
-
if (type == "impl") return stat_of(impl);
|
197
|
-
if (type == "open-attr") return cont(pushlex("]"), commasep(expression, "]"), poplex);
|
198
|
-
if (type == "ignore" || type.match(/[\]\);,]/)) return cont(block);
|
199
|
-
return pass(pushlex("stat"), expression, poplex, endstatement, block);
|
200
|
-
}
|
201
|
-
function endstatement(type) {
|
202
|
-
if (type == ";") return cont();
|
203
|
-
return pass();
|
204
|
-
}
|
205
|
-
function expression(type) {
|
206
|
-
if (type == "atom" || type == "name") return cont(maybeop);
|
207
|
-
if (type == "{") return cont(pushlex("}"), exprbrace, poplex);
|
208
|
-
if (type.match(/[\[\(]/)) return matchBrackets(type, expression);
|
209
|
-
if (type.match(/[\]\)\};,]/)) return pass();
|
210
|
-
if (type == "if-style") return cont(expression, expression);
|
211
|
-
if (type == "else-style" || type == "op") return cont(expression);
|
212
|
-
if (type == "for") return cont(pattern, maybetype, inop, expression, expression);
|
213
|
-
if (type == "alt") return cont(expression, altbody);
|
214
|
-
if (type == "fn") return cont(fndef);
|
215
|
-
if (type == "macro") return cont(macro);
|
216
|
-
return cont();
|
217
|
-
}
|
218
|
-
function maybeop(type) {
|
219
|
-
if (content == ".") return cont(maybeprop);
|
220
|
-
if (content == "::<"){return cont(typarams, maybeop);}
|
221
|
-
if (type == "op" || content == ":") return cont(expression);
|
222
|
-
if (type == "(" || type == "[") return matchBrackets(type, expression);
|
223
|
-
return pass();
|
224
|
-
}
|
225
|
-
function maybeprop() {
|
226
|
-
if (content.match(/^\w+$/)) {cx.marked = "variable"; return cont(maybeop);}
|
227
|
-
return pass(expression);
|
228
|
-
}
|
229
|
-
function exprbrace(type) {
|
230
|
-
if (type == "op") {
|
231
|
-
if (content == "|") return cont(blockvars, poplex, pushlex("}", "block"), block);
|
232
|
-
if (content == "||") return cont(poplex, pushlex("}", "block"), block);
|
233
|
-
}
|
234
|
-
if (content == "mutable" || (content.match(/^\w+$/) && cx.stream.peek() == ":"
|
235
|
-
&& !cx.stream.match("::", false)))
|
236
|
-
return pass(record_of(expression));
|
237
|
-
return pass(block);
|
238
|
-
}
|
239
|
-
function record_of(comb) {
|
240
|
-
function ro(type) {
|
241
|
-
if (content == "mutable" || content == "with") {cx.marked = "keyword"; return cont(ro);}
|
242
|
-
if (content.match(/^\w*$/)) {cx.marked = "variable"; return cont(ro);}
|
243
|
-
if (type == ":") return cont(comb, ro);
|
244
|
-
if (type == "}") return cont();
|
245
|
-
return cont(ro);
|
246
|
-
}
|
247
|
-
return ro;
|
248
|
-
}
|
249
|
-
function blockvars(type) {
|
250
|
-
if (type == "name") {cx.marked = "def"; return cont(blockvars);}
|
251
|
-
if (type == "op" && content == "|") return cont();
|
252
|
-
return cont(blockvars);
|
253
|
-
}
|
254
|
-
|
255
|
-
function letdef1(type) {
|
256
|
-
if (type.match(/[\]\)\};]/)) return cont();
|
257
|
-
if (content == "=") return cont(expression, letdef2);
|
258
|
-
if (type == ",") return cont(letdef1);
|
259
|
-
return pass(pattern, maybetype, letdef1);
|
260
|
-
}
|
261
|
-
function letdef2(type) {
|
262
|
-
if (type.match(/[\]\)\};,]/)) return pass(letdef1);
|
263
|
-
else return pass(expression, letdef2);
|
264
|
-
}
|
265
|
-
function maybetype(type) {
|
266
|
-
if (type == ":") return cont(typecx, rtype, valcx);
|
267
|
-
return pass();
|
268
|
-
}
|
269
|
-
function inop(type) {
|
270
|
-
if (type == "name" && content == "in") {cx.marked = "keyword"; return cont();}
|
271
|
-
return pass();
|
272
|
-
}
|
273
|
-
function fndef(type) {
|
274
|
-
if (content == "@" || content == "~") {cx.marked = "keyword"; return cont(fndef);}
|
275
|
-
if (type == "name") {cx.marked = "def"; return cont(fndef);}
|
276
|
-
if (content == "<") return cont(typarams, fndef);
|
277
|
-
if (type == "{") return pass(expression);
|
278
|
-
if (type == "(") return cont(pushlex(")"), commasep(argdef, ")"), poplex, fndef);
|
279
|
-
if (type == "->") return cont(typecx, rtype, valcx, fndef);
|
280
|
-
if (type == ";") return cont();
|
281
|
-
return cont(fndef);
|
282
|
-
}
|
283
|
-
function tydef(type) {
|
284
|
-
if (type == "name") {cx.marked = "def"; return cont(tydef);}
|
285
|
-
if (content == "<") return cont(typarams, tydef);
|
286
|
-
if (content == "=") return cont(typecx, rtype, valcx);
|
287
|
-
return cont(tydef);
|
288
|
-
}
|
289
|
-
function enumdef(type) {
|
290
|
-
if (type == "name") {cx.marked = "def"; return cont(enumdef);}
|
291
|
-
if (content == "<") return cont(typarams, enumdef);
|
292
|
-
if (content == "=") return cont(typecx, rtype, valcx, endstatement);
|
293
|
-
if (type == "{") return cont(pushlex("}"), typecx, enumblock, valcx, poplex);
|
294
|
-
return cont(enumdef);
|
295
|
-
}
|
296
|
-
function enumblock(type) {
|
297
|
-
if (type == "}") return cont();
|
298
|
-
if (type == "(") return cont(pushlex(")"), commasep(rtype, ")"), poplex, enumblock);
|
299
|
-
if (content.match(/^\w+$/)) cx.marked = "def";
|
300
|
-
return cont(enumblock);
|
301
|
-
}
|
302
|
-
function mod(type) {
|
303
|
-
if (type == "name") {cx.marked = "def"; return cont(mod);}
|
304
|
-
if (type == "{") return cont(pushlex("}"), block, poplex);
|
305
|
-
return pass();
|
306
|
-
}
|
307
|
-
function iface(type) {
|
308
|
-
if (type == "name") {cx.marked = "def"; return cont(iface);}
|
309
|
-
if (content == "<") return cont(typarams, iface);
|
310
|
-
if (type == "{") return cont(pushlex("}"), block, poplex);
|
311
|
-
return pass();
|
312
|
-
}
|
313
|
-
function impl(type) {
|
314
|
-
if (content == "<") return cont(typarams, impl);
|
315
|
-
if (content == "of" || content == "for") {cx.marked = "keyword"; return cont(rtype, impl);}
|
316
|
-
if (type == "name") {cx.marked = "def"; return cont(impl);}
|
317
|
-
if (type == "{") return cont(pushlex("}"), block, poplex);
|
318
|
-
return pass();
|
319
|
-
}
|
320
|
-
function typarams() {
|
321
|
-
if (content == ">") return cont();
|
322
|
-
if (content == ",") return cont(typarams);
|
323
|
-
if (content == ":") return cont(rtype, typarams);
|
324
|
-
return pass(rtype, typarams);
|
325
|
-
}
|
326
|
-
function argdef(type) {
|
327
|
-
if (type == "name") {cx.marked = "def"; return cont(argdef);}
|
328
|
-
if (type == ":") return cont(typecx, rtype, valcx);
|
329
|
-
return pass();
|
330
|
-
}
|
331
|
-
function rtype(type) {
|
332
|
-
if (type == "name") {cx.marked = "variable-3"; return cont(rtypemaybeparam); }
|
333
|
-
if (content == "mutable") {cx.marked = "keyword"; return cont(rtype);}
|
334
|
-
if (type == "atom") return cont(rtypemaybeparam);
|
335
|
-
if (type == "op" || type == "obj") return cont(rtype);
|
336
|
-
if (type == "fn") return cont(fntype);
|
337
|
-
if (type == "{") return cont(pushlex("{"), record_of(rtype), poplex);
|
338
|
-
return matchBrackets(type, rtype);
|
339
|
-
}
|
340
|
-
function rtypemaybeparam() {
|
341
|
-
if (content == "<") return cont(typarams);
|
342
|
-
return pass();
|
343
|
-
}
|
344
|
-
function fntype(type) {
|
345
|
-
if (type == "(") return cont(pushlex("("), commasep(rtype, ")"), poplex, fntype);
|
346
|
-
if (type == "->") return cont(rtype);
|
347
|
-
return pass();
|
348
|
-
}
|
349
|
-
function pattern(type) {
|
350
|
-
if (type == "name") {cx.marked = "def"; return cont(patternmaybeop);}
|
351
|
-
if (type == "atom") return cont(patternmaybeop);
|
352
|
-
if (type == "op") return cont(pattern);
|
353
|
-
if (type.match(/[\]\)\};,]/)) return pass();
|
354
|
-
return matchBrackets(type, pattern);
|
355
|
-
}
|
356
|
-
function patternmaybeop(type) {
|
357
|
-
if (type == "op" && content == ".") return cont();
|
358
|
-
if (content == "to") {cx.marked = "keyword"; return cont(pattern);}
|
359
|
-
else return pass();
|
360
|
-
}
|
361
|
-
function altbody(type) {
|
362
|
-
if (type == "{") return cont(pushlex("}", "alt"), altblock1, poplex);
|
363
|
-
return pass();
|
364
|
-
}
|
365
|
-
function altblock1(type) {
|
366
|
-
if (type == "}") return cont();
|
367
|
-
if (type == "|") return cont(altblock1);
|
368
|
-
if (content == "when") {cx.marked = "keyword"; return cont(expression, altblock2);}
|
369
|
-
if (type.match(/[\]\);,]/)) return cont(altblock1);
|
370
|
-
return pass(pattern, altblock2);
|
371
|
-
}
|
372
|
-
function altblock2(type) {
|
373
|
-
if (type == "{") return cont(pushlex("}", "alt"), block, poplex, altblock1);
|
374
|
-
else return pass(altblock1);
|
375
|
-
}
|
376
|
-
|
377
|
-
function macro(type) {
|
378
|
-
if (type.match(/[\[\(\{]/)) return matchBrackets(type, expression);
|
379
|
-
return pass();
|
380
|
-
}
|
381
|
-
function matchBrackets(type, comb) {
|
382
|
-
if (type == "[") return cont(pushlex("]"), commasep(comb, "]"), poplex);
|
383
|
-
if (type == "(") return cont(pushlex(")"), commasep(comb, ")"), poplex);
|
384
|
-
if (type == "{") return cont(pushlex("}"), commasep(comb, "}"), poplex);
|
385
|
-
return cont();
|
386
|
-
}
|
387
|
-
|
388
|
-
function parse(state, stream, style) {
|
389
|
-
var cc = state.cc;
|
390
|
-
// Communicate our context to the combinators.
|
391
|
-
// (Less wasteful than consing up a hundred closures on every call.)
|
392
|
-
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
|
393
|
-
|
394
|
-
while (true) {
|
395
|
-
var combinator = cc.length ? cc.pop() : block;
|
396
|
-
if (combinator(tcat)) {
|
397
|
-
while(cc.length && cc[cc.length - 1].lex)
|
398
|
-
cc.pop()();
|
399
|
-
return cx.marked || style;
|
400
|
-
}
|
401
|
-
}
|
402
|
-
}
|
403
|
-
|
404
|
-
return {
|
405
|
-
startState: function() {
|
406
|
-
return {
|
407
|
-
tokenize: tokenBase,
|
408
|
-
cc: [],
|
409
|
-
lexical: {indented: -indentUnit, column: 0, type: "top", align: false},
|
410
|
-
keywords: valKeywords,
|
411
|
-
indented: 0
|
412
|
-
};
|
413
|
-
},
|
414
|
-
|
415
|
-
token: function(stream, state) {
|
416
|
-
if (stream.sol()) {
|
417
|
-
if (!state.lexical.hasOwnProperty("align"))
|
418
|
-
state.lexical.align = false;
|
419
|
-
state.indented = stream.indentation();
|
420
|
-
}
|
421
|
-
if (stream.eatSpace()) return null;
|
422
|
-
tcat = content = null;
|
423
|
-
var style = state.tokenize(stream, state);
|
424
|
-
if (style == "comment") return style;
|
425
|
-
if (!state.lexical.hasOwnProperty("align"))
|
426
|
-
state.lexical.align = true;
|
427
|
-
if (tcat == "prefix") return style;
|
428
|
-
if (!content) content = stream.current();
|
429
|
-
return parse(state, stream, style);
|
430
|
-
},
|
431
|
-
|
432
|
-
indent: function(state, textAfter) {
|
433
|
-
if (state.tokenize != tokenBase) return 0;
|
434
|
-
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
|
435
|
-
type = lexical.type, closing = firstChar == type;
|
436
|
-
if (type == "stat") return lexical.indented + indentUnit;
|
437
|
-
if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
438
|
-
return lexical.indented + (closing ? 0 : (lexical.info == "alt" ? altIndentUnit : indentUnit));
|
439
|
-
},
|
440
|
-
|
441
|
-
electricChars: "{}",
|
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*\}$/,
|
442
49
|
blockCommentStart: "/*",
|
443
50
|
blockCommentEnd: "*/",
|
444
51
|
lineComment: "//",
|
445
52
|
fold: "brace"
|
446
|
-
}
|
53
|
+
}
|
447
54
|
});
|
448
55
|
|
449
|
-
CodeMirror.defineMIME("text/x-rustsrc", "rust");
|
450
56
|
|
57
|
+
CodeMirror.defineMIME("text/x-rustsrc", "rust");
|
451
58
|
});
|