Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
(function(mod) {
5
if (typeof exports == "object" && typeof module == "object") // CommonJS
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd) // AMD
8
define(["../../lib/codemirror"], mod);
9
else // Plain browser env
10
mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
14
CodeMirror.defineMode("dylan", function(_config) {
15
// Words
16
var words = {
17
// Words that introduce unnamed definitions like "define interface"
18
unnamedDefinition: ["interface"],
19
20
// Words that introduce simple named definitions like "define library"
21
namedDefinition: ["module", "library", "macro",
22
"C-struct", "C-union",
23
"C-function", "C-callable-wrapper"
24
],
25
26
// Words that introduce type definitions like "define class".
27
// These are also parameterized like "define method" and are
28
// appended to otherParameterizedDefinitionWords
29
typeParameterizedDefinition: ["class", "C-subtype", "C-mapped-subtype"],
30
31
// Words that introduce trickier definitions like "define method".
32
// These require special definitions to be added to startExpressions
33
otherParameterizedDefinition: ["method", "function",
34
"C-variable", "C-address"
35
],
36
37
// Words that introduce module constant definitions.
38
// These must also be simple definitions and are
39
// appended to otherSimpleDefinitionWords
40
constantSimpleDefinition: ["constant"],
41
42
// Words that introduce module variable definitions.
43
// These must also be simple definitions and are
44
// appended to otherSimpleDefinitionWords
45
variableSimpleDefinition: ["variable"],
46
47
// Other words that introduce simple definitions
48
// (without implicit bodies).
49
otherSimpleDefinition: ["generic", "domain",
50
"C-pointer-type",
51
"table"
52
],
53
54
// Words that begin statements with implicit bodies.
55
statement: ["if", "block", "begin", "method", "case",
56
"for", "select", "when", "unless", "until",
57
"while", "iterate", "profiling", "dynamic-bind"
58
],
59
60
// Patterns that act as separators in compound statements.
61
// This may include any general pattern that must be indented
62
// specially.
63
separator: ["finally", "exception", "cleanup", "else",
64
"elseif", "afterwards"
65
],
66
67
// Keywords that do not require special indentation handling,
68
// but which should be highlighted
69
other: ["above", "below", "by", "from", "handler", "in",
70
"instance", "let", "local", "otherwise", "slot",
71
"subclass", "then", "to", "keyed-by", "virtual"
72
],
73
74
// Condition signaling function calls
75
signalingCalls: ["signal", "error", "cerror",
76
"break", "check-type", "abort"
77
]
78
};
79
80
words["otherDefinition"] =
81
words["unnamedDefinition"]
82
.concat(words["namedDefinition"])
83
.concat(words["otherParameterizedDefinition"]);
84
85
words["definition"] =
86
words["typeParameterizedDefinition"]
87
.concat(words["otherDefinition"]);
88
89
words["parameterizedDefinition"] =
90
words["typeParameterizedDefinition"]
91
.concat(words["otherParameterizedDefinition"]);
92
93
words["simpleDefinition"] =
94
words["constantSimpleDefinition"]
95
.concat(words["variableSimpleDefinition"])
96
.concat(words["otherSimpleDefinition"]);
97
98
words["keyword"] =
99
words["statement"]
100
.concat(words["separator"])
101
.concat(words["other"]);
102
103
// Patterns
104
var symbolPattern = "[-_a-zA-Z?!*@<>$%]+";
105
var symbol = new RegExp("^" + symbolPattern);
106
var patterns = {
107
// Symbols with special syntax
108
symbolKeyword: symbolPattern + ":",
109
symbolClass: "<" + symbolPattern + ">",
110
symbolGlobal: "\\*" + symbolPattern + "\\*",
111
symbolConstant: "\\$" + symbolPattern
112
};
113
var patternStyles = {
114
symbolKeyword: "atom",
115
symbolClass: "tag",
116
symbolGlobal: "variable-2",
117
symbolConstant: "variable-3"
118
};
119
120
// Compile all patterns to regular expressions
121
for (var patternName in patterns)
122
if (patterns.hasOwnProperty(patternName))
123
patterns[patternName] = new RegExp("^" + patterns[patternName]);
124
125
// Names beginning "with-" and "without-" are commonly
126
// used as statement macro
127
patterns["keyword"] = [/^with(?:out)?-[-_a-zA-Z?!*@<>$%]+/];
128
129
var styles = {};
130
styles["keyword"] = "keyword";
131
styles["definition"] = "def";
132
styles["simpleDefinition"] = "def";
133
styles["signalingCalls"] = "builtin";
134
135
// protected words lookup table
136
var wordLookup = {};
137
var styleLookup = {};
138
139
[
140
"keyword",
141
"definition",
142
"simpleDefinition",
143
"signalingCalls"
144
].forEach(function(type) {
145
words[type].forEach(function(word) {
146
wordLookup[word] = type;
147
styleLookup[word] = styles[type];
148
});
149
});
150
151
152
function chain(stream, state, f) {
153
state.tokenize = f;
154
return f(stream, state);
155
}
156
157
var type, content;
158
159
function ret(_type, style, _content) {
160
type = _type;
161
content = _content;
162
return style;
163
}
164
165
function tokenBase(stream, state) {
166
// String
167
var ch = stream.peek();
168
if (ch == "'" || ch == '"') {
169
stream.next();
170
return chain(stream, state, tokenString(ch, "string", "string"));
171
}
172
// Comment
173
else if (ch == "/") {
174
stream.next();
175
if (stream.eat("*")) {
176
return chain(stream, state, tokenComment);
177
} else if (stream.eat("/")) {
178
stream.skipToEnd();
179
return ret("comment", "comment");
180
} else {
181
stream.skipTo(" ");
182
return ret("operator", "operator");
183
}
184
}
185
// Decimal
186
else if (/\d/.test(ch)) {
187
stream.match(/^\d*(?:\.\d*)?(?:e[+\-]?\d+)?/);
188
return ret("number", "number");
189
}
190
// Hash
191
else if (ch == "#") {
192
stream.next();
193
// Symbol with string syntax
194
ch = stream.peek();
195
if (ch == '"') {
196
stream.next();
197
return chain(stream, state, tokenString('"', "symbol", "string-2"));
198
}
199
// Binary number
200
else if (ch == "b") {
201
stream.next();
202
stream.eatWhile(/[01]/);
203
return ret("number", "number");
204
}
205
// Hex number
206
else if (ch == "x") {
207
stream.next();
208
stream.eatWhile(/[\da-f]/i);
209
return ret("number", "number");
210
}
211
// Octal number
212
else if (ch == "o") {
213
stream.next();
214
stream.eatWhile(/[0-7]/);
215
return ret("number", "number");
216
}
217
// Hash symbol
218
else {
219
stream.eatWhile(/[-a-zA-Z]/);
220
return ret("hash", "keyword");
221
}
222
} else if (stream.match("end")) {
223
return ret("end", "keyword");
224
}
225
for (var name in patterns) {
226
if (patterns.hasOwnProperty(name)) {
227
var pattern = patterns[name];
228
if ((pattern instanceof Array && pattern.some(function(p) {
229
return stream.match(p);
230
})) || stream.match(pattern))
231
return ret(name, patternStyles[name], stream.current());
232
}
233
}
234
if (stream.match("define")) {
235
return ret("definition", "def");
236
} else {
237
stream.eatWhile(/[\w\-]/);
238
// Keyword
239
if (wordLookup[stream.current()]) {
240
return ret(wordLookup[stream.current()], styleLookup[stream.current()], stream.current());
241
} else if (stream.current().match(symbol)) {
242
return ret("variable", "variable");
243
} else {
244
stream.next();
245
return ret("other", "variable-2");
246
}
247
}
248
}
249
250
function tokenComment(stream, state) {
251
var maybeEnd = false,
252
ch;
253
while ((ch = stream.next())) {
254
if (ch == "/" && maybeEnd) {
255
state.tokenize = tokenBase;
256
break;
257
}
258
maybeEnd = (ch == "*");
259
}
260
return ret("comment", "comment");
261
}
262
263
function tokenString(quote, type, style) {
264
return function(stream, state) {
265
var next, end = false;
266
while ((next = stream.next()) != null) {
267
if (next == quote) {
268
end = true;
269
break;
270
}
271
}
272
if (end)
273
state.tokenize = tokenBase;
274
return ret(type, style);
275
};
276
}
277
278
// Interface
279
return {
280
startState: function() {
281
return {
282
tokenize: tokenBase,
283
currentIndent: 0
284
};
285
},
286
token: function(stream, state) {
287
if (stream.eatSpace())
288
return null;
289
var style = state.tokenize(stream, state);
290
return style;
291
},
292
blockCommentStart: "/*",
293
blockCommentEnd: "*/"
294
};
295
});
296
297
CodeMirror.defineMIME("text/x-dylan", "dylan");
298
299
});
300
301