5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
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 = /[\|\^]/;
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);
35
if (/[\[\]\(\){}:=,;]/.test(ch)) {
40
if (stream.eat("-")) {
46
stream.eatWhile(/[\w\.]/);
49
if (isOperatorChar.test(ch)) {
50
stream.eatWhile(isOperatorChar);
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";
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();
76
afterNext = afterNext.toLowerCase();
77
if(afterNext == "b" || afterNext == "h" || afterNext == "o")
82
escaped = !escaped && next == "\\";
84
if (end || !(escaped || multiLineStrings))
85
state.tokenize = null;
90
function Context(indented, column, type, align, prev) {
91
this.indented = indented;
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);
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;
112
startState: function(basecolumn) {
115
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
121
token: function(stream, state) {
122
var ctx = state.context;
124
if (ctx.align == null) ctx.align = false;
125
state.indented = stream.indentation();
126
state.startOfLine = true;
128
if (stream.eatSpace()) return null;
130
var style = (state.tokenize || tokenBase)(stream, state);
131
if (style == "comment") return style;
132
if (ctx.align == null) ctx.align = true;
134
if ((curPunc == ";" || curPunc == ":" || curPunc == ",")
135
&& ctx.type == "statement"){
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);
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");
152
state.startOfLine = false;
162
function words(str) {
163
var obj = {}, words = str.split(" ");
164
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
168
CodeMirror.defineMIME("text/x-ttcn-asn", {
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" +
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" +
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 SnmpAdminString 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" +
200
accessTypes: words("not-accessible accessible-for-notify read-only" +
201
" read-create read-write"),
202
multiLineStrings: true