Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50665 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("ecl", function(config) {
15
16
function words(str) {
17
var obj = {}, words = str.split(" ");
18
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
19
return obj;
20
}
21
22
function metaHook(stream, state) {
23
if (!state.startOfLine) return false;
24
stream.skipToEnd();
25
return "meta";
26
}
27
28
var indentUnit = config.indentUnit;
29
var keyword = words("abs acos allnodes ascii asin asstring atan atan2 ave case choose choosen choosesets clustersize combine correlation cos cosh count covariance cron dataset dedup define denormalize distribute distributed distribution ebcdic enth error evaluate event eventextra eventname exists exp failcode failmessage fetch fromunicode getisvalid global graph group hash hash32 hash64 hashcrc hashmd5 having if index intformat isvalid iterate join keyunicode length library limit ln local log loop map matched matchlength matchposition matchtext matchunicode max merge mergejoin min nolocal nonempty normalize parse pipe power preload process project pull random range rank ranked realformat recordof regexfind regexreplace regroup rejected rollup round roundup row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt stepped stored sum table tan tanh thisnode topn tounicode transfer trim truncate typeof ungroup unicodeorder variance which workunit xmldecode xmlencode xmltext xmlunicode");
30
var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");
31
var variable_2 = words("__compressed__ all and any as atmost before beginc++ best between case const counter csv descend encrypt end endc++ endmacro except exclusive expire export extend false few first flat from full function group header heading hole ifblock import in interface joined keep keyed last left limit load local locale lookup macro many maxcount maxlength min skew module named nocase noroot noscan nosort not of only opt or outer overwrite packed partition penalty physicallength pipe quote record relationship repeat return right scan self separator service shared skew skip sql store terminator thor threshold token transform trim true type unicodeorder unsorted validate virtual whole wild within xml xpath");
32
var variable_3 = words("ascii big_endian boolean data decimal ebcdic integer pattern qstring real record rule set of string token udecimal unicode unsigned varstring varunicode");
33
var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");
34
var blockKeywords = words("catch class do else finally for if switch try while");
35
var atoms = words("true false null");
36
var hooks = {"#": metaHook};
37
var multiLineStrings;
38
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
39
40
var curPunc;
41
42
function tokenBase(stream, state) {
43
var ch = stream.next();
44
if (hooks[ch]) {
45
var result = hooks[ch](stream, state);
46
if (result !== false) return result;
47
}
48
if (ch == '"' || ch == "'") {
49
state.tokenize = tokenString(ch);
50
return state.tokenize(stream, state);
51
}
52
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
53
curPunc = ch;
54
return null;
55
}
56
if (/\d/.test(ch)) {
57
stream.eatWhile(/[\w\.]/);
58
return "number";
59
}
60
if (ch == "/") {
61
if (stream.eat("*")) {
62
state.tokenize = tokenComment;
63
return tokenComment(stream, state);
64
}
65
if (stream.eat("/")) {
66
stream.skipToEnd();
67
return "comment";
68
}
69
}
70
if (isOperatorChar.test(ch)) {
71
stream.eatWhile(isOperatorChar);
72
return "operator";
73
}
74
stream.eatWhile(/[\w\$_]/);
75
var cur = stream.current().toLowerCase();
76
if (keyword.propertyIsEnumerable(cur)) {
77
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
78
return "keyword";
79
} else if (variable.propertyIsEnumerable(cur)) {
80
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
81
return "variable";
82
} else if (variable_2.propertyIsEnumerable(cur)) {
83
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
84
return "variable-2";
85
} else if (variable_3.propertyIsEnumerable(cur)) {
86
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
87
return "variable-3";
88
} else if (builtin.propertyIsEnumerable(cur)) {
89
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
90
return "builtin";
91
} else { //Data types are of from KEYWORD##
92
var i = cur.length - 1;
93
while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
94
--i;
95
96
if (i > 0) {
97
var cur2 = cur.substr(0, i + 1);
98
if (variable_3.propertyIsEnumerable(cur2)) {
99
if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
100
return "variable-3";
101
}
102
}
103
}
104
if (atoms.propertyIsEnumerable(cur)) return "atom";
105
return null;
106
}
107
108
function tokenString(quote) {
109
return function(stream, state) {
110
var escaped = false, next, end = false;
111
while ((next = stream.next()) != null) {
112
if (next == quote && !escaped) {end = true; break;}
113
escaped = !escaped && next == "\\";
114
}
115
if (end || !(escaped || multiLineStrings))
116
state.tokenize = tokenBase;
117
return "string";
118
};
119
}
120
121
function tokenComment(stream, state) {
122
var maybeEnd = false, ch;
123
while (ch = stream.next()) {
124
if (ch == "/" && maybeEnd) {
125
state.tokenize = tokenBase;
126
break;
127
}
128
maybeEnd = (ch == "*");
129
}
130
return "comment";
131
}
132
133
function Context(indented, column, type, align, prev) {
134
this.indented = indented;
135
this.column = column;
136
this.type = type;
137
this.align = align;
138
this.prev = prev;
139
}
140
function pushContext(state, col, type) {
141
return state.context = new Context(state.indented, col, type, null, state.context);
142
}
143
function popContext(state) {
144
var t = state.context.type;
145
if (t == ")" || t == "]" || t == "}")
146
state.indented = state.context.indented;
147
return state.context = state.context.prev;
148
}
149
150
// Interface
151
152
return {
153
startState: function(basecolumn) {
154
return {
155
tokenize: null,
156
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
157
indented: 0,
158
startOfLine: true
159
};
160
},
161
162
token: function(stream, state) {
163
var ctx = state.context;
164
if (stream.sol()) {
165
if (ctx.align == null) ctx.align = false;
166
state.indented = stream.indentation();
167
state.startOfLine = true;
168
}
169
if (stream.eatSpace()) return null;
170
curPunc = null;
171
var style = (state.tokenize || tokenBase)(stream, state);
172
if (style == "comment" || style == "meta") return style;
173
if (ctx.align == null) ctx.align = true;
174
175
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
176
else if (curPunc == "{") pushContext(state, stream.column(), "}");
177
else if (curPunc == "[") pushContext(state, stream.column(), "]");
178
else if (curPunc == "(") pushContext(state, stream.column(), ")");
179
else if (curPunc == "}") {
180
while (ctx.type == "statement") ctx = popContext(state);
181
if (ctx.type == "}") ctx = popContext(state);
182
while (ctx.type == "statement") ctx = popContext(state);
183
}
184
else if (curPunc == ctx.type) popContext(state);
185
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
186
pushContext(state, stream.column(), "statement");
187
state.startOfLine = false;
188
return style;
189
},
190
191
indent: function(state, textAfter) {
192
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
193
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
194
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
195
var closing = firstChar == ctx.type;
196
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
197
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
198
else return ctx.indented + (closing ? 0 : indentUnit);
199
},
200
201
electricChars: "{}"
202
};
203
});
204
205
CodeMirror.defineMIME("text/x-ecl", "ecl");
206
207
});
208
209