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