codemirror-rails 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/README.md +18 -7
- data/codemirror-rails.gemspec +2 -0
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror.js +852 -399
- data/vendor/assets/javascripts/codemirror/modes/gfm.js +108 -0
- data/vendor/assets/javascripts/codemirror/modes/groovy.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +8 -2
- data/vendor/assets/javascripts/codemirror/modes/lua.js +1 -1
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +43 -31
- data/vendor/assets/javascripts/codemirror/modes/perl.js +10 -4
- data/vendor/assets/javascripts/codemirror/modes/rpm-changes.js +19 -0
- data/vendor/assets/javascripts/codemirror/modes/rpm-spec.js +66 -0
- data/vendor/assets/javascripts/codemirror/modes/rust.js +38 -22
- data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +10 -0
- data/vendor/assets/javascripts/codemirror/modes/xml.js +2 -1
- data/vendor/assets/stylesheets/codemirror.css +9 -0
- data/vendor/assets/stylesheets/codemirror/modes/rpm-spec.css +5 -0
- data/vendor/assets/stylesheets/codemirror/themes/default.css +1 -1
- data/vendor/assets/stylesheets/codemirror/themes/monokai.css +27 -0
- data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +20 -0
- metadata +21 -3
@@ -0,0 +1,108 @@
|
|
1
|
+
CodeMirror.defineMode("gfm", function(config, parserConfig) {
|
2
|
+
var mdMode = CodeMirror.getMode(config, "markdown");
|
3
|
+
var aliases = {
|
4
|
+
html: "htmlmixed",
|
5
|
+
js: "javascript",
|
6
|
+
json: "application/json",
|
7
|
+
c: "text/x-csrc",
|
8
|
+
"c++": "text/x-c++src",
|
9
|
+
java: "text/x-java",
|
10
|
+
csharp: "text/x-csharp",
|
11
|
+
"c#": "text/x-csharp",
|
12
|
+
};
|
13
|
+
|
14
|
+
// make this lazy so that we don't need to load GFM last
|
15
|
+
var getMode = (function () {
|
16
|
+
var i, modes = {}, mimes = {}, mime;
|
17
|
+
|
18
|
+
var list = CodeMirror.listModes();
|
19
|
+
for (i = 0; i < list.length; i++) {
|
20
|
+
modes[list[i]] = list[i];
|
21
|
+
}
|
22
|
+
var mimesList = CodeMirror.listMIMEs();
|
23
|
+
for (i = 0; i < mimesList.length; i++) {
|
24
|
+
mime = mimesList[i].mime;
|
25
|
+
mimes[mime] = mimesList[i].mime;
|
26
|
+
}
|
27
|
+
|
28
|
+
for (var a in aliases) {
|
29
|
+
if (aliases[a] in modes || aliases[a] in mimes)
|
30
|
+
modes[a] = aliases[a];
|
31
|
+
}
|
32
|
+
|
33
|
+
return function (lang) {
|
34
|
+
return modes[lang] ? CodeMirror.getMode(config, modes[lang]) : null;
|
35
|
+
}
|
36
|
+
}());
|
37
|
+
|
38
|
+
function markdown(stream, state) {
|
39
|
+
// intercept fenced code blocks
|
40
|
+
if (stream.sol() && stream.match(/^```([\w+#]*)/)) {
|
41
|
+
// try switching mode
|
42
|
+
state.localMode = getMode(RegExp.$1)
|
43
|
+
if (state.localMode)
|
44
|
+
state.localState = state.localMode.startState();
|
45
|
+
|
46
|
+
state.token = local;
|
47
|
+
return 'code';
|
48
|
+
}
|
49
|
+
|
50
|
+
return mdMode.token(stream, state.mdState);
|
51
|
+
}
|
52
|
+
|
53
|
+
function local(stream, state) {
|
54
|
+
if (stream.sol() && stream.match(/^```/)) {
|
55
|
+
state.localMode = state.localState = null;
|
56
|
+
state.token = markdown;
|
57
|
+
return 'code';
|
58
|
+
}
|
59
|
+
else if (state.localMode) {
|
60
|
+
return state.localMode.token(stream, state.localState);
|
61
|
+
} else {
|
62
|
+
stream.skipToEnd();
|
63
|
+
return 'code';
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
// custom handleText to prevent emphasis in the middle of a word
|
68
|
+
// and add autolinking
|
69
|
+
function handleText(stream, mdState) {
|
70
|
+
var match;
|
71
|
+
if (stream.match(/^\w+:\/\/\S+/)) {
|
72
|
+
return 'linkhref';
|
73
|
+
}
|
74
|
+
if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) {
|
75
|
+
return mdMode.getType(mdState);
|
76
|
+
}
|
77
|
+
if (match = stream.match(/^[^\[*\\<>` ]+/)) {
|
78
|
+
var word = match[0];
|
79
|
+
if (word[0] === '_' && word[word.length-1] === '_') {
|
80
|
+
stream.backUp(word.length);
|
81
|
+
return undefined;
|
82
|
+
}
|
83
|
+
return mdMode.getType(mdState);
|
84
|
+
}
|
85
|
+
if (stream.eatSpace()) {
|
86
|
+
return null;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
return {
|
91
|
+
startState: function() {
|
92
|
+
var mdState = mdMode.startState();
|
93
|
+
mdState.text = handleText;
|
94
|
+
return {token: markdown, mode: "markdown", mdState: mdState,
|
95
|
+
localMode: null, localState: null};
|
96
|
+
},
|
97
|
+
|
98
|
+
copyState: function(state) {
|
99
|
+
return {token: state.token, mode: state.mode, mdState: CodeMirror.copyState(mdMode, state.mdState),
|
100
|
+
localMode: state.localMode,
|
101
|
+
localState: state.localMode ? CodeMirror.copyState(state.localMode, state.localState) : null};
|
102
|
+
},
|
103
|
+
|
104
|
+
token: function(stream, state) {
|
105
|
+
return state.token(stream, state);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
});
|
@@ -25,7 +25,7 @@ CodeMirror.defineMode("groovy", function(config, parserConfig) {
|
|
25
25
|
}
|
26
26
|
if (/\d/.test(ch)) {
|
27
27
|
stream.eatWhile(/[\w\.]/);
|
28
|
-
if (stream.eat(/eE/)) { stream.eat(
|
28
|
+
if (stream.eat(/eE/)) { stream.eat(/\+\-/); stream.eatWhile(/\d/); }
|
29
29
|
return "number";
|
30
30
|
}
|
31
31
|
if (ch == "/") {
|
@@ -11,7 +11,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
11
11
|
return {
|
12
12
|
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
13
13
|
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
|
14
|
-
"var": kw("var"), "
|
14
|
+
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
15
|
+
"function": kw("function"), "catch": kw("catch"),
|
15
16
|
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
16
17
|
"in": operator, "typeof": operator, "instanceof": operator,
|
17
18
|
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
@@ -228,13 +229,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|
228
229
|
function expression(type) {
|
229
230
|
if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
|
230
231
|
if (type == "function") return cont(functiondef);
|
231
|
-
if (type == "keyword c") return cont(
|
232
|
+
if (type == "keyword c") return cont(maybeexpression);
|
232
233
|
if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
233
234
|
if (type == "operator") return cont(expression);
|
234
235
|
if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
235
236
|
if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
236
237
|
return cont();
|
237
238
|
}
|
239
|
+
function maybeexpression(type) {
|
240
|
+
if (type.match(/[;\}\)\],]/)) return pass();
|
241
|
+
return pass(expression);
|
242
|
+
}
|
243
|
+
|
238
244
|
function maybeoperator(type, value) {
|
239
245
|
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
|
240
246
|
if (type == "operator") return cont(expression);
|
@@ -123,7 +123,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
|
|
123
123
|
else if (builtins.test(word)) style = "builtin";
|
124
124
|
else if (specials.test(word)) style = "variable-2";
|
125
125
|
}
|
126
|
-
if ((style != "
|
126
|
+
if ((style != "comment") && (style != "string")){
|
127
127
|
if (indentTokens.test(word)) ++state.indentDepth;
|
128
128
|
else if (dedentTokens.test(word)) --state.indentDepth;
|
129
129
|
}
|
@@ -51,9 +51,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
51
51
|
state.indentation++;
|
52
52
|
return quote;
|
53
53
|
}
|
54
|
-
if (stream.peek() === '<') {
|
55
|
-
return switchBlock(stream, state, htmlBlock);
|
56
|
-
}
|
57
54
|
if (stream.peek() === '[') {
|
58
55
|
return switchInline(stream, state, footnoteLink);
|
59
56
|
}
|
@@ -74,51 +71,59 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
74
71
|
}
|
75
72
|
|
76
73
|
function htmlBlock(stream, state) {
|
77
|
-
var
|
78
|
-
if (
|
74
|
+
var style = htmlMode.token(stream, state.htmlState);
|
75
|
+
if (style === 'tag' && state.htmlState.type !== 'openTag' && !state.htmlState.context) {
|
76
|
+
state.f = inlineNormal;
|
79
77
|
state.block = blockNormal;
|
80
78
|
}
|
81
|
-
return
|
79
|
+
return style;
|
82
80
|
}
|
83
81
|
|
84
82
|
|
85
83
|
// Inline
|
84
|
+
function getType(state) {
|
85
|
+
return state.strong ? (state.em ? emstrong : strong)
|
86
|
+
: (state.em ? em : null);
|
87
|
+
}
|
86
88
|
|
87
|
-
function
|
88
|
-
function getType() {
|
89
|
-
return state.strong ? (state.em ? emstrong : strong)
|
90
|
-
: (state.em ? em : null);
|
91
|
-
}
|
92
|
-
|
89
|
+
function handleText(stream, state) {
|
93
90
|
if (stream.match(textRE, true)) {
|
94
|
-
return getType();
|
91
|
+
return getType(state);
|
95
92
|
}
|
93
|
+
return undefined;
|
94
|
+
}
|
95
|
+
|
96
|
+
function inlineNormal(stream, state) {
|
97
|
+
var style = state.text(stream, state)
|
98
|
+
if (typeof style !== 'undefined')
|
99
|
+
return style;
|
96
100
|
|
97
101
|
var ch = stream.next();
|
98
102
|
|
99
103
|
if (ch === '\\') {
|
100
104
|
stream.next();
|
101
|
-
return getType();
|
105
|
+
return getType(state);
|
102
106
|
}
|
103
107
|
if (ch === '`') {
|
104
108
|
return switchInline(stream, state, inlineElement(code, '`'));
|
105
109
|
}
|
106
|
-
if (ch === '<') {
|
107
|
-
return switchInline(stream, state, inlineElement(linktext, '>'));
|
108
|
-
}
|
109
110
|
if (ch === '[') {
|
110
111
|
return switchInline(stream, state, linkText);
|
111
112
|
}
|
112
|
-
|
113
|
-
|
113
|
+
if (ch === '<' && stream.match(/^\w/, false)) {
|
114
|
+
stream.backUp(1);
|
115
|
+
return switchBlock(stream, state, htmlBlock);
|
116
|
+
}
|
117
|
+
|
118
|
+
var t = getType(state);
|
114
119
|
if (ch === '*' || ch === '_') {
|
115
120
|
if (stream.eat(ch)) {
|
116
|
-
return (state.strong = !state.strong) ? getType() : t;
|
121
|
+
return (state.strong = !state.strong) ? getType(state) : t;
|
117
122
|
}
|
118
|
-
return (state.em = !state.em) ? getType() : t;
|
123
|
+
return (state.em = !state.em) ? getType(state) : t;
|
119
124
|
}
|
120
125
|
|
121
|
-
return getType();
|
126
|
+
return getType(state);
|
122
127
|
}
|
123
128
|
|
124
129
|
function linkText(stream, state) {
|
@@ -157,17 +162,20 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
157
162
|
return linkhref;
|
158
163
|
}
|
159
164
|
|
165
|
+
function inlineRE(endChar) {
|
166
|
+
if (!inlineRE[endChar]) {
|
167
|
+
// match any not-escaped-non-endChar and any escaped char
|
168
|
+
// then match endChar or eol
|
169
|
+
inlineRE[endChar] = new RegExp('^(?:[^\\\\\\' + endChar + ']|\\\\.)*(?:\\' + endChar + '|$)');
|
170
|
+
}
|
171
|
+
return inlineRE[endChar];
|
172
|
+
}
|
173
|
+
|
160
174
|
function inlineElement(type, endChar, next) {
|
161
175
|
next = next || inlineNormal;
|
162
176
|
return function(stream, state) {
|
163
|
-
|
164
|
-
|
165
|
-
if (ch === '\\') stream.next();
|
166
|
-
if (ch === endChar) {
|
167
|
-
state.inline = state.f = next;
|
168
|
-
return type;
|
169
|
-
}
|
170
|
-
}
|
177
|
+
stream.match(inlineRE(endChar));
|
178
|
+
state.inline = state.f = next;
|
171
179
|
return type;
|
172
180
|
};
|
173
181
|
}
|
@@ -182,6 +190,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
182
190
|
indentation: 0,
|
183
191
|
|
184
192
|
inline: inlineNormal,
|
193
|
+
text: handleText,
|
185
194
|
em: false,
|
186
195
|
strong: false
|
187
196
|
};
|
@@ -196,6 +205,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
196
205
|
indentation: s.indentation,
|
197
206
|
|
198
207
|
inline: s.inline,
|
208
|
+
text: s.text,
|
199
209
|
em: s.em,
|
200
210
|
strong: s.strong
|
201
211
|
};
|
@@ -222,7 +232,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
222
232
|
if (currentIndentation > 0) return null;
|
223
233
|
}
|
224
234
|
return state.f(stream, state);
|
225
|
-
}
|
235
|
+
},
|
236
|
+
|
237
|
+
getType: getType
|
226
238
|
};
|
227
239
|
|
228
240
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// CodeMirror2 mode/perl/perl.js (text/x-perl) beta 0.
|
1
|
+
// CodeMirror2 mode/perl/perl.js (text/x-perl) beta 0.10 (2011-11-08)
|
2
2
|
// This is a part of CodeMirror from https://github.com/sabaca/CodeMirror_mode_perl (mail@sabaca.com)
|
3
3
|
CodeMirror.defineMode("perl",function(config,parserConfig){
|
4
4
|
// http://perldoc.perl.org
|
@@ -665,7 +665,10 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
|
|
665
665
|
if(ch=="`"){
|
666
666
|
return tokenChain(stream,state,[ch],"variable-2")}
|
667
667
|
if(ch=="/"){
|
668
|
-
|
668
|
+
if(!/~\s*$/.test(stream.prefix()))
|
669
|
+
return "operator";
|
670
|
+
else
|
671
|
+
return tokenChain(stream,state,[ch],RXstyle,RXmodifiers)}
|
669
672
|
if(ch=="$"){
|
670
673
|
var p=stream.pos;
|
671
674
|
if(stream.eatWhile(/\d/)||stream.eat("{")&&stream.eatWhile(/\d/)&&stream.eat("}"))
|
@@ -782,8 +785,11 @@ CodeMirror.StringStream.prototype.look=function(c){
|
|
782
785
|
|
783
786
|
// return a part of prefix of current stream from current position
|
784
787
|
CodeMirror.StringStream.prototype.prefix=function(c){
|
785
|
-
|
786
|
-
|
788
|
+
if(c){
|
789
|
+
var x=this.pos-c;
|
790
|
+
return this.string.substr((x>=0?x:0),c)}
|
791
|
+
else{
|
792
|
+
return this.string.substr(0,this.pos-1)}};
|
787
793
|
|
788
794
|
// return a part of suffix of current stream from current position
|
789
795
|
CodeMirror.StringStream.prototype.suffix=function(c){
|
@@ -0,0 +1,19 @@
|
|
1
|
+
CodeMirror.defineMode("changes", function(config, modeConfig) {
|
2
|
+
var headerSeperator = /^-+$/;
|
3
|
+
var headerLine = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?\d{1,2} \d{2}:\d{2}(:\d{2})? [A-Z]{3,4} \d{4} - /;
|
4
|
+
var simpleEmail = /^[\w+.-]+@[\w.-]+/;
|
5
|
+
|
6
|
+
return {
|
7
|
+
token: function(stream) {
|
8
|
+
if (stream.sol()) {
|
9
|
+
if (stream.match(headerSeperator)) { return 'tag'; }
|
10
|
+
if (stream.match(headerLine)) { return 'tag'; }
|
11
|
+
}
|
12
|
+
if (stream.match(simpleEmail)) { return 'string'; }
|
13
|
+
stream.next();
|
14
|
+
return null;
|
15
|
+
}
|
16
|
+
};
|
17
|
+
});
|
18
|
+
|
19
|
+
CodeMirror.defineMIME("text/x-rpm-changes", "changes");
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// Quick and dirty spec file highlighting
|
2
|
+
|
3
|
+
CodeMirror.defineMode("spec", function(config, modeConfig) {
|
4
|
+
var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
|
5
|
+
|
6
|
+
var preamble = /^(Name|Version|Release|License|Summary|Url|Group|Source|BuildArch|BuildRequires|BuildRoot|AutoReqProv|Provides|Requires(\(\w+\))?|Obsoletes|Conflicts|Recommends|Source\d*|Patch\d*|ExclusiveArch|NoSource|Supplements):/;
|
7
|
+
var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preun|postun|pre|post|triggerin|triggerun|pretrans|posttrans|verifyscript|check|triggerpostun|triggerprein|trigger)/;
|
8
|
+
var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros
|
9
|
+
var control_flow_simple = /^%(else|endif)/; // rpm control flow macros
|
10
|
+
var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros
|
11
|
+
|
12
|
+
return {
|
13
|
+
startState: function () {
|
14
|
+
return {
|
15
|
+
controlFlow: false,
|
16
|
+
macroParameters: false,
|
17
|
+
section: false,
|
18
|
+
};
|
19
|
+
},
|
20
|
+
token: function (stream, state) {
|
21
|
+
var ch = stream.peek();
|
22
|
+
if (ch == "#") { stream.skipToEnd(); return "comment"; }
|
23
|
+
|
24
|
+
if (stream.sol()) {
|
25
|
+
if (stream.match(preamble)) { return "preamble"; }
|
26
|
+
if (stream.match(section)) { return "section"; }
|
27
|
+
}
|
28
|
+
|
29
|
+
if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
|
30
|
+
if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
|
31
|
+
|
32
|
+
if (stream.match(control_flow_simple)) { return "keyword"; }
|
33
|
+
if (stream.match(control_flow_complex)) {
|
34
|
+
state.controlFlow = true;
|
35
|
+
return "keyword";
|
36
|
+
}
|
37
|
+
if (state.controlFlow) {
|
38
|
+
if (stream.match(operators)) { return "operator"; }
|
39
|
+
if (stream.match(/^(\d+)/)) { return "number"; }
|
40
|
+
if (stream.eol()) { state.controlFlow = false; }
|
41
|
+
}
|
42
|
+
|
43
|
+
if (stream.match(arch)) { return "number"; }
|
44
|
+
|
45
|
+
// Macros like '%make_install' or '%attr(0775,root,root)'
|
46
|
+
if (stream.match(/^%[\w]+/)) {
|
47
|
+
if (stream.match(/^\(/)) { state.macroParameters = true; }
|
48
|
+
return "macro";
|
49
|
+
}
|
50
|
+
if (state.macroParameters) {
|
51
|
+
if (stream.match(/^\d+/)) { return "number";}
|
52
|
+
if (stream.match(/^\)/)) {
|
53
|
+
state.macroParameters = false;
|
54
|
+
return "macro";
|
55
|
+
}
|
56
|
+
}
|
57
|
+
if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
|
58
|
+
|
59
|
+
//TODO: Include bash script sub-parser (CodeMirror supports that)
|
60
|
+
stream.next();
|
61
|
+
return null;
|
62
|
+
}
|
63
|
+
};
|
64
|
+
});
|
65
|
+
|
66
|
+
CodeMirror.defineMIME("text/x-rpm-spec", "spec");
|
@@ -8,7 +8,8 @@ CodeMirror.defineMode("rust", function() {
|
|
8
8
|
"lambda": "fn", "type": "type", "tag": "tag", "mod": "mod",
|
9
9
|
"as": "op", "true": "atom", "false": "atom", "assert": "op", "check": "op",
|
10
10
|
"claim": "op", "native": "ignore", "unsafe": "ignore", "import": "else-style",
|
11
|
-
"export": "else-style", "copy": "op", "log": "op", "log_err": "op"
|
11
|
+
"export": "else-style", "copy": "op", "log": "op", "log_err": "op",
|
12
|
+
"use": "op", "bind": "op"
|
12
13
|
};
|
13
14
|
var typeKeywords = function() {
|
14
15
|
var keywords = {"fn": "fn", "block": "fn", "obj": "obj"};
|
@@ -83,7 +84,7 @@ CodeMirror.defineMode("rust", function() {
|
|
83
84
|
return r("prefix", "variable-2");
|
84
85
|
}
|
85
86
|
if (state.keywords.propertyIsEnumerable(content))
|
86
|
-
return r(state.keywords[content], "keyword");
|
87
|
+
return r(state.keywords[content], content.match(/true|false/) ? "atom" : "keyword");
|
87
88
|
return r("name", "variable");
|
88
89
|
}
|
89
90
|
|
@@ -170,13 +171,13 @@ CodeMirror.defineMode("rust", function() {
|
|
170
171
|
|
171
172
|
function block(type) {
|
172
173
|
if (type == "}") return cont();
|
173
|
-
if (type == "let") return cont(pushlex("stat", "let"),
|
174
|
+
if (type == "let") return cont(pushlex("stat", "let"), letdef1, poplex, block);
|
174
175
|
if (type == "fn") return cont(pushlex("stat"), fndef, poplex, block);
|
175
176
|
if (type == "type") return cont(pushlex("stat"), tydef, endstatement, poplex, block);
|
176
177
|
if (type == "tag") return cont(pushlex("stat"), tagdef, poplex, block);
|
177
178
|
if (type == "mod") return cont(pushlex("stat"), mod, poplex, block);
|
178
179
|
if (type == "open-attr") return cont(pushlex("]"), commasep(expression, "]"), poplex);
|
179
|
-
if (type == "ignore") return cont(block);
|
180
|
+
if (type == "ignore" || type.match(/[\]\);,]/)) return cont(block);
|
180
181
|
return pass(pushlex("stat"), expression, poplex, endstatement, block);
|
181
182
|
}
|
182
183
|
function endstatement(type) {
|
@@ -213,15 +214,19 @@ CodeMirror.defineMode("rust", function() {
|
|
213
214
|
if (content == "||") return cont(poplex, pushlex("}", "block"), block);
|
214
215
|
}
|
215
216
|
if (content == "mutable" || (content.match(/^\w+$/) && cx.stream.peek() == ":"
|
216
|
-
&& !cx.stream.match("::", false)))
|
217
|
+
&& !cx.stream.match("::", false)))
|
218
|
+
return pass(record_of(expression));
|
217
219
|
return pass(block);
|
218
220
|
}
|
219
|
-
function
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
221
|
+
function record_of(comb) {
|
222
|
+
function ro(type) {
|
223
|
+
if (content == "mutable" || content == "with") {cx.marked = "keyword"; return cont(ro);}
|
224
|
+
if (content.match(/^\w*$/)) {cx.marked = "variable"; return cont(ro);}
|
225
|
+
if (type == ":") return cont(comb, ro);
|
226
|
+
if (type == "}") return cont();
|
227
|
+
return cont(ro);
|
228
|
+
}
|
229
|
+
return ro;
|
225
230
|
}
|
226
231
|
function blockvars(type) {
|
227
232
|
if (type == "name") {cx.marked = "def"; return cont(blockvars);}
|
@@ -229,11 +234,15 @@ CodeMirror.defineMode("rust", function() {
|
|
229
234
|
return cont(blockvars);
|
230
235
|
}
|
231
236
|
|
232
|
-
function
|
233
|
-
if (type
|
234
|
-
if (content == "=") return cont(expression,
|
235
|
-
if (type == ",") return cont(
|
236
|
-
return pass(pattern, maybetype,
|
237
|
+
function letdef1(type) {
|
238
|
+
if (type.match(/[\]\)\};]/)) return cont();
|
239
|
+
if (content == "=") return cont(expression, letdef2);
|
240
|
+
if (type == ",") return cont(letdef1);
|
241
|
+
return pass(pattern, maybetype, letdef1);
|
242
|
+
}
|
243
|
+
function letdef2(type) {
|
244
|
+
if (type.match(/[\]\)\};,]/)) return pass(letdef1);
|
245
|
+
else return pass(expression, letdef2);
|
237
246
|
}
|
238
247
|
function maybetype(type) {
|
239
248
|
if (type == ":") return cont(typecx, rtype, valcx);
|
@@ -291,6 +300,7 @@ CodeMirror.defineMode("rust", function() {
|
|
291
300
|
if (type == "atom") return cont(rtypemaybeparam);
|
292
301
|
if (type == "op" || type == "obj") return cont(rtype);
|
293
302
|
if (type == "fn") return cont(fntype);
|
303
|
+
if (type == "{") return cont(pushlex("{"), record_of(rtype), poplex);
|
294
304
|
return matchBrackets(type, rtype);
|
295
305
|
}
|
296
306
|
function rtypemaybeparam(type) {
|
@@ -306,6 +316,7 @@ CodeMirror.defineMode("rust", function() {
|
|
306
316
|
if (type == "name") {cx.marked = "def"; return cont(patternmaybeop);}
|
307
317
|
if (type == "atom") return cont(patternmaybeop);
|
308
318
|
if (type == "op") return cont(pattern);
|
319
|
+
if (type.match(/[\]\)\};,]/)) return pass();
|
309
320
|
return matchBrackets(type, pattern);
|
310
321
|
}
|
311
322
|
function patternmaybeop(type) {
|
@@ -314,16 +325,21 @@ CodeMirror.defineMode("rust", function() {
|
|
314
325
|
else return pass();
|
315
326
|
}
|
316
327
|
function altbody(type) {
|
317
|
-
if (type == "{") return cont(pushlex("}", "alt"),
|
328
|
+
if (type == "{") return cont(pushlex("}", "alt"), altblock1, poplex);
|
318
329
|
return pass();
|
319
330
|
}
|
320
|
-
function
|
331
|
+
function altblock1(type) {
|
321
332
|
if (type == "}") return cont();
|
322
|
-
if (type == "|") return cont(
|
323
|
-
if (content == "when") {cx.marked = "keyword"; return cont(expression,
|
324
|
-
if (type
|
325
|
-
return pass(pattern,
|
333
|
+
if (type == "|") return cont(altblock1);
|
334
|
+
if (content == "when") {cx.marked = "keyword"; return cont(expression, altblock2);}
|
335
|
+
if (type.match(/[\]\);,]/)) return cont(altblock1);
|
336
|
+
return pass(pattern, altblock2);
|
337
|
+
}
|
338
|
+
function altblock2(type) {
|
339
|
+
if (type == "{") return cont(pushlex("}", "alt"), block, poplex, altblock1);
|
340
|
+
else return pass(altblock1);
|
326
341
|
}
|
342
|
+
|
327
343
|
function macro(type) {
|
328
344
|
if (type.match(/[\[\(\{]/)) return matchBrackets(type, expression);
|
329
345
|
return pass();
|