LaravelTest
204 строки · 7.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("asn.1", function(config, parserConfig) {15var indentUnit = config.indentUnit,16keywords = parserConfig.keywords || {},17cmipVerbs = parserConfig.cmipVerbs || {},18compareTypes = parserConfig.compareTypes || {},19status = parserConfig.status || {},20tags = parserConfig.tags || {},21storage = parserConfig.storage || {},22modifier = parserConfig.modifier || {},23accessTypes = parserConfig.accessTypes|| {},24multiLineStrings = parserConfig.multiLineStrings,25indentStatements = parserConfig.indentStatements !== false;26var isOperatorChar = /[\|\^]/;27var curPunc;28
29function tokenBase(stream, state) {30var ch = stream.next();31if (ch == '"' || ch == "'") {32state.tokenize = tokenString(ch);33return state.tokenize(stream, state);34}35if (/[\[\]\(\){}:=,;]/.test(ch)) {36curPunc = ch;37return "punctuation";38}39if (ch == "-"){40if (stream.eat("-")) {41stream.skipToEnd();42return "comment";43}44}45if (/\d/.test(ch)) {46stream.eatWhile(/[\w\.]/);47return "number";48}49if (isOperatorChar.test(ch)) {50stream.eatWhile(isOperatorChar);51return "operator";52}53
54stream.eatWhile(/[\w\-]/);55var cur = stream.current();56if (keywords.propertyIsEnumerable(cur)) return "keyword";57if (cmipVerbs.propertyIsEnumerable(cur)) return "variable cmipVerbs";58if (compareTypes.propertyIsEnumerable(cur)) return "atom compareTypes";59if (status.propertyIsEnumerable(cur)) return "comment status";60if (tags.propertyIsEnumerable(cur)) return "variable-3 tags";61if (storage.propertyIsEnumerable(cur)) return "builtin storage";62if (modifier.propertyIsEnumerable(cur)) return "string-2 modifier";63if (accessTypes.propertyIsEnumerable(cur)) return "atom accessTypes";64
65return "variable";66}67
68function tokenString(quote) {69return function(stream, state) {70var escaped = false, next, end = false;71while ((next = stream.next()) != null) {72if (next == quote && !escaped){73var afterNext = stream.peek();74//look if the character if the quote is like the B in '10100010'B75if (afterNext){76afterNext = afterNext.toLowerCase();77if(afterNext == "b" || afterNext == "h" || afterNext == "o")78stream.next();79}80end = true; break;81}82escaped = !escaped && next == "\\";83}84if (end || !(escaped || multiLineStrings))85state.tokenize = null;86return "string";87};88}89
90function Context(indented, column, type, align, prev) {91this.indented = indented;92this.column = column;93this.type = type;94this.align = align;95this.prev = prev;96}97function pushContext(state, col, type) {98var indent = state.indented;99if (state.context && state.context.type == "statement")100indent = state.context.indented;101return state.context = new Context(indent, col, type, null, state.context);102}103function popContext(state) {104var t = state.context.type;105if (t == ")" || t == "]" || t == "}")106state.indented = state.context.indented;107return state.context = state.context.prev;108}109
110//Interface111return {112startState: function(basecolumn) {113return {114tokenize: null,115context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),116indented: 0,117startOfLine: true118};119},120
121token: function(stream, state) {122var ctx = state.context;123if (stream.sol()) {124if (ctx.align == null) ctx.align = false;125state.indented = stream.indentation();126state.startOfLine = true;127}128if (stream.eatSpace()) return null;129curPunc = null;130var style = (state.tokenize || tokenBase)(stream, state);131if (style == "comment") return style;132if (ctx.align == null) ctx.align = true;133
134if ((curPunc == ";" || curPunc == ":" || curPunc == ",")135&& ctx.type == "statement"){136popContext(state);137}138else if (curPunc == "{") pushContext(state, stream.column(), "}");139else if (curPunc == "[") pushContext(state, stream.column(), "]");140else if (curPunc == "(") pushContext(state, stream.column(), ")");141else if (curPunc == "}") {142while (ctx.type == "statement") ctx = popContext(state);143if (ctx.type == "}") ctx = popContext(state);144while (ctx.type == "statement") ctx = popContext(state);145}146else if (curPunc == ctx.type) popContext(state);147else if (indentStatements && (((ctx.type == "}" || ctx.type == "top")148&& curPunc != ';') || (ctx.type == "statement"149&& curPunc == "newstatement")))150pushContext(state, stream.column(), "statement");151
152state.startOfLine = false;153return style;154},155
156electricChars: "{}",157lineComment: "--",158fold: "brace"159};160});161
162function words(str) {163var obj = {}, words = str.split(" ");164for (var i = 0; i < words.length; ++i) obj[words[i]] = true;165return obj;166}167
168CodeMirror.defineMIME("text/x-ttcn-asn", {169name: "asn.1",170keywords: words("DEFINITIONS OBJECTS IF DERIVED INFORMATION ACTION" +171" REPLY ANY NAMED CHARACTERIZED BEHAVIOUR REGISTERED" +172" WITH AS IDENTIFIED CONSTRAINED BY PRESENT BEGIN" +173" IMPORTS FROM UNITS SYNTAX MIN-ACCESS MAX-ACCESS" +174" MINACCESS MAXACCESS REVISION STATUS DESCRIPTION" +175" SEQUENCE SET COMPONENTS OF CHOICE DistinguishedName" +176" ENUMERATED SIZE MODULE END INDEX AUGMENTS EXTENSIBILITY" +177" IMPLIED EXPORTS"),178cmipVerbs: words("ACTIONS ADD GET NOTIFICATIONS REPLACE REMOVE"),179compareTypes: words("OPTIONAL DEFAULT MANAGED MODULE-TYPE MODULE_IDENTITY" +180" MODULE-COMPLIANCE OBJECT-TYPE OBJECT-IDENTITY" +181" OBJECT-COMPLIANCE MODE CONFIRMED CONDITIONAL" +182" SUBORDINATE SUPERIOR CLASS TRUE FALSE NULL" +183" TEXTUAL-CONVENTION"),184status: words("current deprecated mandatory obsolete"),185tags: words("APPLICATION AUTOMATIC EXPLICIT IMPLICIT PRIVATE TAGS" +186" UNIVERSAL"),187storage: words("BOOLEAN INTEGER OBJECT IDENTIFIER BIT OCTET STRING" +188" UTCTime InterfaceIndex IANAifType CMIP-Attribute" +189" REAL PACKAGE PACKAGES IpAddress PhysAddress" +190" NetworkAddress BITS BMPString TimeStamp TimeTicks" +191" TruthValue RowStatus DisplayString GeneralString" +192" GraphicString IA5String NumericString" +193" PrintableString SnmpAdminString TeletexString" +194" UTF8String VideotexString VisibleString StringStore" +195" ISO646String T61String UniversalString Unsigned32" +196" Integer32 Gauge Gauge32 Counter Counter32 Counter64"),197modifier: words("ATTRIBUTE ATTRIBUTES MANDATORY-GROUP MANDATORY-GROUPS" +198" GROUP GROUPS ELEMENTS EQUALITY ORDERING SUBSTRINGS" +199" DEFINED"),200accessTypes: words("not-accessible accessible-for-notify read-only" +201" read-create read-write"),202multiLineStrings: true203});204});205