codemirror-rails 0.1.1 → 0.1.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/codemirror-rails-0.0.0.gem +0 -0
- data/codemirror-rails-0.1.gem +0 -0
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror.js +122 -63
- data/vendor/assets/javascripts/codemirror/modes/clike.js +221 -0
- data/vendor/assets/javascripts/codemirror/modes/css.js +124 -0
- data/vendor/assets/javascripts/codemirror/modes/diff.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/haskell.js +242 -0
- data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +79 -0
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +348 -0
- data/vendor/assets/javascripts/codemirror/modes/lua.js +138 -0
- data/vendor/assets/javascripts/codemirror/modes/php.js +111 -0
- data/vendor/assets/javascripts/codemirror/modes/plsql.js +217 -0
- data/vendor/assets/javascripts/codemirror/modes/python.js +321 -0
- data/vendor/assets/javascripts/codemirror/modes/rst.js +333 -0
- data/vendor/assets/javascripts/codemirror/modes/scheme.js +181 -0
- data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +122 -0
- data/vendor/assets/javascripts/codemirror/modes/stex.js +167 -0
- data/vendor/assets/javascripts/codemirror/modes/xml.js +227 -0
- data/vendor/assets/javascripts/codemirror/modes/yaml.js +95 -0
- data/vendor/assets/javascripts/codemirror/overlay.js +51 -0
- data/vendor/assets/javascripts/codemirror/runmode.js +27 -0
- data/vendor/assets/stylesheets/codemirror.css +3 -0
- data/vendor/assets/stylesheets/codemirror/modes/clike.css +7 -0
- data/vendor/assets/stylesheets/codemirror/modes/diff.css +3 -0
- data/vendor/assets/stylesheets/codemirror/modes/rst.css +75 -0
- metadata +25 -3
- data/codemirror-rails-0.1.1.gem +0 -0
@@ -0,0 +1,221 @@
|
|
1
|
+
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
2
|
+
var indentUnit = config.indentUnit,
|
3
|
+
keywords = parserConfig.keywords || {},
|
4
|
+
atoms = parserConfig.atoms || {},
|
5
|
+
hooks = parserConfig.hooks || {},
|
6
|
+
multiLineStrings = parserConfig.multiLineStrings;
|
7
|
+
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
8
|
+
|
9
|
+
var curPunc;
|
10
|
+
|
11
|
+
function tokenBase(stream, state) {
|
12
|
+
var ch = stream.next();
|
13
|
+
if (hooks[ch]) {
|
14
|
+
var result = hooks[ch](stream, state);
|
15
|
+
if (result !== false) return result;
|
16
|
+
}
|
17
|
+
if (ch == '"' || ch == "'") {
|
18
|
+
state.tokenize = tokenString(ch);
|
19
|
+
return state.tokenize(stream, state);
|
20
|
+
}
|
21
|
+
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
22
|
+
curPunc = ch;
|
23
|
+
return null
|
24
|
+
}
|
25
|
+
if (/\d/.test(ch)) {
|
26
|
+
stream.eatWhile(/[\w\.]/);
|
27
|
+
return "number";
|
28
|
+
}
|
29
|
+
if (ch == "/") {
|
30
|
+
if (stream.eat("*")) {
|
31
|
+
state.tokenize = tokenComment;
|
32
|
+
return tokenComment(stream, state);
|
33
|
+
}
|
34
|
+
if (stream.eat("/")) {
|
35
|
+
stream.skipToEnd();
|
36
|
+
return "comment";
|
37
|
+
}
|
38
|
+
}
|
39
|
+
if (isOperatorChar.test(ch)) {
|
40
|
+
stream.eatWhile(isOperatorChar);
|
41
|
+
return "operator";
|
42
|
+
}
|
43
|
+
stream.eatWhile(/[\w\$_]/);
|
44
|
+
var cur = stream.current();
|
45
|
+
if (keywords.propertyIsEnumerable(cur)) return "keyword";
|
46
|
+
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
47
|
+
return "word";
|
48
|
+
}
|
49
|
+
|
50
|
+
function tokenString(quote) {
|
51
|
+
return function(stream, state) {
|
52
|
+
var escaped = false, next, end = false;
|
53
|
+
while ((next = stream.next()) != null) {
|
54
|
+
if (next == quote && !escaped) {end = true; break;}
|
55
|
+
escaped = !escaped && next == "\\";
|
56
|
+
}
|
57
|
+
if (end || !(escaped || multiLineStrings))
|
58
|
+
state.tokenize = tokenBase;
|
59
|
+
return "string";
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
function tokenComment(stream, state) {
|
64
|
+
var maybeEnd = false, ch;
|
65
|
+
while (ch = stream.next()) {
|
66
|
+
if (ch == "/" && maybeEnd) {
|
67
|
+
state.tokenize = tokenBase;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
maybeEnd = (ch == "*");
|
71
|
+
}
|
72
|
+
return "comment";
|
73
|
+
}
|
74
|
+
|
75
|
+
function Context(indented, column, type, align, prev) {
|
76
|
+
this.indented = indented;
|
77
|
+
this.column = column;
|
78
|
+
this.type = type;
|
79
|
+
this.align = align;
|
80
|
+
this.prev = prev;
|
81
|
+
}
|
82
|
+
|
83
|
+
function pushContext(state, col, type) {
|
84
|
+
return state.context = new Context(state.indented, col, type, null, state.context);
|
85
|
+
}
|
86
|
+
function popContext(state) {
|
87
|
+
return state.context = state.context.prev;
|
88
|
+
}
|
89
|
+
|
90
|
+
// Interface
|
91
|
+
|
92
|
+
return {
|
93
|
+
startState: function(basecolumn) {
|
94
|
+
return {
|
95
|
+
tokenize: null,
|
96
|
+
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
97
|
+
indented: 0,
|
98
|
+
startOfLine: true
|
99
|
+
};
|
100
|
+
},
|
101
|
+
|
102
|
+
token: function(stream, state) {
|
103
|
+
var ctx = state.context;
|
104
|
+
if (stream.sol()) {
|
105
|
+
if (ctx.align == null) ctx.align = false;
|
106
|
+
state.indented = stream.indentation();
|
107
|
+
state.startOfLine = true;
|
108
|
+
}
|
109
|
+
if (stream.eatSpace()) return null;
|
110
|
+
curPunc = null;
|
111
|
+
var style = (state.tokenize || tokenBase)(stream, state);
|
112
|
+
if (style == "comment") return style;
|
113
|
+
if (ctx.align == null) ctx.align = true;
|
114
|
+
|
115
|
+
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
116
|
+
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
117
|
+
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
118
|
+
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
119
|
+
else if (curPunc == "}") {
|
120
|
+
if (ctx.type == "statement") ctx = popContext(state);
|
121
|
+
if (ctx.type == "}") ctx = popContext(state);
|
122
|
+
if (ctx.type == "statement") ctx = popContext(state);
|
123
|
+
}
|
124
|
+
else if (curPunc == ctx.type) popContext(state);
|
125
|
+
else if (ctx.type == "}" || ctx.type == "top") pushContext(state, stream.column(), "statement");
|
126
|
+
state.startOfLine = false;
|
127
|
+
return style;
|
128
|
+
},
|
129
|
+
|
130
|
+
indent: function(state, textAfter) {
|
131
|
+
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
132
|
+
var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
|
133
|
+
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
|
134
|
+
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
135
|
+
else return ctx.indented + (closing ? 0 : indentUnit);
|
136
|
+
},
|
137
|
+
|
138
|
+
electricChars: "{}"
|
139
|
+
};
|
140
|
+
});
|
141
|
+
|
142
|
+
(function() {
|
143
|
+
function words(str) {
|
144
|
+
var obj = {}, words = str.split(" ");
|
145
|
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
146
|
+
return obj;
|
147
|
+
}
|
148
|
+
var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
|
149
|
+
"double static else struct entry switch extern typedef float union for unsigned " +
|
150
|
+
"goto while enum void const signed volatile";
|
151
|
+
|
152
|
+
function cppHook(stream, state) {
|
153
|
+
if (!state.startOfLine) return false;
|
154
|
+
stream.skipToEnd();
|
155
|
+
return "meta";
|
156
|
+
}
|
157
|
+
|
158
|
+
// C#-style strings where "" escapes a quote.
|
159
|
+
function tokenAtString(stream, state) {
|
160
|
+
var next;
|
161
|
+
while ((next = stream.next()) != null) {
|
162
|
+
if (next == '"' && !stream.eat('"')) {
|
163
|
+
state.tokenize = null;
|
164
|
+
break;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
return "string";
|
168
|
+
}
|
169
|
+
|
170
|
+
CodeMirror.defineMIME("text/x-csrc", {
|
171
|
+
name: "clike",
|
172
|
+
keywords: words(cKeywords),
|
173
|
+
atoms: words("null"),
|
174
|
+
hooks: {"#": cppHook}
|
175
|
+
});
|
176
|
+
CodeMirror.defineMIME("text/x-c++src", {
|
177
|
+
name: "clike",
|
178
|
+
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
|
179
|
+
"static_cast typeid catch operator template typename class friend private " +
|
180
|
+
"this using const_cast inline public throw virtual delete mutable protected " +
|
181
|
+
"wchar_t"),
|
182
|
+
atoms: words("true false null"),
|
183
|
+
hooks: {"#": cppHook}
|
184
|
+
});
|
185
|
+
CodeMirror.defineMIME("text/x-java", {
|
186
|
+
name: "clike",
|
187
|
+
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
188
|
+
"do double else enum extends final finally float for goto if implements import " +
|
189
|
+
"instanceof int interface long native new package private protected public " +
|
190
|
+
"return short static strictfp super switch synchronized this throw throws transient " +
|
191
|
+
"try void volatile while"),
|
192
|
+
atoms: words("true false null"),
|
193
|
+
hooks: {
|
194
|
+
"@": function(stream, state) {
|
195
|
+
stream.eatWhile(/[\w\$_]/);
|
196
|
+
return "meta";
|
197
|
+
}
|
198
|
+
}
|
199
|
+
});
|
200
|
+
CodeMirror.defineMIME("text/x-csharp", {
|
201
|
+
name: "clike",
|
202
|
+
keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
|
203
|
+
" default delegate do double else enum event explicit extern finally fixed float for" +
|
204
|
+
" foreach goto if implicit in int interface internal is lock long namespace new object" +
|
205
|
+
" operator out override params private protected public readonly ref return sbyte sealed short" +
|
206
|
+
" sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" +
|
207
|
+
" unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" +
|
208
|
+
" global group into join let orderby partial remove select set value var yield"),
|
209
|
+
atoms: words("true false null"),
|
210
|
+
hooks: {
|
211
|
+
"@": function(stream, state) {
|
212
|
+
if (stream.eat('"')) {
|
213
|
+
state.tokenize = tokenAtString;
|
214
|
+
return tokenAtString(stream, state);
|
215
|
+
}
|
216
|
+
stream.eatWhile(/[\w\$_]/);
|
217
|
+
return "meta";
|
218
|
+
}
|
219
|
+
}
|
220
|
+
});
|
221
|
+
}());
|
@@ -0,0 +1,124 @@
|
|
1
|
+
CodeMirror.defineMode("css", function(config) {
|
2
|
+
var indentUnit = config.indentUnit, type;
|
3
|
+
function ret(style, tp) {type = tp; return style;}
|
4
|
+
|
5
|
+
function tokenBase(stream, state) {
|
6
|
+
var ch = stream.next();
|
7
|
+
if (ch == "@") {stream.eatWhile(/\w/); return ret("meta", stream.current());}
|
8
|
+
else if (ch == "/" && stream.eat("*")) {
|
9
|
+
state.tokenize = tokenCComment;
|
10
|
+
return tokenCComment(stream, state);
|
11
|
+
}
|
12
|
+
else if (ch == "<" && stream.eat("!")) {
|
13
|
+
state.tokenize = tokenSGMLComment;
|
14
|
+
return tokenSGMLComment(stream, state);
|
15
|
+
}
|
16
|
+
else if (ch == "=") ret(null, "compare");
|
17
|
+
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
18
|
+
else if (ch == "\"" || ch == "'") {
|
19
|
+
state.tokenize = tokenString(ch);
|
20
|
+
return state.tokenize(stream, state);
|
21
|
+
}
|
22
|
+
else if (ch == "#") {
|
23
|
+
stream.eatWhile(/\w/);
|
24
|
+
return ret("atom", "hash");
|
25
|
+
}
|
26
|
+
else if (ch == "!") {
|
27
|
+
stream.match(/^\s*\w*/);
|
28
|
+
return ret("keyword", "important");
|
29
|
+
}
|
30
|
+
else if (/\d/.test(ch)) {
|
31
|
+
stream.eatWhile(/[\w.%]/);
|
32
|
+
return ret("number", "unit");
|
33
|
+
}
|
34
|
+
else if (/[,.+>*\/]/.test(ch)) {
|
35
|
+
return ret(null, "select-op");
|
36
|
+
}
|
37
|
+
else if (/[;{}:\[\]]/.test(ch)) {
|
38
|
+
return ret(null, ch);
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
stream.eatWhile(/[\w\\\-_]/);
|
42
|
+
return ret("variable", "variable");
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
function tokenCComment(stream, state) {
|
47
|
+
var maybeEnd = false, ch;
|
48
|
+
while ((ch = stream.next()) != null) {
|
49
|
+
if (maybeEnd && ch == "/") {
|
50
|
+
state.tokenize = tokenBase;
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
maybeEnd = (ch == "*");
|
54
|
+
}
|
55
|
+
return ret("comment", "comment");
|
56
|
+
}
|
57
|
+
|
58
|
+
function tokenSGMLComment(stream, state) {
|
59
|
+
var dashes = 0, ch;
|
60
|
+
while ((ch = stream.next()) != null) {
|
61
|
+
if (dashes >= 2 && ch == ">") {
|
62
|
+
state.tokenize = tokenBase;
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
dashes = (ch == "-") ? dashes + 1 : 0;
|
66
|
+
}
|
67
|
+
return ret("comment", "comment");
|
68
|
+
}
|
69
|
+
|
70
|
+
function tokenString(quote) {
|
71
|
+
return function(stream, state) {
|
72
|
+
var escaped = false, ch;
|
73
|
+
while ((ch = stream.next()) != null) {
|
74
|
+
if (ch == quote && !escaped)
|
75
|
+
break;
|
76
|
+
escaped = !escaped && ch == "\\";
|
77
|
+
}
|
78
|
+
if (!escaped) state.tokenize = tokenBase;
|
79
|
+
return ret("string", "string");
|
80
|
+
};
|
81
|
+
}
|
82
|
+
|
83
|
+
return {
|
84
|
+
startState: function(base) {
|
85
|
+
return {tokenize: tokenBase,
|
86
|
+
baseIndent: base || 0,
|
87
|
+
stack: []};
|
88
|
+
},
|
89
|
+
|
90
|
+
token: function(stream, state) {
|
91
|
+
if (stream.eatSpace()) return null;
|
92
|
+
var style = state.tokenize(stream, state);
|
93
|
+
|
94
|
+
var context = state.stack[state.stack.length-1];
|
95
|
+
if (type == "hash" && context == "rule") style = "atom";
|
96
|
+
else if (style == "variable") {
|
97
|
+
if (context == "rule") style = "number";
|
98
|
+
else if (!context || context == "@media{") style = "tag";
|
99
|
+
}
|
100
|
+
|
101
|
+
if (context == "rule" && /^[\{\};]$/.test(type))
|
102
|
+
state.stack.pop();
|
103
|
+
if (type == "{") {
|
104
|
+
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
|
105
|
+
else state.stack.push("{");
|
106
|
+
}
|
107
|
+
else if (type == "}") state.stack.pop();
|
108
|
+
else if (type == "@media") state.stack.push("@media");
|
109
|
+
else if (context == "{" && type != "comment") state.stack.push("rule");
|
110
|
+
return style;
|
111
|
+
},
|
112
|
+
|
113
|
+
indent: function(state, textAfter) {
|
114
|
+
var n = state.stack.length;
|
115
|
+
if (/^\}/.test(textAfter))
|
116
|
+
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
|
117
|
+
return state.baseIndent + n * indentUnit;
|
118
|
+
},
|
119
|
+
|
120
|
+
electricChars: "}"
|
121
|
+
};
|
122
|
+
});
|
123
|
+
|
124
|
+
CodeMirror.defineMIME("text/css", "css");
|
@@ -0,0 +1,13 @@
|
|
1
|
+
CodeMirror.defineMode("diff", function() {
|
2
|
+
return {
|
3
|
+
token: function(stream) {
|
4
|
+
var ch = stream.next();
|
5
|
+
stream.skipToEnd();
|
6
|
+
if (ch == "+") return "plus";
|
7
|
+
if (ch == "-") return "minus";
|
8
|
+
if (ch == "@") return "rangeinfo";
|
9
|
+
}
|
10
|
+
};
|
11
|
+
});
|
12
|
+
|
13
|
+
CodeMirror.defineMIME("text/x-diff", "diff");
|
@@ -0,0 +1,242 @@
|
|
1
|
+
CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
|
2
|
+
|
3
|
+
function switchState(source, setState, f) {
|
4
|
+
setState(f);
|
5
|
+
return f(source, setState);
|
6
|
+
}
|
7
|
+
|
8
|
+
// These should all be Unicode extended, as per the Haskell 2010 report
|
9
|
+
var smallRE = /[a-z_]/;
|
10
|
+
var largeRE = /[A-Z]/;
|
11
|
+
var digitRE = /[0-9]/;
|
12
|
+
var hexitRE = /[0-9A-Fa-f]/;
|
13
|
+
var octitRE = /[0-7]/;
|
14
|
+
var idRE = /[a-z_A-Z0-9']/;
|
15
|
+
var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
|
16
|
+
var specialRE = /[(),;[\]`{}]/;
|
17
|
+
var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer
|
18
|
+
|
19
|
+
function normal(source, setState) {
|
20
|
+
if (source.eatWhile(whiteCharRE)) {
|
21
|
+
return null;
|
22
|
+
}
|
23
|
+
|
24
|
+
var ch = source.next();
|
25
|
+
if (specialRE.test(ch)) {
|
26
|
+
if (ch == '{' && source.eat('-')) {
|
27
|
+
var t = "comment";
|
28
|
+
if (source.eat('#')) {
|
29
|
+
t = "meta";
|
30
|
+
}
|
31
|
+
return switchState(source, setState, ncomment(t, 1));
|
32
|
+
}
|
33
|
+
return null;
|
34
|
+
}
|
35
|
+
|
36
|
+
if (ch == '\'') {
|
37
|
+
if (source.eat('\\')) {
|
38
|
+
source.next(); // should handle other escapes here
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
source.next();
|
42
|
+
}
|
43
|
+
if (source.eat('\'')) {
|
44
|
+
return "string";
|
45
|
+
}
|
46
|
+
return "error";
|
47
|
+
}
|
48
|
+
|
49
|
+
if (ch == '"') {
|
50
|
+
return switchState(source, setState, stringLiteral);
|
51
|
+
}
|
52
|
+
|
53
|
+
if (largeRE.test(ch)) {
|
54
|
+
source.eatWhile(idRE);
|
55
|
+
if (source.eat('.')) {
|
56
|
+
return "qualifier";
|
57
|
+
}
|
58
|
+
return "variable-2";
|
59
|
+
}
|
60
|
+
|
61
|
+
if (smallRE.test(ch)) {
|
62
|
+
source.eatWhile(idRE);
|
63
|
+
return "variable";
|
64
|
+
}
|
65
|
+
|
66
|
+
if (digitRE.test(ch)) {
|
67
|
+
if (ch == '0') {
|
68
|
+
if (source.eat(/[xX]/)) {
|
69
|
+
source.eatWhile(hexitRE); // should require at least 1
|
70
|
+
return "integer";
|
71
|
+
}
|
72
|
+
if (source.eat(/[oO]/)) {
|
73
|
+
source.eatWhile(octitRE); // should require at least 1
|
74
|
+
return "number";
|
75
|
+
}
|
76
|
+
}
|
77
|
+
source.eatWhile(digitRE);
|
78
|
+
var t = "number";
|
79
|
+
if (source.eat('.')) {
|
80
|
+
t = "number";
|
81
|
+
source.eatWhile(digitRE); // should require at least 1
|
82
|
+
}
|
83
|
+
if (source.eat(/[eE]/)) {
|
84
|
+
t = "number";
|
85
|
+
source.eat(/[-+]/);
|
86
|
+
source.eatWhile(digitRE); // should require at least 1
|
87
|
+
}
|
88
|
+
return t;
|
89
|
+
}
|
90
|
+
|
91
|
+
if (symbolRE.test(ch)) {
|
92
|
+
if (ch == '-' && source.eat(/-/)) {
|
93
|
+
source.eatWhile(/-/);
|
94
|
+
if (!source.eat(symbolRE)) {
|
95
|
+
source.skipToEnd();
|
96
|
+
return "comment";
|
97
|
+
}
|
98
|
+
}
|
99
|
+
var t = "variable";
|
100
|
+
if (ch == ':') {
|
101
|
+
t = "variable-2";
|
102
|
+
}
|
103
|
+
source.eatWhile(symbolRE);
|
104
|
+
return t;
|
105
|
+
}
|
106
|
+
|
107
|
+
return "error";
|
108
|
+
}
|
109
|
+
|
110
|
+
function ncomment(type, nest) {
|
111
|
+
if (nest == 0) {
|
112
|
+
return normal;
|
113
|
+
}
|
114
|
+
return function(source, setState) {
|
115
|
+
var currNest = nest;
|
116
|
+
while (!source.eol()) {
|
117
|
+
var ch = source.next();
|
118
|
+
if (ch == '{' && source.eat('-')) {
|
119
|
+
++currNest;
|
120
|
+
}
|
121
|
+
else if (ch == '-' && source.eat('}')) {
|
122
|
+
--currNest;
|
123
|
+
if (currNest == 0) {
|
124
|
+
setState(normal);
|
125
|
+
return type;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
setState(ncomment(type, currNest));
|
130
|
+
return type;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
function stringLiteral(source, setState) {
|
135
|
+
while (!source.eol()) {
|
136
|
+
var ch = source.next();
|
137
|
+
if (ch == '"') {
|
138
|
+
setState(normal);
|
139
|
+
return "string";
|
140
|
+
}
|
141
|
+
if (ch == '\\') {
|
142
|
+
if (source.eol() || source.eat(whiteCharRE)) {
|
143
|
+
setState(stringGap);
|
144
|
+
return "string";
|
145
|
+
}
|
146
|
+
if (source.eat('&')) {
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
source.next(); // should handle other escapes here
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
setState(normal);
|
154
|
+
return "error";
|
155
|
+
}
|
156
|
+
|
157
|
+
function stringGap(source, setState) {
|
158
|
+
if (source.eat('\\')) {
|
159
|
+
return switchState(source, setState, stringLiteral);
|
160
|
+
}
|
161
|
+
source.next();
|
162
|
+
setState(normal);
|
163
|
+
return "error";
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
var wellKnownWords = (function() {
|
168
|
+
var wkw = {};
|
169
|
+
function setType(t) {
|
170
|
+
return function () {
|
171
|
+
for (var i = 0; i < arguments.length; i++)
|
172
|
+
wkw[arguments[i]] = t;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
setType("keyword")(
|
177
|
+
"case", "class", "data", "default", "deriving", "do", "else", "foreign",
|
178
|
+
"if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
|
179
|
+
"module", "newtype", "of", "then", "type", "where", "_");
|
180
|
+
|
181
|
+
setType("keyword")(
|
182
|
+
"\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
|
183
|
+
|
184
|
+
setType("builtin")(
|
185
|
+
"!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
|
186
|
+
"==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
|
187
|
+
|
188
|
+
setType("builtin")(
|
189
|
+
"Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
|
190
|
+
"False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
|
191
|
+
"IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
|
192
|
+
"Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
|
193
|
+
"ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
|
194
|
+
"String", "True");
|
195
|
+
|
196
|
+
setType("builtin")(
|
197
|
+
"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
|
198
|
+
"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
|
199
|
+
"compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
|
200
|
+
"cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
|
201
|
+
"elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
|
202
|
+
"enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
|
203
|
+
"flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
|
204
|
+
"foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
|
205
|
+
"fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
|
206
|
+
"getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
|
207
|
+
"isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
|
208
|
+
"lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
|
209
|
+
"mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
|
210
|
+
"minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
|
211
|
+
"otherwise", "pi", "pred", "print", "product", "properFraction",
|
212
|
+
"putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
|
213
|
+
"readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
|
214
|
+
"realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
|
215
|
+
"round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
|
216
|
+
"sequence", "sequence_", "show", "showChar", "showList", "showParen",
|
217
|
+
"showString", "shows", "showsPrec", "significand", "signum", "sin",
|
218
|
+
"sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
|
219
|
+
"tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
|
220
|
+
"toRational", "truncate", "uncurry", "undefined", "unlines", "until",
|
221
|
+
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
|
222
|
+
"zip3", "zipWith", "zipWith3");
|
223
|
+
|
224
|
+
return wkw;
|
225
|
+
})();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
return {
|
230
|
+
startState: function () { return { f: normal }; },
|
231
|
+
copyState: function (s) { return { f: s.f }; },
|
232
|
+
|
233
|
+
token: function(stream, state) {
|
234
|
+
var t = state.f(stream, function(s) { state.f = s; });
|
235
|
+
var w = stream.current();
|
236
|
+
return (w in wellKnownWords) ? wellKnownWords[w] : t;
|
237
|
+
}
|
238
|
+
};
|
239
|
+
|
240
|
+
});
|
241
|
+
|
242
|
+
CodeMirror.defineMIME("text/x-haskell", "haskell");
|