Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / mode / ecl / ecl.js
1 CodeMirror.defineMode("ecl", function(config) {
2
3   function words(str) {
4     var obj = {}, words = str.split(" ");
5     for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
6     return obj;
7   }
8
9   function metaHook(stream, state) {
10     if (!state.startOfLine) return false;
11     stream.skipToEnd();
12     return "meta";
13   }
14
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};
24   var multiLineStrings;
25   var isOperatorChar = /[+\-*&%=<>!?|\/]/;
26
27   var curPunc;
28
29   function tokenBase(stream, state) {
30     var ch = stream.next();
31     if (hooks[ch]) {
32       var result = hooks[ch](stream, state);
33       if (result !== false) return result;
34     }
35     if (ch == '"' || ch == "'") {
36       state.tokenize = tokenString(ch);
37       return state.tokenize(stream, state);
38     }
39     if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
40       curPunc = ch;
41       return null;
42     }
43     if (/\d/.test(ch)) {
44       stream.eatWhile(/[\w\.]/);
45       return "number";
46     }
47     if (ch == "/") {
48       if (stream.eat("*")) {
49         state.tokenize = tokenComment;
50         return tokenComment(stream, state);
51       }
52       if (stream.eat("/")) {
53         stream.skipToEnd();
54         return "comment";
55       }
56     }
57     if (isOperatorChar.test(ch)) {
58       stream.eatWhile(isOperatorChar);
59       return "operator";
60     }
61     stream.eatWhile(/[\w\$_]/);
62     var cur = stream.current().toLowerCase();
63     if (keyword.propertyIsEnumerable(cur)) {
64       if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
65       return "keyword";
66     } else if (variable.propertyIsEnumerable(cur)) {
67       if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
68       return "variable";
69     } else if (variable_2.propertyIsEnumerable(cur)) {
70       if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
71       return "variable-2";
72     } else if (variable_3.propertyIsEnumerable(cur)) {
73       if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
74       return "variable-3";
75     } else if (builtin.propertyIsEnumerable(cur)) {
76       if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
77       return "builtin";
78     } else { //Data types are of from KEYWORD##
79                 var i = cur.length - 1;
80                 while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
81                         --i;
82
83                 if (i > 0) {
84                         var cur2 = cur.substr(0, i + 1);
85                 if (variable_3.propertyIsEnumerable(cur2)) {
86                         if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
87                         return "variable-3";
88                 }
89             }
90     }
91     if (atoms.propertyIsEnumerable(cur)) return "atom";
92     return null;
93   }
94
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 == "\\";
101       }
102       if (end || !(escaped || multiLineStrings))
103         state.tokenize = tokenBase;
104       return "string";
105     };
106   }
107
108   function tokenComment(stream, state) {
109     var maybeEnd = false, ch;
110     while (ch = stream.next()) {
111       if (ch == "/" && maybeEnd) {
112         state.tokenize = tokenBase;
113         break;
114       }
115       maybeEnd = (ch == "*");
116     }
117     return "comment";
118   }
119
120   function Context(indented, column, type, align, prev) {
121     this.indented = indented;
122     this.column = column;
123     this.type = type;
124     this.align = align;
125     this.prev = prev;
126   }
127   function pushContext(state, col, type) {
128     return state.context = new Context(state.indented, col, type, null, state.context);
129   }
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;
135   }
136
137   // Interface
138
139   return {
140     startState: function(basecolumn) {
141       return {
142         tokenize: null,
143         context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
144         indented: 0,
145         startOfLine: true
146       };
147     },
148
149     token: function(stream, state) {
150       var ctx = state.context;
151       if (stream.sol()) {
152         if (ctx.align == null) ctx.align = false;
153         state.indented = stream.indentation();
154         state.startOfLine = true;
155       }
156       if (stream.eatSpace()) return null;
157       curPunc = 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;
161
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);
170       }
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;
175       return style;
176     },
177
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);
186     },
187
188     electricChars: "{}"
189   };
190 });
191
192 CodeMirror.defineMIME("text/x-ecl", "ecl");