aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/ecl
diff options
context:
space:
mode:
Diffstat (limited to 'imports/codemirror/mode/ecl')
-rw-r--r--imports/codemirror/mode/ecl/ecl.js203
-rw-r--r--imports/codemirror/mode/ecl/index.html42
2 files changed, 245 insertions, 0 deletions
diff --git a/imports/codemirror/mode/ecl/ecl.js b/imports/codemirror/mode/ecl/ecl.js
new file mode 100644
index 00000000..9c94e670
--- /dev/null
+++ b/imports/codemirror/mode/ecl/ecl.js
@@ -0,0 +1,203 @@
1CodeMirror.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 function tokenAtString(stream, state) {
16 var next;
17 while ((next = stream.next()) != null) {
18 if (next == '"' && !stream.eat('"')) {
19 state.tokenize = null;
20 break;
21 }
22 }
23 return "string";
24 }
25
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};
35 var multiLineStrings;
36 var isOperatorChar = /[+\-*&%=<>!?|\/]/;
37
38 var curPunc;
39
40 function tokenBase(stream, state) {
41 var ch = stream.next();
42 if (hooks[ch]) {
43 var result = hooks[ch](stream, state);
44 if (result !== false) return result;
45 }
46 if (ch == '"' || ch == "'") {
47 state.tokenize = tokenString(ch);
48 return state.tokenize(stream, state);
49 }
50 if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
51 curPunc = ch;
52 return null
53 }
54 if (/\d/.test(ch)) {
55 stream.eatWhile(/[\w\.]/);
56 return "number";
57 }
58 if (ch == "/") {
59 if (stream.eat("*")) {
60 state.tokenize = tokenComment;
61 return tokenComment(stream, state);
62 }
63 if (stream.eat("/")) {
64 stream.skipToEnd();
65 return "comment";
66 }
67 }
68 if (isOperatorChar.test(ch)) {
69 stream.eatWhile(isOperatorChar);
70 return "operator";
71 }
72 stream.eatWhile(/[\w\$_]/);
73 var cur = stream.current().toLowerCase();
74 if (keyword.propertyIsEnumerable(cur)) {
75 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
76 return "keyword";
77 } else if (variable.propertyIsEnumerable(cur)) {
78 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
79 return "variable";
80 } else if (variable_2.propertyIsEnumerable(cur)) {
81 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
82 return "variable-2";
83 } else if (variable_3.propertyIsEnumerable(cur)) {
84 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
85 return "variable-3";
86 } else if (builtin.propertyIsEnumerable(cur)) {
87 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
88 return "builtin";
89 } else { //Data types are of from KEYWORD##
90 var i = cur.length - 1;
91 while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))
92 --i;
93
94 if (i > 0) {
95 var cur2 = cur.substr(0, i + 1);
96 if (variable_3.propertyIsEnumerable(cur2)) {
97 if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";
98 return "variable-3";
99 }
100 }
101 }
102 if (atoms.propertyIsEnumerable(cur)) return "atom";
103 return "word";
104 }
105
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 == "\\";
112 }
113 if (end || !(escaped || multiLineStrings))
114 state.tokenize = tokenBase;
115 return "string";
116 };
117 }
118
119 function tokenComment(stream, state) {
120 var maybeEnd = false, ch;
121 while (ch = stream.next()) {
122 if (ch == "/" && maybeEnd) {
123 state.tokenize = tokenBase;
124 break;
125 }
126 maybeEnd = (ch == "*");
127 }
128 return "comment";
129 }
130
131 function Context(indented, column, type, align, prev) {
132 this.indented = indented;
133 this.column = column;
134 this.type = type;
135 this.align = align;
136 this.prev = prev;
137 }
138 function pushContext(state, col, type) {
139 return state.context = new Context(state.indented, col, type, null, state.context);
140 }
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;
146 }
147
148 // Interface
149
150 return {
151 startState: function(basecolumn) {
152 return {
153 tokenize: null,
154 context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
155 indented: 0,
156 startOfLine: true
157 };
158 },
159
160 token: function(stream, state) {
161 var ctx = state.context;
162 if (stream.sol()) {
163 if (ctx.align == null) ctx.align = false;
164 state.indented = stream.indentation();
165 state.startOfLine = true;
166 }
167 if (stream.eatSpace()) return null;
168 curPunc = 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;
172
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);
181 }
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;
186 return style;
187 },
188
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);
197 },
198
199 electricChars: "{}"
200 };
201});
202
203CodeMirror.defineMIME("text/x-ecl");
diff --git a/imports/codemirror/mode/ecl/index.html b/imports/codemirror/mode/ecl/index.html
new file mode 100644
index 00000000..d6b41f4e
--- /dev/null
+++ b/imports/codemirror/mode/ecl/index.html
@@ -0,0 +1,42 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror: ECL mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="ecl.js"></script>
8 <link rel="stylesheet" href="../../doc/docs.css">
9 <style>.CodeMirror {border: 1px solid black;}</style>
10 </head>
11 <body>
12 <h1>CodeMirror: ECL mode</h1>
13 <form><textarea id="code" name="code">
14/*
15sample useless code to demonstrate ecl syntax highlighting
16this is a multiline comment!
17*/
18
19// this is a singleline comment!
20