File modules/editor/codemirror/mode/asn.1/asn.1.js

Last commit: Sun Dec 17 01:14:09 2017 +0100	Jan Dankert	Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 // Distributed under an MIT license: http://codemirror.net/LICENSE 3 4 (function(mod) { 5 if (typeof exports == "object" && typeof module == "object") // CommonJS 6 mod(require("../../lib/codemirror")); 7 else if (typeof define == "function" && define.amd) // AMD 8 define(["../../lib/codemirror"], mod); 9 else // Plain browser env 10 mod(CodeMirror); 11 })(function(CodeMirror) { 12 "use strict"; 13 14 CodeMirror.defineMode("asn.1", function(config, parserConfig) { 15 var indentUnit = config.indentUnit, 16 keywords = parserConfig.keywords || {}, 17 cmipVerbs = parserConfig.cmipVerbs || {}, 18 compareTypes = parserConfig.compareTypes || {}, 19 status = parserConfig.status || {}, 20 tags = parserConfig.tags || {}, 21 storage = parserConfig.storage || {}, 22 modifier = parserConfig.modifier || {}, 23 accessTypes = parserConfig.accessTypes|| {}, 24 multiLineStrings = parserConfig.multiLineStrings, 25 indentStatements = parserConfig.indentStatements !== false; 26 var isOperatorChar = /[\|\^]/; 27 var curPunc; 28 29 function tokenBase(stream, state) { 30 var ch = stream.next(); 31 if (ch == '"' || ch == "'") { 32 state.tokenize = tokenString(ch); 33 return state.tokenize(stream, state); 34 } 35 if (/[\[\]\(\){}:=,;]/.test(ch)) { 36 curPunc = ch; 37 return "punctuation"; 38 } 39 if (ch == "-"){ 40 if (stream.eat("-")) { 41 stream.skipToEnd(); 42 return "comment"; 43 } 44 } 45 if (/\d/.test(ch)) { 46 stream.eatWhile(/[\w\.]/); 47 return "number"; 48 } 49 if (isOperatorChar.test(ch)) { 50 stream.eatWhile(isOperatorChar); 51 return "operator"; 52 } 53 54 stream.eatWhile(/[\w\-]/); 55 var cur = stream.current(); 56 if (keywords.propertyIsEnumerable(cur)) return "keyword"; 57 if (cmipVerbs.propertyIsEnumerable(cur)) return "variable cmipVerbs"; 58 if (compareTypes.propertyIsEnumerable(cur)) return "atom compareTypes"; 59 if (status.propertyIsEnumerable(cur)) return "comment status"; 60 if (tags.propertyIsEnumerable(cur)) return "variable-3 tags"; 61 if (storage.propertyIsEnumerable(cur)) return "builtin storage"; 62 if (modifier.propertyIsEnumerable(cur)) return "string-2 modifier"; 63 if (accessTypes.propertyIsEnumerable(cur)) return "atom accessTypes"; 64 65 return "variable"; 66 } 67 68 function tokenString(quote) { 69 return function(stream, state) { 70 var escaped = false, next, end = false; 71 while ((next = stream.next()) != null) { 72 if (next == quote && !escaped){ 73 var afterNext = stream.peek(); 74 //look if the character if the quote is like the B in '10100010'B 75 if (afterNext){ 76 afterNext = afterNext.toLowerCase(); 77 if(afterNext == "b" || afterNext == "h" || afterNext == "o") 78 stream.next(); 79 } 80 end = true; break; 81 } 82 escaped = !escaped && next == "\\"; 83 } 84 if (end || !(escaped || multiLineStrings)) 85 state.tokenize = null; 86 return "string"; 87 }; 88 } 89 90 function Context(indented, column, type, align, prev) { 91 this.indented = indented; 92 this.column = column; 93 this.type = type; 94 this.align = align; 95 this.prev = prev; 96 } 97 function pushContext(state, col, type) { 98 var indent = state.indented; 99 if (state.context && state.context.type == "statement") 100 indent = state.context.indented; 101 return state.context = new Context(indent, col, type, null, state.context); 102 } 103 function popContext(state) { 104 var t = state.context.type; 105 if (t == ")" || t == "]" || t == "}") 106 state.indented = state.context.indented; 107 return state.context = state.context.prev; 108 } 109 110 //Interface 111 return { 112 startState: function(basecolumn) { 113 return { 114 tokenize: null, 115 context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), 116 indented: 0, 117 startOfLine: true 118 }; 119 }, 120 121 token: function(stream, state) { 122 var ctx = state.context; 123 if (stream.sol()) { 124 if (ctx.align == null) ctx.align = false; 125 state.indented = stream.indentation(); 126 state.startOfLine = true; 127 } 128 if (stream.eatSpace()) return null; 129 curPunc = null; 130 var style = (state.tokenize || tokenBase)(stream, state); 131 if (style == "comment") return style; 132 if (ctx.align == null) ctx.align = true; 133 134 if ((curPunc == ";" || curPunc == ":" || curPunc == ",") 135 && ctx.type == "statement"){ 136 popContext(state); 137 } 138 else if (curPunc == "{") pushContext(state, stream.column(), "}"); 139 else if (curPunc == "[") pushContext(state, stream.column(), "]"); 140 else if (curPunc == "(") pushContext(state, stream.column(), ")"); 141 else if (curPunc == "}") { 142 while (ctx.type == "statement") ctx = popContext(state); 143 if (ctx.type == "}") ctx = popContext(state); 144 while (ctx.type == "statement") ctx = popContext(state); 145 } 146 else if (curPunc == ctx.type) popContext(state); 147 else if (indentStatements && (((ctx.type == "}" || ctx.type == "top") 148 && curPunc != ';') || (ctx.type == "statement" 149 && curPunc == "newstatement"))) 150 pushContext(state, stream.column(), "statement"); 151 152 state.startOfLine = false; 153 return style; 154 }, 155 156 electricChars: "{}", 157 lineComment: "--", 158 fold: "brace" 159 }; 160 }); 161 162 function words(str) { 163 var obj = {}, words = str.split(" "); 164 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 165 return obj; 166 } 167 168 CodeMirror.defineMIME("text/x-ttcn-asn", { 169 name: "asn.1", 170 keywords: 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"), 178 cmipVerbs: words("ACTIONS ADD GET NOTIFICATIONS REPLACE REMOVE"), 179 compareTypes: 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"), 184 status: words("current deprecated mandatory obsolete"), 185 tags: words("APPLICATION AUTOMATIC EXPLICIT IMPLICIT PRIVATE TAGS" + 186 " UNIVERSAL"), 187 storage: 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 SnmpAdminAtring TeletexString" + 194 " UTF8String VideotexString VisibleString StringStore" + 195 " ISO646String T61String UniversalString Unsigned32" + 196 " Integer32 Gauge Gauge32 Counter Counter32 Counter64"), 197 modifier: words("ATTRIBUTE ATTRIBUTES MANDATORY-GROUP MANDATORY-GROUPS" + 198 " GROUP GROUPS ELEMENTS EQUALITY ORDERING SUBSTRINGS" + 199 " DEFINED"), 200 accessTypes: words("not-accessible accessible-for-notify read-only" + 201 " read-create read-write"), 202 multiLineStrings: true 203 }); 204 });
Download modules/editor/codemirror/mode/asn.1/asn.1.js
History Sun, 17 Dec 2017 01:14:09 +0100 Jan Dankert Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.