5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
function forEach(arr, f) {
15
for (var i = 0; i < arr.length; i++) f(arr[i], i)
17
function some(arr, f) {
18
for (var i = 0; i < arr.length; i++) if (f(arr[i], i)) return true
22
CodeMirror.defineMode("dylan", function(_config) {
26
unnamedDefinition: ["interface"],
29
namedDefinition: ["module", "library", "macro",
30
"C-struct", "C-union",
31
"C-function", "C-callable-wrapper"
37
typeParameterizedDefinition: ["class", "C-subtype", "C-mapped-subtype"],
41
otherParameterizedDefinition: ["method", "function",
42
"C-variable", "C-address"
48
constantSimpleDefinition: ["constant"],
53
variableSimpleDefinition: ["variable"],
57
otherSimpleDefinition: ["generic", "domain",
63
statement: ["if", "block", "begin", "method", "case",
64
"for", "select", "when", "unless", "until",
65
"while", "iterate", "profiling", "dynamic-bind"
71
separator: ["finally", "exception", "cleanup", "else",
72
"elseif", "afterwards"
77
other: ["above", "below", "by", "from", "handler", "in",
78
"instance", "let", "local", "otherwise", "slot",
79
"subclass", "then", "to", "keyed-by", "virtual"
83
signalingCalls: ["signal", "error", "cerror",
84
"break", "check-type", "abort"
88
words["otherDefinition"] =
89
words["unnamedDefinition"]
90
.concat(words["namedDefinition"])
91
.concat(words["otherParameterizedDefinition"]);
94
words["typeParameterizedDefinition"]
95
.concat(words["otherDefinition"]);
97
words["parameterizedDefinition"] =
98
words["typeParameterizedDefinition"]
99
.concat(words["otherParameterizedDefinition"]);
101
words["simpleDefinition"] =
102
words["constantSimpleDefinition"]
103
.concat(words["variableSimpleDefinition"])
104
.concat(words["otherSimpleDefinition"]);
108
.concat(words["separator"])
109
.concat(words["other"]);
112
var symbolPattern = "[-_a-zA-Z?!*@<>$%]+";
113
var symbol = new RegExp("^" + symbolPattern);
116
symbolKeyword: symbolPattern + ":",
117
symbolClass: "<" + symbolPattern + ">",
118
symbolGlobal: "\\*" + symbolPattern + "\\*",
119
symbolConstant: "\\$" + symbolPattern
121
var patternStyles = {
122
symbolKeyword: "atom",
124
symbolGlobal: "variable-2",
125
symbolConstant: "variable-3"
129
for (var patternName in patterns)
130
if (patterns.hasOwnProperty(patternName))
131
patterns[patternName] = new RegExp("^" + patterns[patternName]);
135
patterns["keyword"] = [/^with(?:out)?-[-_a-zA-Z?!*@<>$%]+/];
138
styles["keyword"] = "keyword";
139
styles["definition"] = "def";
140
styles["simpleDefinition"] = "def";
141
styles["signalingCalls"] = "builtin";
145
var styleLookup = {};
153
forEach(words[type], function(word) {
154
wordLookup[word] = type;
155
styleLookup[word] = styles[type];
160
function chain(stream, state, f) {
162
return f(stream, state);
165
function tokenBase(stream, state) {
167
var ch = stream.peek();
168
if (ch == "'" || ch == '"') {
170
return chain(stream, state, tokenString(ch, "string"));
173
else if (ch == "/") {
175
if (stream.eat("*")) {
176
return chain(stream, state, tokenComment);
177
} else if (stream.eat("/")) {
184
else if (/[+\-\d\.]/.test(ch)) {
185
if (stream.match(/^[+-]?[0-9]*\.[0-9]*([esdx][+-]?[0-9]+)?/i) ||
186
stream.match(/^[+-]?[0-9]+([esdx][+-]?[0-9]+)/i) ||
187
stream.match(/^[+-]?\d+/)) {
192
else if (ch == "#") {
198
return chain(stream, state, tokenString('"', "string"));
201
else if (ch == "b") {
203
stream.eatWhile(/[01]/);
207
else if (ch == "x") {
209
stream.eatWhile(/[\da-f]/i);
213
else if (ch == "o") {
215
stream.eatWhile(/[0-7]/);
219
else if (ch == '#') {
221
return "punctuation";
224
else if ((ch == '[') || (ch == '(')) {
228
} else if (stream.match(/f|t|all-keys|include|key|next|rest/i)) {
231
stream.eatWhile(/[-a-zA-Z]/);
234
} else if (ch == "~") {
247
} else if (ch == ":") {
253
} else if (ch == ":") {
255
return "punctuation";
257
} else if ("[](){}".indexOf(ch) != -1) {
260
} else if (".,".indexOf(ch) != -1) {
262
return "punctuation";
263
} else if (stream.match("end")) {
266
for (var name in patterns) {
267
if (patterns.hasOwnProperty(name)) {
268
var pattern = patterns[name];
269
if ((pattern instanceof Array && some(pattern, function(p) {
270
return stream.match(p);
271
})) || stream.match(pattern))
272
return patternStyles[name];
275
if (/[+\-*\/^=<>&|]/.test(ch)) {
279
if (stream.match("define")) {
282
stream.eatWhile(/[\w\-]/);
284
if (wordLookup.hasOwnProperty(stream.current())) {
285
return styleLookup[stream.current()];
286
} else if (stream.current().match(symbol)) {
295
function tokenComment(stream, state) {
296
var maybeEnd = false, maybeNested = false, nestedCount = 0, ch;
297
while ((ch = stream.next())) {
298
if (ch == "/" && maybeEnd) {
299
if (nestedCount > 0) {
302
state.tokenize = tokenBase;
305
} else if (ch == "*" && maybeNested) {
308
maybeEnd = (ch == "*");
309
maybeNested = (ch == "/");
314
function tokenString(quote, style) {
315
return function(stream, state) {
316
var escaped = false, next, end = false;
317
while ((next = stream.next()) != null) {
318
if (next == quote && !escaped) {
322
escaped = !escaped && next == "\\";
324
if (end || !escaped) {
325
state.tokenize = tokenBase;
333
startState: function() {
339
token: function(stream, state) {
340
if (stream.eatSpace())
342
var style = state.tokenize(stream, state);
345
blockCommentStart: "/*",
346
blockCommentEnd: "*/"
350
CodeMirror.defineMIME("text/x-dylan", "dylan");