Debian Codegraph @

codemirror-legacy-modes/mode/ecl.js

raw
1 function words(str) {
2 var obj = {}, words = str.split(" ");
3 for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
4 return obj;
5 }
6
7 function metaHook(stream, state) {
8 if (!state.startOfLine) return false;
9 stream.skipToEnd();
10 return "meta";
11 }
12
13 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");
14 var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");
15 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");
16 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");
17 var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");
18 var blockKeywords = words("catch class do else finally for if switch try while");
19 var atoms = words("true false null");
20 var hooks = {"#": metaHook};
21 var isOperatorChar = /[+\-*&%=<>!?|\/]/;
22
23 var curPunc;
24
25 function tokenBase(stream, state) {
26 var ch = stream.next();
27 if (hooks[ch]) {
28 var result = hooks[ch](stream, state);
29 if (result !== false) return result;
30 }
31 if (ch == '"' || ch == "'") {
32 state.tokenize = tokenString(ch);
33 return state.tokenize(stream, state);
34 }
35 if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
36 curPunc = ch;
37 return null;
38 }
39 if (/\d/.test(ch)) {
40 stream.eatWhile(/[\w\.]/);
41 return "number";
42 }
43 if (ch == "/") {
44 if (stream.eat("*")) {
45 state.tokenize = tokenComment;
46 return tokenComment(stream, state);
47 }
48 if (stream.eat("/")) {
49 stream.skipToEnd();
50 return "comment";
51 }
52 }
53 if (isOperatorChar.test(ch)) {
54 stream.eatWhile(isOperatorChar);
55 return "operator";
56 }
57 stream.eatWhile(/[\w\$_]/);
58 var cur = stream.current().toLowerCase();
59 if (keyword.propertyIsEnumerable(cur)) {
60 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
61 return "keyword";
62 } else if (variable.propertyIsEnumerable(cur)) {
63 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
64 return "variable";
65 } else if (variable_2.propertyIsEnumerable(cur)) {
66 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
67 return "modifier";
68 } else if (variable_3.propertyIsEnumerable(cur)) {
69 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
70 return "type";
71 } else if (builtin.propertyIsEnumerable(cur)) {
72 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
73 return "builtin";
74 } else { //Data types are of from KEYWORD##
75 var i = cur.length - 1;
76 while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
77 --i;
78
79 if (i > 0) {
80 var cur2 = cur.substr(0, i + 1);
81 if (variable_3.propertyIsEnumerable(cur2)) {
82 if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
83 return "type";
84 }
85 }
86 }
87 if (atoms.propertyIsEnumerable(cur)) return "atom";
88 return null;
89 }
90
91 function tokenString(quote) {
92 return function(stream, state) {
93 var escaped = false, next, end = false;
94 while ((next = stream.next()) != null) {
95 if (next == quote && !escaped) {end = true; break;}
96 escaped = !escaped && next == "\\";
97 }
98 if (end || !escaped)
99 state.tokenize = tokenBase;
100 return "string";
101 };
102 }
103
104 function tokenComment(stream, state) {
105 var maybeEnd = false, ch;
106 while (ch = stream.next()) {
107 if (ch == "/" && maybeEnd) {
108 state.tokenize = tokenBase;
109 break;
110 }
111 maybeEnd = (ch == "*");
112 }
113 return "comment";
114 }
115
116 function Context(indented, column, type, align, prev) {
117 this.indented = indented;
118 this.column = column;
119 this.type = type;
120 this.align = align;
121 this.prev = prev;
122 }
123 function pushContext(state, col, type) {
124 return state.context = new Context(state.indented, col, type, null, state.context);
125 }
126 function popContext(state) {
127 var t = state.context.type;
128 if (t == ")" || t == "]" || t == "}")
129 state.indented = state.context.indented;
130 return state.context = state.context.prev;
131 }
132
133 // Interface
134
135 export const ecl = {
136 name: "ecl",
137 startState: function(indentUnit) {
138 return {
139 tokenize: null,
140 context: new Context(-indentUnit, 0, "top", false),
141 indented: 0,
142 startOfLine: true
143 };
144 },
145
146 token: function(stream, state) {
147 var ctx = state.context;
148 if (stream.sol()) {
149 if (ctx.align == null) ctx.align = false;
150 state.indented = stream.indentation();
151 state.startOfLine = true;
152 }
153 if (stream.eatSpace()) return null;
154 curPunc = null;
155 var style = (state.tokenize || tokenBase)(stream, state);
156 if (style == "comment" || style == "meta") return style;
157 if (ctx.align == null) ctx.align = true;
158
159 if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
160 else if (curPunc == "{") pushContext(state, stream.column(), "}");
161 else if (curPunc == "[") pushContext(state, stream.column(), "]");
162 else if (curPunc == "(") pushContext(state, stream.column(), ")");
163 else if (curPunc == "}") {
164 while (ctx.type == "statement") ctx = popContext(state);
165 if (ctx.type == "}") ctx = popContext(state);
166 while (ctx.type == "statement") ctx = popContext(state);
167 }
168 else if (curPunc == ctx.type) popContext(state);
169 else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
170 pushContext(state, stream.column(), "statement");
171 state.startOfLine = false;
172 return style;
173 },
174
175 indent: function(state, textAfter, cx) {
176 if (state.tokenize != tokenBase && state.tokenize != null) return 0;
177 var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
178 if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
179 var closing = firstChar == ctx.type;
180 if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : cx.unit);
181 else if (ctx.align) return ctx.column + (closing ? 0 : 1);
182 else return ctx.indented + (closing ? 0 : cx.unit);
183 },
184
185 languageData: {
186 indentOnInput: /^\s*[{}]$/
187 }
188 };