1
CodeMirror.defineMode("ecl", function(config) {
4
var obj = {}, words = str.split(" ");
5
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
9
function metaHook(stream, state) {
10
if (!state.startOfLine) return false;
15
function tokenAtString(stream, state) {
17
while ((next = stream.next()) != null) {
18
if (next == '"' && !stream.eat('"')) {
19
state.tokenize = null;
26
var indentUnit = config.indentUnit;
27
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");
28
var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");
29
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");
30
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");
31
var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");
32
var blockKeywords = words("catch class do else finally for if switch try while");
33
var atoms = words("true false null");
34
var hooks = {"#": metaHook};
36
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
40
function tokenBase(stream, state) {
41
var ch = stream.next();
43
var result = hooks[ch](stream, state);
44
if (result !== false) return result;
46
if (ch == '"' || ch == "'") {
47
state.tokenize = tokenString(ch);
48
return state.tokenize(stream, state);
50
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
55
stream.eatWhile(/[\w\.]/);
59
if (stream.eat("*")) {
60
state.tokenize = tokenComment;
61
return tokenComment(stream, state);
63
if (stream.eat("/")) {
68
if (isOperatorChar.test(ch)) {
69
stream.eatWhile(isOperatorChar);
72
stream.eatWhile(/[\w\$_]/);
73
var cur = stream.current().toLowerCase();
74
if (keyword.propertyIsEnumerable(cur)) {
75
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
77
} else if (variable.propertyIsEnumerable(cur)) {
78
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
80
} else if (variable_2.propertyIsEnumerable(cur)) {
81
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
83
} else if (variable_3.propertyIsEnumerable(cur)) {
84
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
86
} else if (builtin.propertyIsEnumerable(cur)) {
87
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
89
} else { //Data types are of from KEYWORD##
90
var i = cur.length - 1;
91
while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
95
var cur2 = cur.substr(0, i + 1);
96
if (variable_3.propertyIsEnumerable(cur2)) {
97
if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
102
if (atoms.propertyIsEnumerable(cur)) return "atom";
106
function tokenString(quote) {
107
return function(stream, state) {
108
var escaped = false, next, end = false;
109
while ((next = stream.next()) != null) {
110
if (next == quote && !escaped) {end = true; break;}
111
escaped = !escaped && next == "\\";
113
if (end || !(escaped || multiLineStrings))
114
state.tokenize = tokenBase;
119
function tokenComment(stream, state) {
120
var maybeEnd = false, ch;
121
while (ch = stream.next()) {
122
if (ch == "/" && maybeEnd) {
123
state.tokenize = tokenBase;
126
maybeEnd = (ch == "*");
131
function Context(indented, column, type, align, prev) {
132
this.indented = indented;
133
this.column = column;
138
function pushContext(state, col, type) {
139
return state.context = new Context(state.indented, col, type, null, state.context);
141
function popContext(state) {
142
var t = state.context.type;
143
if (t == ")" || t == "]" || t == "}")
144
state.indented = state.context.indented;
145
return state.context = state.context.prev;
151
startState: function(basecolumn) {
154
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
160
token: function(stream, state) {
161
var ctx = state.context;
163
if (ctx.align == null) ctx.align = false;
164
state.indented = stream.indentation();
165
state.startOfLine = true;
167
if (stream.eatSpace()) return null;
169
var style = (state.tokenize || tokenBase)(stream, state);
170
if (style == "comment" || style == "meta") return style;
171
if (ctx.align == null) ctx.align = true;
173
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
174
else if (curPunc == "{") pushContext(state, stream.column(), "}");
175
else if (curPunc == "[") pushContext(state, stream.column(), "]");
176
else if (curPunc == "(") pushContext(state, stream.column(), ")");
177
else if (curPunc == "}") {
178
while (ctx.type == "statement") ctx = popContext(state);
179
if (ctx.type == "}") ctx = popContext(state);
180
while (ctx.type == "statement") ctx = popContext(state);
182
else if (curPunc == ctx.type) popContext(state);
183
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
184
pushContext(state, stream.column(), "statement");
185
state.startOfLine = false;
189
indent: function(state, textAfter) {
190
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
191
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
192
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
193
var closing = firstChar == ctx.type;
194
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
195
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
196
else return ctx.indented + (closing ? 0 : indentUnit);
203
CodeMirror.defineMIME("text/x-ecl");