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 var indentUnit = config.indentUnit;
16 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");
17 var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");
18 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");
19 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");
20 var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");
21 var blockKeywords = words("catch class do else finally for if switch try while");
22 var atoms = words("true false null");
23 var hooks = {"#": metaHook};
25 var isOperatorChar = /[+\-*&%=<>!?|\/]/;
29 function tokenBase(stream, state) {
30 var ch = stream.next();
32 var result = hooks[ch](stream, state);
33 if (result !== false) return result;
35 if (ch == '"' || ch == "'") {
36 state.tokenize = tokenString(ch);
37 return state.tokenize(stream, state);
39 if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
44 stream.eatWhile(/[\w\.]/);
48 if (stream.eat("*")) {
49 state.tokenize = tokenComment;
50 return tokenComment(stream, state);
52 if (stream.eat("/")) {
57 if (isOperatorChar.test(ch)) {
58 stream.eatWhile(isOperatorChar);
61 stream.eatWhile(/[\w\$_]/);
62 var cur = stream.current().toLowerCase();
63 if (keyword.propertyIsEnumerable(cur)) {
64 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
66 } else if (variable.propertyIsEnumerable(cur)) {
67 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
69 } else if (variable_2.propertyIsEnumerable(cur)) {
70 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
72 } else if (variable_3.propertyIsEnumerable(cur)) {
73 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
75 } else if (builtin.propertyIsEnumerable(cur)) {
76 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
78 } else { //Data types are of from KEYWORD##
79 var i = cur.length - 1;
80 while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
84 var cur2 = cur.substr(0, i + 1);
85 if (variable_3.propertyIsEnumerable(cur2)) {
86 if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
91 if (atoms.propertyIsEnumerable(cur)) return "atom";
95 function tokenString(quote) {
96 return function(stream, state) {
97 var escaped = false, next, end = false;
98 while ((next = stream.next()) != null) {
99 if (next == quote && !escaped) {end = true; break;}
100 escaped = !escaped && next == "\\";
102 if (end || !(escaped || multiLineStrings))
103 state.tokenize = tokenBase;
108 function tokenComment(stream, state) {
109 var maybeEnd = false, ch;
110 while (ch = stream.next()) {
111 if (ch == "/" && maybeEnd) {
112 state.tokenize = tokenBase;
115 maybeEnd = (ch == "*");
120 function Context(indented, column, type, align, prev) {
121 this.indented = indented;
122 this.column = column;
127 function pushContext(state, col, type) {
128 return state.context = new Context(state.indented, col, type, null, state.context);
130 function popContext(state) {
131 var t = state.context.type;
132 if (t == ")" || t == "]" || t == "}")
133 state.indented = state.context.indented;
134 return state.context = state.context.prev;
140 startState: function(basecolumn) {
143 context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
149 token: function(stream, state) {
150 var ctx = state.context;
152 if (ctx.align == null) ctx.align = false;
153 state.indented = stream.indentation();
154 state.startOfLine = true;
156 if (stream.eatSpace()) return null;
158 var style = (state.tokenize || tokenBase)(stream, state);
159 if (style == "comment" || style == "meta") return style;
160 if (ctx.align == null) ctx.align = true;
162 if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
163 else if (curPunc == "{") pushContext(state, stream.column(), "}");
164 else if (curPunc == "[") pushContext(state, stream.column(), "]");
165 else if (curPunc == "(") pushContext(state, stream.column(), ")");
166 else if (curPunc == "}") {
167 while (ctx.type == "statement") ctx = popContext(state);
168 if (ctx.type == "}") ctx = popContext(state);
169 while (ctx.type == "statement") ctx = popContext(state);
171 else if (curPunc == ctx.type) popContext(state);
172 else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
173 pushContext(state, stream.column(), "statement");
174 state.startOfLine = false;
178 indent: function(state, textAfter) {
179 if (state.tokenize != tokenBase && state.tokenize != null) return 0;
180 var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
181 if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
182 var closing = firstChar == ctx.type;
183 if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
184 else if (ctx.align) return ctx.column + (closing ? 0 : 1);
185 else return ctx.indented + (closing ? 0 : indentUnit);
192 CodeMirror.defineMIME("text/x-ecl", "ecl");