Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/haskell/haskell.js
1293 views
1
CodeMirror.defineMode("haskell", function(_config, modeConfig) {
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 = /\d/;
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.match(/^\.\d+/)) {
80
t = "number";
81
}
82
if (source.eat(/[eE]/)) {
83
t = "number";
84
source.eat(/[-+]/);
85
source.eatWhile(digitRE); // should require at least 1
86
}
87
return t;
88
}
89
90
if (ch == "." && source.eat("."))
91
return "keyword";
92
93
if (symbolRE.test(ch)) {
94
if (ch == '-' && source.eat(/-/)) {
95
source.eatWhile(/-/);
96
if (!source.eat(symbolRE)) {
97
source.skipToEnd();
98
return "comment";
99
}
100
}
101
var t = "variable";
102
if (ch == ':') {
103
t = "variable-2";
104
}
105
source.eatWhile(symbolRE);
106
return t;
107
}
108
109
return "error";
110
}
111
112
function ncomment(type, nest) {
113
if (nest == 0) {
114
return normal;
115
}
116
return function(source, setState) {
117
var currNest = nest;
118
while (!source.eol()) {
119
var ch = source.next();
120
if (ch == '{' && source.eat('-')) {
121
++currNest;
122
}
123
else if (ch == '-' && source.eat('}')) {
124
--currNest;
125
if (currNest == 0) {
126
setState(normal);
127
return type;
128
}
129
}
130
}
131
setState(ncomment(type, currNest));
132
return type;
133
};
134
}
135
136
function stringLiteral(source, setState) {
137
while (!source.eol()) {
138
var ch = source.next();
139
if (ch == '"') {
140
setState(normal);
141
return "string";
142
}
143
if (ch == '\\') {
144
if (source.eol() || source.eat(whiteCharRE)) {
145
setState(stringGap);
146
return "string";
147
}
148
if (source.eat('&')) {
149
}
150
else {
151
source.next(); // should handle other escapes here
152
}
153
}
154
}
155
setState(normal);
156
return "error";
157
}
158
159
function stringGap(source, setState) {
160
if (source.eat('\\')) {
161
return switchState(source, setState, stringLiteral);
162
}
163
source.next();
164
setState(normal);
165
return "error";
166
}
167
168
169
var wellKnownWords = (function() {
170
var wkw = {};
171
function setType(t) {
172
return function () {
173
for (var i = 0; i < arguments.length; i++)
174
wkw[arguments[i]] = t;
175
};
176
}
177
178
setType("keyword")(
179
"case", "class", "data", "default", "deriving", "do", "else", "foreign",
180
"if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
181
"module", "newtype", "of", "then", "type", "where", "_");
182
183
setType("keyword")(
184
"\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
185
186
setType("builtin")(
187
"!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
188
"==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
189
190
setType("builtin")(
191
"Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
192
"False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
193
"IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
194
"Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
195
"ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
196
"String", "True");
197
198
setType("builtin")(
199
"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
200
"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
201
"compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
202
"cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
203
"elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
204
"enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
205
"flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
206
"foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
207
"fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
208
"getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
209
"isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
210
"lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
211
"mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
212
"minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
213
"otherwise", "pi", "pred", "print", "product", "properFraction",
214
"putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
215
"readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
216
"realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
217
"round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
218
"sequence", "sequence_", "show", "showChar", "showList", "showParen",
219
"showString", "shows", "showsPrec", "significand", "signum", "sin",
220
"sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
221
"tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
222
"toRational", "truncate", "uncurry", "undefined", "unlines", "until",
223
"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
224
"zip3", "zipWith", "zipWith3");
225
226
var override = modeConfig.overrideKeywords;
227
if (override) for (var word in override) if (override.hasOwnProperty(word))
228
wkw[word] = override[word];
229
230
return wkw;
231
})();
232
233
234
235
return {
236
startState: function () { return { f: normal }; },
237
copyState: function (s) { return { f: s.f }; },
238
239
token: function(stream, state) {
240
var t = state.f(stream, function(s) { state.f = s; });
241
var w = stream.current();
242
return wellKnownWords.hasOwnProperty(w) ? wellKnownWords[w] : t;
243
},
244
245
blockCommentStart: "{-",
246
blockCommentEnd: "-}",
247
lineComment: "--"
248
};
249
250
});
251
252
CodeMirror.defineMIME("text/x-haskell", "haskell");
253
254