LaravelTest
206 строк · 8.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("ecl", function(config) {15
16function words(str) {17var obj = {}, words = str.split(" ");18for (var i = 0; i < words.length; ++i) obj[words[i]] = true;19return obj;20}21
22function metaHook(stream, state) {23if (!state.startOfLine) return false;24stream.skipToEnd();25return "meta";26}27
28var indentUnit = config.indentUnit;29var 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");30var variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait");31var 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");32var 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");33var builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when");34var blockKeywords = words("catch class do else finally for if switch try while");35var atoms = words("true false null");36var hooks = {"#": metaHook};37var isOperatorChar = /[+\-*&%=<>!?|\/]/;38
39var curPunc;40
41function tokenBase(stream, state) {42var ch = stream.next();43if (hooks[ch]) {44var result = hooks[ch](stream, state);45if (result !== false) return result;46}47if (ch == '"' || ch == "'") {48state.tokenize = tokenString(ch);49return state.tokenize(stream, state);50}51if (/[\[\]{}\(\),;\:\.]/.test(ch)) {52curPunc = ch;53return null;54}55if (/\d/.test(ch)) {56stream.eatWhile(/[\w\.]/);57return "number";58}59if (ch == "/") {60if (stream.eat("*")) {61state.tokenize = tokenComment;62return tokenComment(stream, state);63}64if (stream.eat("/")) {65stream.skipToEnd();66return "comment";67}68}69if (isOperatorChar.test(ch)) {70stream.eatWhile(isOperatorChar);71return "operator";72}73stream.eatWhile(/[\w\$_]/);74var cur = stream.current().toLowerCase();75if (keyword.propertyIsEnumerable(cur)) {76if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";77return "keyword";78} else if (variable.propertyIsEnumerable(cur)) {79if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";80return "variable";81} else if (variable_2.propertyIsEnumerable(cur)) {82if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";83return "variable-2";84} else if (variable_3.propertyIsEnumerable(cur)) {85if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";86return "variable-3";87} else if (builtin.propertyIsEnumerable(cur)) {88if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";89return "builtin";90} else { //Data types are of from KEYWORD##91var i = cur.length - 1;92while(i >= 0 && (!isNaN(cur[i]) || cur[i] == '_'))93--i;94
95if (i > 0) {96var cur2 = cur.substr(0, i + 1);97if (variable_3.propertyIsEnumerable(cur2)) {98if (blockKeywords.propertyIsEnumerable(cur2)) curPunc = "newstatement";99return "variable-3";100}101}102}103if (atoms.propertyIsEnumerable(cur)) return "atom";104return null;105}106
107function tokenString(quote) {108return function(stream, state) {109var escaped = false, next, end = false;110while ((next = stream.next()) != null) {111if (next == quote && !escaped) {end = true; break;}112escaped = !escaped && next == "\\";113}114if (end || !escaped)115state.tokenize = tokenBase;116return "string";117};118}119
120function tokenComment(stream, state) {121var maybeEnd = false, ch;122while (ch = stream.next()) {123if (ch == "/" && maybeEnd) {124state.tokenize = tokenBase;125break;126}127maybeEnd = (ch == "*");128}129return "comment";130}131
132function Context(indented, column, type, align, prev) {133this.indented = indented;134this.column = column;135this.type = type;136this.align = align;137this.prev = prev;138}139function pushContext(state, col, type) {140return state.context = new Context(state.indented, col, type, null, state.context);141}142function popContext(state) {143var t = state.context.type;144if (t == ")" || t == "]" || t == "}")145state.indented = state.context.indented;146return state.context = state.context.prev;147}148
149// Interface150
151return {152startState: function(basecolumn) {153return {154tokenize: null,155context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),156indented: 0,157startOfLine: true158};159},160
161token: function(stream, state) {162var ctx = state.context;163if (stream.sol()) {164if (ctx.align == null) ctx.align = false;165state.indented = stream.indentation();166state.startOfLine = true;167}168if (stream.eatSpace()) return null;169curPunc = null;170var style = (state.tokenize || tokenBase)(stream, state);171if (style == "comment" || style == "meta") return style;172if (ctx.align == null) ctx.align = true;173
174if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);175else if (curPunc == "{") pushContext(state, stream.column(), "}");176else if (curPunc == "[") pushContext(state, stream.column(), "]");177else if (curPunc == "(") pushContext(state, stream.column(), ")");178else if (curPunc == "}") {179while (ctx.type == "statement") ctx = popContext(state);180if (ctx.type == "}") ctx = popContext(state);181while (ctx.type == "statement") ctx = popContext(state);182}183else if (curPunc == ctx.type) popContext(state);184else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))185pushContext(state, stream.column(), "statement");186state.startOfLine = false;187return style;188},189
190indent: function(state, textAfter) {191if (state.tokenize != tokenBase && state.tokenize != null) return 0;192var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);193if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;194var closing = firstChar == ctx.type;195if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);196else if (ctx.align) return ctx.column + (closing ? 0 : 1);197else return ctx.indented + (closing ? 0 : indentUnit);198},199
200electricChars: "{}"201};202});203
204CodeMirror.defineMIME("text/x-ecl", "ecl");205
206});207