LaravelTest
283 строки · 9.9 Кб
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("ttcn", function(config, parserConfig) {15var indentUnit = config.indentUnit,16keywords = parserConfig.keywords || {},17builtin = parserConfig.builtin || {},18timerOps = parserConfig.timerOps || {},19portOps = parserConfig.portOps || {},20configOps = parserConfig.configOps || {},21verdictOps = parserConfig.verdictOps || {},22sutOps = parserConfig.sutOps || {},23functionOps = parserConfig.functionOps || {},24
25verdictConsts = parserConfig.verdictConsts || {},26booleanConsts = parserConfig.booleanConsts || {},27otherConsts = parserConfig.otherConsts || {},28
29types = parserConfig.types || {},30visibilityModifiers = parserConfig.visibilityModifiers || {},31templateMatch = parserConfig.templateMatch || {},32multiLineStrings = parserConfig.multiLineStrings,33indentStatements = parserConfig.indentStatements !== false;34var isOperatorChar = /[+\-*&@=<>!\/]/;35var curPunc;36
37function tokenBase(stream, state) {38var ch = stream.next();39
40if (ch == '"' || ch == "'") {41state.tokenize = tokenString(ch);42return state.tokenize(stream, state);43}44if (/[\[\]{}\(\),;\\:\?\.]/.test(ch)) {45curPunc = ch;46return "punctuation";47}48if (ch == "#"){49stream.skipToEnd();50return "atom preprocessor";51}52if (ch == "%"){53stream.eatWhile(/\b/);54return "atom ttcn3Macros";55}56if (/\d/.test(ch)) {57stream.eatWhile(/[\w\.]/);58return "number";59}60if (ch == "/") {61if (stream.eat("*")) {62state.tokenize = tokenComment;63return tokenComment(stream, state);64}65if (stream.eat("/")) {66stream.skipToEnd();67return "comment";68}69}70if (isOperatorChar.test(ch)) {71if(ch == "@"){72if(stream.match("try") || stream.match("catch")73|| stream.match("lazy")){74return "keyword";75}76}77stream.eatWhile(isOperatorChar);78return "operator";79}80stream.eatWhile(/[\w\$_\xa1-\uffff]/);81var cur = stream.current();82
83if (keywords.propertyIsEnumerable(cur)) return "keyword";84if (builtin.propertyIsEnumerable(cur)) return "builtin";85
86if (timerOps.propertyIsEnumerable(cur)) return "def timerOps";87if (configOps.propertyIsEnumerable(cur)) return "def configOps";88if (verdictOps.propertyIsEnumerable(cur)) return "def verdictOps";89if (portOps.propertyIsEnumerable(cur)) return "def portOps";90if (sutOps.propertyIsEnumerable(cur)) return "def sutOps";91if (functionOps.propertyIsEnumerable(cur)) return "def functionOps";92
93if (verdictConsts.propertyIsEnumerable(cur)) return "string verdictConsts";94if (booleanConsts.propertyIsEnumerable(cur)) return "string booleanConsts";95if (otherConsts.propertyIsEnumerable(cur)) return "string otherConsts";96
97if (types.propertyIsEnumerable(cur)) return "builtin types";98if (visibilityModifiers.propertyIsEnumerable(cur))99return "builtin visibilityModifiers";100if (templateMatch.propertyIsEnumerable(cur)) return "atom templateMatch";101
102return "variable";103}104
105function tokenString(quote) {106return function(stream, state) {107var escaped = false, next, end = false;108while ((next = stream.next()) != null) {109if (next == quote && !escaped){110var afterQuote = stream.peek();111//look if the character after the quote is like the B in '10100010'B112if (afterQuote){113afterQuote = afterQuote.toLowerCase();114if(afterQuote == "b" || afterQuote == "h" || afterQuote == "o")115stream.next();116}117end = true; break;118}119escaped = !escaped && next == "\\";120}121if (end || !(escaped || multiLineStrings))122state.tokenize = null;123return "string";124};125}126
127function tokenComment(stream, state) {128var maybeEnd = false, ch;129while (ch = stream.next()) {130if (ch == "/" && maybeEnd) {131state.tokenize = null;132break;133}134maybeEnd = (ch == "*");135}136return "comment";137}138
139function Context(indented, column, type, align, prev) {140this.indented = indented;141this.column = column;142this.type = type;143this.align = align;144this.prev = prev;145}146
147function pushContext(state, col, type) {148var indent = state.indented;149if (state.context && state.context.type == "statement")150indent = state.context.indented;151return state.context = new Context(indent, col, type, null, state.context);152}153
154function popContext(state) {155var t = state.context.type;156if (t == ")" || t == "]" || t == "}")157state.indented = state.context.indented;158return state.context = state.context.prev;159}160
161//Interface162return {163startState: function(basecolumn) {164return {165tokenize: null,166context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),167indented: 0,168startOfLine: true169};170},171
172token: function(stream, state) {173var ctx = state.context;174if (stream.sol()) {175if (ctx.align == null) ctx.align = false;176state.indented = stream.indentation();177state.startOfLine = true;178}179if (stream.eatSpace()) return null;180curPunc = null;181var style = (state.tokenize || tokenBase)(stream, state);182if (style == "comment") return style;183if (ctx.align == null) ctx.align = true;184
185if ((curPunc == ";" || curPunc == ":" || curPunc == ",")186&& ctx.type == "statement"){187popContext(state);188}189else if (curPunc == "{") pushContext(state, stream.column(), "}");190else if (curPunc == "[") pushContext(state, stream.column(), "]");191else if (curPunc == "(") pushContext(state, stream.column(), ")");192else if (curPunc == "}") {193while (ctx.type == "statement") ctx = popContext(state);194if (ctx.type == "}") ctx = popContext(state);195while (ctx.type == "statement") ctx = popContext(state);196}197else if (curPunc == ctx.type) popContext(state);198else if (indentStatements &&199(((ctx.type == "}" || ctx.type == "top") && curPunc != ';') ||200(ctx.type == "statement" && curPunc == "newstatement")))201pushContext(state, stream.column(), "statement");202
203state.startOfLine = false;204
205return style;206},207
208electricChars: "{}",209blockCommentStart: "/*",210blockCommentEnd: "*/",211lineComment: "//",212fold: "brace"213};214});215
216function words(str) {217var obj = {}, words = str.split(" ");218for (var i = 0; i < words.length; ++i) obj[words[i]] = true;219return obj;220}221
222function def(mimes, mode) {223if (typeof mimes == "string") mimes = [mimes];224var words = [];225function add(obj) {226if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))227words.push(prop);228}229
230add(mode.keywords);231add(mode.builtin);232add(mode.timerOps);233add(mode.portOps);234
235if (words.length) {236mode.helperType = mimes[0];237CodeMirror.registerHelper("hintWords", mimes[0], words);238}239
240for (var i = 0; i < mimes.length; ++i)241CodeMirror.defineMIME(mimes[i], mode);242}243
244def(["text/x-ttcn", "text/x-ttcn3", "text/x-ttcnpp"], {245name: "ttcn",246keywords: words("activate address alive all alt altstep and and4b any" +247" break case component const continue control deactivate" +248" display do else encode enumerated except exception" +249" execute extends extension external for from function" +250" goto group if import in infinity inout interleave" +251" label language length log match message mixed mod" +252" modifies module modulepar mtc noblock not not4b nowait" +253" of on optional or or4b out override param pattern port" +254" procedure record recursive rem repeat return runs select" +255" self sender set signature system template testcase to" +256" type union value valueof var variant while with xor xor4b"),257builtin: words("bit2hex bit2int bit2oct bit2str char2int char2oct encvalue" +258" decomp decvalue float2int float2str hex2bit hex2int" +259" hex2oct hex2str int2bit int2char int2float int2hex" +260" int2oct int2str int2unichar isbound ischosen ispresent" +261" isvalue lengthof log2str oct2bit oct2char oct2hex oct2int" +262" oct2str regexp replace rnd sizeof str2bit str2float" +263" str2hex str2int str2oct substr unichar2int unichar2char" +264" enum2int"),265types: words("anytype bitstring boolean char charstring default float" +266" hexstring integer objid octetstring universal verdicttype timer"),267timerOps: words("read running start stop timeout"),268portOps: words("call catch check clear getcall getreply halt raise receive" +269" reply send trigger"),270configOps: words("create connect disconnect done kill killed map unmap"),271verdictOps: words("getverdict setverdict"),272sutOps: words("action"),273functionOps: words("apply derefers refers"),274
275verdictConsts: words("error fail inconc none pass"),276booleanConsts: words("true false"),277otherConsts: words("null NULL omit"),278
279visibilityModifiers: words("private public friend"),280templateMatch: words("complement ifpresent subset superset permutation"),281multiLineStrings: true282});283});284