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
CodeMirror.defineMode("ecl", function(config) {
17
var obj = {}, words = str.split(" ");
18
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
22
function metaHook(stream, state) {
23
if (!state.startOfLine) return false;
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 isOperatorChar = /[+\-*&%=<>!?|\/]/;
41
function tokenBase(stream, state) {
42
var ch = stream.next();
44
var result = hooks[ch](stream, state);
45
if (result !== false) return result;
47
if (ch == '"' || ch == "'") {
48
state.tokenize = tokenString(ch);
49
return state.tokenize(stream, state);
51
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
56
stream.eatWhile(/[\w\.]/);
60
if (stream.eat("*")) {
61
state.tokenize = tokenComment;
62
return tokenComment(stream, state);
64
if (stream.eat("/")) {
69
if (isOperatorChar.test(ch)) {
70
stream.eatWhile(isOperatorChar);
73
stream.eatWhile(/[\w\$_]/);
74
var cur = stream.current().toLowerCase();
75
if (keyword.propertyIsEnumerable(cur)) {
76
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
78
} else if (variable.propertyIsEnumerable(cur)) {
79
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
81
} else if (variable_2.propertyIsEnumerable(cur)) {
82
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
84
} else if (variable_3.propertyIsEnumerable(cur)) {
85
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
87
} else if (builtin.propertyIsEnumerable(cur)) {
88
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
91
var i = cur.length - 1;
92
while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
96
var cur2 = cur.substr(0, i + 1);
97
if (variable_3.propertyIsEnumerable(cur2)) {
98
if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
103
if (atoms.propertyIsEnumerable(cur)) return "atom";
107
function tokenString(quote) {
108
return function(stream, state) {
109
var escaped = false, next, end = false;
110
while ((next = stream.next()) != null) {
111
if (next == quote && !escaped) {end = true; break;}
112
escaped = !escaped && next == "\\";
115
state.tokenize = tokenBase;
120
function tokenComment(stream, state) {
121
var maybeEnd = false, ch;
122
while (ch = stream.next()) {
123
if (ch == "/" && maybeEnd) {
124
state.tokenize = tokenBase;
127
maybeEnd = (ch == "*");
132
function Context(indented, column, type, align, prev) {
133
this.indented = indented;
134
this.column = column;
139
function pushContext(state, col, type) {
140
return state.context = new Context(state.indented, col, type, null, state.context);
142
function popContext(state) {
143
var t = state.context.type;
144
if (t == ")" || t == "]" || t == "}")
145
state.indented = state.context.indented;
146
return state.context = state.context.prev;
152
startState: function(basecolumn) {
155
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
161
token: function(stream, state) {
162
var ctx = state.context;
164
if (ctx.align == null) ctx.align = false;
165
state.indented = stream.indentation();
166
state.startOfLine = true;
168
if (stream.eatSpace()) return null;
170
var style = (state.tokenize || tokenBase)(stream, state);
171
if (style == "comment" || style == "meta") return style;
172
if (ctx.align == null) ctx.align = true;
174
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
175
else if (curPunc == "{") pushContext(state, stream.column(), "}");
176
else if (curPunc == "[") pushContext(state, stream.column(), "]");
177
else if (curPunc == "(") pushContext(state, stream.column(), ")");
178
else if (curPunc == "}") {
179
while (ctx.type == "statement") ctx = popContext(state);
180
if (ctx.type == "}") ctx = popContext(state);
181
while (ctx.type == "statement") ctx = popContext(state);
183
else if (curPunc == ctx.type) popContext(state);
184
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
185
pushContext(state, stream.column(), "statement");
186
state.startOfLine = false;
190
indent: function(state, textAfter) {
191
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
192
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
193
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
194
var closing = firstChar == ctx.type;
195
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
196
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
197
else return ctx.indented + (closing ? 0 : indentUnit);
204
CodeMirror.defineMIME("text/x-ecl", "ecl");