| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| // CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
| // Distributed under an MIT license: http://codemirror.net/LICENSE | ||
|
|
||
| (function(mod) { | ||
| if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
| mod(require("../../lib/codemirror")); | ||
| else if (typeof define == "function" && define.amd) // AMD | ||
| define(["../../lib/codemirror"], mod); | ||
| else // Plain browser env | ||
| mod(CodeMirror); | ||
| })(function(CodeMirror) { | ||
| "use strict"; | ||
|
|
||
| CodeMirror.defineMode("asn.1", function(config, parserConfig) { | ||
| var indentUnit = config.indentUnit, | ||
| keywords = parserConfig.keywords || {}, | ||
| cmipVerbs = parserConfig.cmipVerbs || {}, | ||
| compareTypes = parserConfig.compareTypes || {}, | ||
| status = parserConfig.status || {}, | ||
| tags = parserConfig.tags || {}, | ||
| storage = parserConfig.storage || {}, | ||
| modifier = parserConfig.modifier || {}, | ||
| accessTypes = parserConfig.accessTypes|| {}, | ||
| multiLineStrings = parserConfig.multiLineStrings, | ||
| indentStatements = parserConfig.indentStatements !== false; | ||
| var isOperatorChar = /[\|\^]/; | ||
| var curPunc; | ||
|
|
||
| function tokenBase(stream, state) { | ||
| var ch = stream.next(); | ||
| if (ch == '"' || ch == "'") { | ||
| state.tokenize = tokenString(ch); | ||
| return state.tokenize(stream, state); | ||
| } | ||
| if (/[\[\]\(\){}:=,;]/.test(ch)) { | ||
| curPunc = ch; | ||
| return "punctuation"; | ||
| } | ||
| if (ch == "-"){ | ||
| if (stream.eat("-")) { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| } | ||
| if (/\d/.test(ch)) { | ||
| stream.eatWhile(/[\w\.]/); | ||
| return "number"; | ||
| } | ||
| if (isOperatorChar.test(ch)) { | ||
| stream.eatWhile(isOperatorChar); | ||
| return "operator"; | ||
| } | ||
|
|
||
| stream.eatWhile(/[\w\-]/); | ||
| var cur = stream.current(); | ||
| if (keywords.propertyIsEnumerable(cur)) return "keyword"; | ||
| if (cmipVerbs.propertyIsEnumerable(cur)) return "variable cmipVerbs"; | ||
| if (compareTypes.propertyIsEnumerable(cur)) return "atom compareTypes"; | ||
| if (status.propertyIsEnumerable(cur)) return "comment status"; | ||
| if (tags.propertyIsEnumerable(cur)) return "variable-3 tags"; | ||
| if (storage.propertyIsEnumerable(cur)) return "builtin storage"; | ||
| if (modifier.propertyIsEnumerable(cur)) return "string-2 modifier"; | ||
| if (accessTypes.propertyIsEnumerable(cur)) return "atom accessTypes"; | ||
|
|
||
| return "variable"; | ||
| } | ||
|
|
||
| function tokenString(quote) { | ||
| return function(stream, state) { | ||
| var escaped = false, next, end = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next == quote && !escaped){ | ||
| var afterNext = stream.peek(); | ||
| //look if the character if the quote is like the B in '10100010'B | ||
| if (afterNext){ | ||
| afterNext = afterNext.toLowerCase(); | ||
| if(afterNext == "b" || afterNext == "h" || afterNext == "o") | ||
| stream.next(); | ||
| } | ||
| end = true; break; | ||
| } | ||
| escaped = !escaped && next == "\\"; | ||
| } | ||
| if (end || !(escaped || multiLineStrings)) | ||
| state.tokenize = null; | ||
| return "string"; | ||
| }; | ||
| } | ||
|
|
||
| function Context(indented, column, type, align, prev) { | ||
| this.indented = indented; | ||
| this.column = column; | ||
| this.type = type; | ||
| this.align = align; | ||
| this.prev = prev; | ||
| } | ||
| function pushContext(state, col, type) { | ||
| var indent = state.indented; | ||
| if (state.context && state.context.type == "statement") | ||
| indent = state.context.indented; | ||
| return state.context = new Context(indent, col, type, null, state.context); | ||
| } | ||
| function popContext(state) { | ||
| var t = state.context.type; | ||
| if (t == ")" || t == "]" || t == "}") | ||
| state.indented = state.context.indented; | ||
| return state.context = state.context.prev; | ||
| } | ||
|
|
||
| //Interface | ||
| return { | ||
| startState: function(basecolumn) { | ||
| return { | ||
| tokenize: null, | ||
| context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | ||
| indented: 0, | ||
| startOfLine: true | ||
| }; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| var ctx = state.context; | ||
| if (stream.sol()) { | ||
| if (ctx.align == null) ctx.align = false; | ||
| state.indented = stream.indentation(); | ||
| state.startOfLine = true; | ||
| } | ||
| if (stream.eatSpace()) return null; | ||
| curPunc = null; | ||
| var style = (state.tokenize || tokenBase)(stream, state); | ||
| if (style == "comment") return style; | ||
| if (ctx.align == null) ctx.align = true; | ||
|
|
||
| if ((curPunc == ";" || curPunc == ":" || curPunc == ",") | ||
| && ctx.type == "statement"){ | ||
| popContext(state); | ||
| } | ||
| else if (curPunc == "{") pushContext(state, stream.column(), "}"); | ||
| else if (curPunc == "[") pushContext(state, stream.column(), "]"); | ||
| else if (curPunc == "(") pushContext(state, stream.column(), ")"); | ||
| else if (curPunc == "}") { | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| if (ctx.type == "}") ctx = popContext(state); | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| } | ||
| else if (curPunc == ctx.type) popContext(state); | ||
| else if (indentStatements && (((ctx.type == "}" || ctx.type == "top") | ||
| && curPunc != ';') || (ctx.type == "statement" | ||
| && curPunc == "newstatement"))) | ||
| pushContext(state, stream.column(), "statement"); | ||
|
|
||
| state.startOfLine = false; | ||
| return style; | ||
| }, | ||
|
|
||
| electricChars: "{}", | ||
| lineComment: "--", | ||
| fold: "brace" | ||
| }; | ||
| }); | ||
|
|
||
| function words(str) { | ||
| var obj = {}, words = str.split(" "); | ||
| for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | ||
| return obj; | ||
| } | ||
|
|
||
| CodeMirror.defineMIME("text/x-ttcn-asn", { | ||
| name: "asn.1", | ||
| keywords: words("DEFINITIONS OBJECTS IF DERIVED INFORMATION ACTION" + | ||
| " REPLY ANY NAMED CHARACTERIZED BEHAVIOUR REGISTERED" + | ||
| " WITH AS IDENTIFIED CONSTRAINED BY PRESENT BEGIN" + | ||
| " IMPORTS FROM UNITS SYNTAX MIN-ACCESS MAX-ACCESS" + | ||
| " MINACCESS MAXACCESS REVISION STATUS DESCRIPTION" + | ||
| " SEQUENCE SET COMPONENTS OF CHOICE DistinguishedName" + | ||
| " ENUMERATED SIZE MODULE END INDEX AUGMENTS EXTENSIBILITY" + | ||
| " IMPLIED EXPORTS"), | ||
| cmipVerbs: words("ACTIONS ADD GET NOTIFICATIONS REPLACE REMOVE"), | ||
| compareTypes: words("OPTIONAL DEFAULT MANAGED MODULE-TYPE MODULE_IDENTITY" + | ||
| " MODULE-COMPLIANCE OBJECT-TYPE OBJECT-IDENTITY" + | ||
| " OBJECT-COMPLIANCE MODE CONFIRMED CONDITIONAL" + | ||
| " SUBORDINATE SUPERIOR CLASS TRUE FALSE NULL" + | ||
| " TEXTUAL-CONVENTION"), | ||
| status: words("current deprecated mandatory obsolete"), | ||
| tags: words("APPLICATION AUTOMATIC EXPLICIT IMPLICIT PRIVATE TAGS" + | ||
| " UNIVERSAL"), | ||
| storage: words("BOOLEAN INTEGER OBJECT IDENTIFIER BIT OCTET STRING" + | ||
| " UTCTime InterfaceIndex IANAifType CMIP-Attribute" + | ||
| " REAL PACKAGE PACKAGES IpAddress PhysAddress" + | ||
| " NetworkAddress BITS BMPString TimeStamp TimeTicks" + | ||
| " TruthValue RowStatus DisplayString GeneralString" + | ||
| " GraphicString IA5String NumericString" + | ||
| " PrintableString SnmpAdminAtring TeletexString" + | ||
| " UTF8String VideotexString VisibleString StringStore" + | ||
| " ISO646String T61String UniversalString Unsigned32" + | ||
| " Integer32 Gauge Gauge32 Counter Counter32 Counter64"), | ||
| modifier: words("ATTRIBUTE ATTRIBUTES MANDATORY-GROUP MANDATORY-GROUPS" + | ||
| " GROUP GROUPS ELEMENTS EQUALITY ORDERING SUBSTRINGS" + | ||
| " DEFINED"), | ||
| accessTypes: words("not-accessible accessible-for-notify read-only" + | ||
| " read-create read-write"), | ||
| multiLineStrings: true | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: ASN.1 mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="asn.1.js"></script> | ||
| <style type="text/css"> | ||
| .CodeMirror { | ||
| border-top: 1px solid black; | ||
| border-bottom: 1px solid black; | ||
| } | ||
| </style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><h1>CodeMirror</h1> | ||
| <img id=logo src="../../doc/logo.png"> | ||
| </a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/codemirror/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One">ASN.1</a> | ||
| </ul> | ||
| </div> | ||
| <article> | ||
| <h2>ASN.1 example</h2> | ||
| <div> | ||
| <textarea id="ttcn-asn-code"> | ||
| -- | ||
| -- Sample ASN.1 Code | ||
| -- | ||
| MyModule DEFINITIONS ::= | ||
| BEGIN | ||
|
|
||
| MyTypes ::= SEQUENCE { | ||
| myObjectId OBJECT IDENTIFIER, | ||
| mySeqOf SEQUENCE OF MyInt, | ||
| myBitString BIT STRING { | ||
| muxToken(0), | ||
| modemToken(1) | ||
| } | ||
| } | ||
|
|
||
| MyInt ::= INTEGER (0..65535) | ||
|
|
||
| END | ||
| </textarea> | ||
| </div> | ||
|
|
||
| <script> | ||
| var ttcnEditor = CodeMirror.fromTextArea(document.getElementById("ttcn-asn-code"), { | ||
| lineNumbers: true, | ||
| matchBrackets: true, | ||
| mode: "text/x-ttcn-asn" | ||
| }); | ||
| ttcnEditor.setSize(400, 400); | ||
| var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; | ||
| CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; | ||
| </script> | ||
| <br/> | ||
| <p><strong>Language:</strong> Abstract Syntax Notation One | ||
| (<a href="http://www.itu.int/en/ITU-T/asn1/Pages/introduction.aspx">ASN.1</a>) | ||
| </p> | ||
| <p><strong>MIME types defined:</strong> <code>text/x-ttcn-asn</code></p> | ||
|
|
||
| <br/> | ||
| <p>The development of this mode has been sponsored by <a href="http://www.ericsson.com/">Ericsson | ||
| </a>.</p> | ||
| <p>Coded by Asmelash Tsegay Gebretsadkan </p> | ||
| </article> | ||
| </article> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
| // Distributed under an MIT license: http://codemirror.net/LICENSE | ||
|
|
||
| (function() { | ||
| var mode = CodeMirror.getMode({indentUnit: 2}, "text/x-c"); | ||
| function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | ||
|
|
||
| MT("indent", | ||
| "[variable-3 void] [def foo]([variable-3 void*] [variable a], [variable-3 int] [variable b]) {", | ||
| " [variable-3 int] [variable c] [operator =] [variable b] [operator +]", | ||
| " [number 1];", | ||
| " [keyword return] [operator *][variable a];", | ||
| "}"); | ||
|
|
||
| MT("indent_switch", | ||
| "[keyword switch] ([variable x]) {", | ||
| " [keyword case] [number 10]:", | ||
| " [keyword return] [number 20];", | ||
| " [keyword default]:", | ||
| " [variable printf]([string \"foo %c\"], [variable x]);", | ||
| "}"); | ||
|
|
||
| MT("def", | ||
| "[variable-3 void] [def foo]() {}", | ||
| "[keyword struct] [def bar]{}", | ||
| "[variable-3 int] [variable-3 *][def baz]() {}"); | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: Mathematica mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel=stylesheet href=../../lib/codemirror.css> | ||
| <script src=../../lib/codemirror.js></script> | ||
| <script src=../../addon/edit/matchbrackets.js></script> | ||
| <script src=mathematica.js></script> | ||
| <style type=text/css> | ||
| .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} | ||
| </style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/codemirror/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="#">Mathematica</a> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <article> | ||
| <h2>Mathematica mode</h2> | ||
|
|
||
|
|
||
| <textarea id="mathematicaCode"> | ||
| (* example Mathematica code *) | ||
| (* Dualisiert wird anhand einer Polarität an einer | ||
| Quadrik $x^t Q x = 0$ mit regulärer Matrix $Q$ (also | ||
| mit $det(Q) \neq 0$), z.B. die Identitätsmatrix. | ||
| $p$ ist eine Liste von Polynomen - ein Ideal. *) | ||
| dualize::"singular" = "Q must be regular: found Det[Q]==0."; | ||
| dualize[ Q_, p_ ] := Block[ | ||
| { m, n, xv, lv, uv, vars, polys, dual }, | ||
| If[Det[Q] == 0, | ||
| Message[dualize::"singular"], | ||
| m = Length[p]; | ||
| n = Length[Q] - 1; | ||
| xv = Table[Subscript[x, i], {i, 0, n}]; | ||
| lv = Table[Subscript[l, i], {i, 1, m}]; | ||
| uv = Table[Subscript[u, i], {i, 0, n}]; | ||
| (* Konstruiere Ideal polys. *) | ||
| If[m == 0, | ||
| polys = Q.uv, | ||
| polys = Join[p, Q.uv - Transpose[Outer[D, p, xv]].lv] | ||
| ]; | ||
| (* Eliminiere die ersten n + 1 + m Variablen xv und lv | ||
| aus dem Ideal polys. *) | ||
| vars = Join[xv, lv]; | ||
| dual = GroebnerBasis[polys, uv, vars]; | ||
| (* Ersetze u mit x im Ergebnis. *) | ||
| ReplaceAll[dual, Rule[u, x]] | ||
| ] | ||
| ] | ||
| </textarea> | ||
|
|
||
| <script> | ||
| var mathematicaEditor = CodeMirror.fromTextArea(document.getElementById('mathematicaCode'), { | ||
| mode: 'text/x-mathematica', | ||
| lineNumbers: true, | ||
| matchBrackets: true | ||
| }); | ||
| </script> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/x-mathematica</code> (Mathematica).</p> | ||
| </article> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
| // Distributed under an MIT license: http://codemirror.net/LICENSE | ||
|
|
||
| // Mathematica mode copyright (c) 2015 by Calin Barbat | ||
| // Based on code by Patrick Scheibe (halirutan) | ||
| // See: https://github.com/halirutan/Mathematica-Source-Highlighting/tree/master/src/lang-mma.js | ||
|
|
||
| (function(mod) { | ||
| if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
| mod(require("../../lib/codemirror")); | ||
| else if (typeof define == "function" && define.amd) // AMD | ||
| define(["../../lib/codemirror"], mod); | ||
| else // Plain browser env | ||
| mod(CodeMirror); | ||
| })(function(CodeMirror) { | ||
| "use strict"; | ||
|
|
||
| CodeMirror.defineMode('mathematica', function(_config, _parserConfig) { | ||
|
|
||
| // used pattern building blocks | ||
| var Identifier = '[a-zA-Z\\$][a-zA-Z0-9\\$]*'; | ||
| var pBase = "(?:\\d+)"; | ||
| var pFloat = "(?:\\.\\d+|\\d+\\.\\d*|\\d+)"; | ||
| var pFloatBase = "(?:\\.\\w+|\\w+\\.\\w*|\\w+)"; | ||
| var pPrecision = "(?:`(?:`?"+pFloat+")?)"; | ||
|
|
||
| // regular expressions | ||
| var reBaseForm = new RegExp('(?:'+pBase+'(?:\\^\\^'+pFloatBase+pPrecision+'?(?:\\*\\^[+-]?\\d+)?))'); | ||
| var reFloatForm = new RegExp('(?:' + pFloat + pPrecision + '?(?:\\*\\^[+-]?\\d+)?)'); | ||
| var reIdInContext = new RegExp('(?:`?)(?:' + Identifier + ')(?:`(?:' + Identifier + '))*(?:`?)'); | ||
|
|
||
| function tokenBase(stream, state) { | ||
| var ch; | ||
|
|
||
| // get next character | ||
| ch = stream.next(); | ||
|
|
||
| // string | ||
| if (ch === '"') { | ||
| state.tokenize = tokenString; | ||
| return state.tokenize(stream, state); | ||
| } | ||
|
|
||
| // comment | ||
| if (ch === '(') { | ||
| if (stream.eat('*')) { | ||
| state.commentLevel++; | ||
| state.tokenize = tokenComment; | ||
| return state.tokenize(stream, state); | ||
| } | ||
| } | ||
|
|
||
| // go back one character | ||
| stream.backUp(1); | ||
|
|
||
| // look for numbers | ||
| // Numbers in a baseform | ||
| if (stream.match(reBaseForm, true, false)) { | ||
| return 'number'; | ||
| } | ||
|
|
||
| // Mathematica numbers. Floats (1.2, .2, 1.) can have optionally a precision (`float) or an accuracy definition | ||
| // (``float). Note: while 1.2` is possible 1.2`` is not. At the end an exponent (float*^+12) can follow. | ||
| if (stream.match(reFloatForm, true, false)) { | ||
| return 'number'; | ||
| } | ||
|
|
||
| /* In[23] and Out[34] */ | ||
| if (stream.match(/(?:In|Out)\[[0-9]*\]/, true, false)) { | ||
| return 'atom'; | ||
| } | ||
|
|
||
| // usage | ||
| if (stream.match(/([a-zA-Z\$]+(?:`?[a-zA-Z0-9\$])*::usage)/, true, false)) { | ||
| return 'meta'; | ||
| } | ||
|
|
||
| // message | ||
| if (stream.match(/([a-zA-Z\$]+(?:`?[a-zA-Z0-9\$])*::[a-zA-Z\$][a-zA-Z0-9\$]*):?/, true, false)) { | ||
| return 'string-2'; | ||
| } | ||
|
|
||
| // this makes a look-ahead match for something like variable:{_Integer} | ||
| // the match is then forwarded to the mma-patterns tokenizer. | ||
| if (stream.match(/([a-zA-Z\$][a-zA-Z0-9\$]*\s*:)(?:(?:[a-zA-Z\$][a-zA-Z0-9\$]*)|(?:[^:=>~@\^\&\*\)\[\]'\?,\|])).*/, true, false)) { | ||
| return 'variable-2'; | ||
| } | ||
|
|
||
| // catch variables which are used together with Blank (_), BlankSequence (__) or BlankNullSequence (___) | ||
| // Cannot start with a number, but can have numbers at any other position. Examples | ||
| // blub__Integer, a1_, b34_Integer32 | ||
| if (stream.match(/[a-zA-Z\$][a-zA-Z0-9\$]*_+[a-zA-Z\$][a-zA-Z0-9\$]*/, true, false)) { | ||
| return 'variable-2'; | ||
| } | ||
| if (stream.match(/[a-zA-Z\$][a-zA-Z0-9\$]*_+/, true, false)) { | ||
| return 'variable-2'; | ||
| } | ||
| if (stream.match(/_+[a-zA-Z\$][a-zA-Z0-9\$]*/, true, false)) { | ||
| return 'variable-2'; | ||
| } | ||
|
|
||
| // Named characters in Mathematica, like \[Gamma]. | ||
| if (stream.match(/\\\[[a-zA-Z\$][a-zA-Z0-9\$]*\]/, true, false)) { | ||
| return 'variable-3'; | ||
| } | ||
|
|
||
| // Match all braces separately | ||
| if (stream.match(/(?:\[|\]|{|}|\(|\))/, true, false)) { | ||
| return 'bracket'; | ||
| } | ||
|
|
||
| // Catch Slots (#, ##, #3, ##9 and the V10 named slots #name). I have never seen someone using more than one digit after #, so we match | ||
| // only one. | ||
| if (stream.match(/(?:#[a-zA-Z\$][a-zA-Z0-9\$]*|#+[0-9]?)/, true, false)) { | ||
| return 'variable-2'; | ||
| } | ||
|
|
||
| // Literals like variables, keywords, functions | ||
| if (stream.match(reIdInContext, true, false)) { | ||
| return 'keyword'; | ||
| } | ||
|
|
||
| // operators. Note that operators like @@ or /; are matched separately for each symbol. | ||
| if (stream.match(/(?:\\|\+|\-|\*|\/|,|;|\.|:|@|~|=|>|<|&|\||_|`|'|\^|\?|!|%)/, true, false)) { | ||
| return 'operator'; | ||
| } | ||
|
|
||
| // everything else is an error | ||
| return 'error'; | ||
| } | ||
|
|
||
| function tokenString(stream, state) { | ||
| var next, end = false, escaped = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next === '"' && !escaped) { | ||
| end = true; | ||
| break; | ||
| } | ||
| escaped = !escaped && next === '\\'; | ||
| } | ||
| if (end && !escaped) { | ||
| state.tokenize = tokenBase; | ||
| } | ||
| return 'string'; | ||
| }; | ||
|
|
||
| function tokenComment(stream, state) { | ||
| var prev, next; | ||
| while(state.commentLevel > 0 && (next = stream.next()) != null) { | ||
| if (prev === '(' && next === '*') state.commentLevel++; | ||
| if (prev === '*' && next === ')') state.commentLevel--; | ||
| prev = next; | ||
| } | ||
| if (state.commentLevel <= 0) { | ||
| state.tokenize = tokenBase; | ||
| } | ||
| return 'comment'; | ||
| } | ||
|
|
||
| return { | ||
| startState: function() {return {tokenize: tokenBase, commentLevel: 0};}, | ||
| token: function(stream, state) { | ||
| if (stream.eatSpace()) return null; | ||
| return state.tokenize(stream, state); | ||
| }, | ||
| blockCommentStart: "(*", | ||
| blockCommentEnd: "*)" | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME('text/x-mathematica', { | ||
| name: 'mathematica' | ||
| }); | ||
|
|
||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: TTCN-CFG mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="ttcn-cfg.js"></script> | ||
| <style type="text/css"> | ||
| .CodeMirror { | ||
| border-top: 1px solid black; | ||
| border-bottom: 1px solid black; | ||
| } | ||
| </style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><h1>CodeMirror</h1> | ||
| <img id=logo src="../../doc/logo.png"> | ||
| </a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/codemirror/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="http://en.wikipedia.org/wiki/TTCN">TTCN-CFG</a> | ||
| </ul> | ||
| </div> | ||
| <article> | ||
| <h2>TTCN-CFG example</h2> | ||
| <div> | ||
| <textarea id="ttcn-cfg-code"> | ||
| [MODULE_PARAMETERS] | ||
| # This section shall contain the values of all parameters that are defined in your TTCN-3 modules. | ||
|
|
||
| [LOGGING] | ||
| # In this section you can specify the name of the log file and the classes of events | ||
| # you want to log into the file or display on console (standard error). | ||
|
|
||
| LogFile := "logs/%e.%h-%r.%s" | ||
| FileMask := LOG_ALL | DEBUG | MATCHING | ||
| ConsoleMask := ERROR | WARNING | TESTCASE | STATISTICS | PORTEVENT | ||
|
|
||
| LogSourceInfo := Yes | ||
| AppendFile := No | ||
| TimeStampFormat := DateTime | ||
| LogEventTypes := Yes | ||
| SourceInfoFormat := Single | ||
| LogEntityName := Yes | ||
|
|
||
| [TESTPORT_PARAMETERS] | ||
| # In this section you can specify parameters that are passed to Test Ports. | ||
|
|
||
| [DEFINE] | ||
| # In this section you can create macro definitions, | ||
| # that can be used in other configuration file sections except [INCLUDE]. | ||
|
|
||
| [INCLUDE] | ||
| # To use configuration settings given in other configuration files, | ||
| # the configuration files just need to be listed in this section, with their full or relative pathnames. | ||
|
|
||
| [EXTERNAL_COMMANDS] | ||
| # This section can define external commands (shell scripts) to be executed by the ETS | ||
| # whenever a control part or test case is started or terminated. | ||
|
|
||
| BeginTestCase := "" | ||
| EndTestCase := "" | ||
| BeginControlPart := "" | ||
| EndControlPart := "" | ||
|
|
||
| [EXECUTE] | ||
| # In this section you can specify what parts of your test suite you want to execute. | ||
|
|
||
| [GROUPS] | ||
| # In this section you can specify groups of hosts. These groups can be used inside the | ||
| # [COMPONENTS] section to restrict the creation of certain PTCs to a given set of hosts. | ||
|
|
||
| [COMPONENTS] | ||
| # This section consists of rules restricting the location of created PTCs. | ||
|
|
||
| [MAIN_CONTROLLER] | ||
| # The options herein control the behavior of MC. | ||
|
|
||
| TCPPort := 0 | ||
| KillTimer := 10.0 | ||
| NumHCs := 0 | ||
| LocalAddress := | ||
| </textarea> | ||
| </div> | ||
|
|
||
| <script> | ||
| var ttcnEditor = CodeMirror.fromTextArea(document.getElementById("ttcn-cfg-code"), { | ||
| lineNumbers: true, | ||
| matchBrackets: true, | ||
| mode: "text/x-ttcn-cfg" | ||
| }); | ||
| ttcnEditor.setSize(600, 860); | ||
| var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; | ||
| CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; | ||
| </script> | ||
| <br/> | ||
| <p><strong>Language:</strong> Testing and Test Control Notation - | ||
| Configuration files | ||
| (<a href="http://en.wikipedia.org/wiki/TTCN">TTCN-CFG</a>) | ||
| </p> | ||
| <p><strong>MIME types defined:</strong> <code>text/x-ttcn-cfg</code>.</p> | ||
|
|
||
| <br/> | ||
| <p>The development of this mode has been sponsored by <a href="http://www.ericsson.com/">Ericsson | ||
| </a>.</p> | ||
| <p>Coded by Asmelash Tsegay Gebretsadkan </p> | ||
| </article> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| // CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
| // Distributed under an MIT license: http://codemirror.net/LICENSE | ||
|
|
||
| (function(mod) { | ||
| if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
| mod(require("../../lib/codemirror")); | ||
| else if (typeof define == "function" && define.amd) // AMD | ||
| define(["../../lib/codemirror"], mod); | ||
| else // Plain browser env | ||
| mod(CodeMirror); | ||
| })(function(CodeMirror) { | ||
| "use strict"; | ||
|
|
||
| CodeMirror.defineMode("ttcn-cfg", function(config, parserConfig) { | ||
| var indentUnit = config.indentUnit, | ||
| keywords = parserConfig.keywords || {}, | ||
| fileNCtrlMaskOptions = parserConfig.fileNCtrlMaskOptions || {}, | ||
| externalCommands = parserConfig.externalCommands || {}, | ||
| multiLineStrings = parserConfig.multiLineStrings, | ||
| indentStatements = parserConfig.indentStatements !== false; | ||
| var isOperatorChar = /[\|]/; | ||
| var curPunc; | ||
|
|
||
| function tokenBase(stream, state) { | ||
| var ch = stream.next(); | ||
| if (ch == '"' || ch == "'") { | ||
| state.tokenize = tokenString(ch); | ||
| return state.tokenize(stream, state); | ||
| } | ||
| if (/[:=]/.test(ch)) { | ||
| curPunc = ch; | ||
| return "punctuation"; | ||
| } | ||
| if (ch == "#"){ | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| if (/\d/.test(ch)) { | ||
| stream.eatWhile(/[\w\.]/); | ||
| return "number"; | ||
| } | ||
| if (isOperatorChar.test(ch)) { | ||
| stream.eatWhile(isOperatorChar); | ||
| return "operator"; | ||
| } | ||
| if (ch == "["){ | ||
| stream.eatWhile(/[\w_\]]/); | ||
| return "number sectionTitle"; | ||
| } | ||
|
|
||
| stream.eatWhile(/[\w\$_]/); | ||
| var cur = stream.current(); | ||
| if (keywords.propertyIsEnumerable(cur)) return "keyword"; | ||
| if (fileNCtrlMaskOptions.propertyIsEnumerable(cur)) | ||
| return "negative fileNCtrlMaskOptions"; | ||
| if (externalCommands.propertyIsEnumerable(cur)) return "negative externalCommands"; | ||
|
|
||
| return "variable"; | ||
| } | ||
|
|
||
| function tokenString(quote) { | ||
| return function(stream, state) { | ||
| var escaped = false, next, end = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next == quote && !escaped){ | ||
| var afterNext = stream.peek(); | ||
| //look if the character if the quote is like the B in '10100010'B | ||
| if (afterNext){ | ||
| afterNext = afterNext.toLowerCase(); | ||
| if(afterNext == "b" || afterNext == "h" || afterNext == "o") | ||
| stream.next(); | ||
| } | ||
| end = true; break; | ||
| } | ||
| escaped = !escaped && next == "\\"; | ||
| } | ||
| if (end || !(escaped || multiLineStrings)) | ||
| state.tokenize = null; | ||
| return "string"; | ||
| }; | ||
| } | ||
|
|
||
| function Context(indented, column, type, align, prev) { | ||
| this.indented = indented; | ||
| this.column = column; | ||
| this.type = type; | ||
| this.align = align; | ||
| this.prev = prev; | ||
| } | ||
| function pushContext(state, col, type) { | ||
| var indent = state.indented; | ||
| if (state.context && state.context.type == "statement") | ||
| indent = state.context.indented; | ||
| return state.context = new Context(indent, col, type, null, state.context); | ||
| } | ||
| function popContext(state) { | ||
| var t = state.context.type; | ||
| if (t == ")" || t == "]" || t == "}") | ||
| state.indented = state.context.indented; | ||
| return state.context = state.context.prev; | ||
| } | ||
|
|
||
| //Interface | ||
| return { | ||
| startState: function(basecolumn) { | ||
| return { | ||
| tokenize: null, | ||
| context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | ||
| indented: 0, | ||
| startOfLine: true | ||
| }; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| var ctx = state.context; | ||
| if (stream.sol()) { | ||
| if (ctx.align == null) ctx.align = false; | ||
| state.indented = stream.indentation(); | ||
| state.startOfLine = true; | ||
| } | ||
| if (stream.eatSpace()) return null; | ||
| curPunc = null; | ||
| var style = (state.tokenize || tokenBase)(stream, state); | ||
| if (style == "comment") return style; | ||
| if (ctx.align == null) ctx.align = true; | ||
|
|
||
| if ((curPunc == ";" || curPunc == ":" || curPunc == ",") | ||
| && ctx.type == "statement"){ | ||
| popContext(state); | ||
| } | ||
| else if (curPunc == "{") pushContext(state, stream.column(), "}"); | ||
| else if (curPunc == "[") pushContext(state, stream.column(), "]"); | ||
| else if (curPunc == "(") pushContext(state, stream.column(), ")"); | ||
| else if (curPunc == "}") { | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| if (ctx.type == "}") ctx = popContext(state); | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| } | ||
| else if (curPunc == ctx.type) popContext(state); | ||
| else if (indentStatements && (((ctx.type == "}" || ctx.type == "top") | ||
| && curPunc != ';') || (ctx.type == "statement" | ||
| && curPunc == "newstatement"))) | ||
| pushContext(state, stream.column(), "statement"); | ||
| state.startOfLine = false; | ||
| return style; | ||
| }, | ||
|
|
||
| electricChars: "{}", | ||
| lineComment: "#", | ||
| fold: "brace" | ||
| }; | ||
| }); | ||
|
|
||
| function words(str) { | ||
| var obj = {}, words = str.split(" "); | ||
| for (var i = 0; i < words.length; ++i) | ||
| obj[words[i]] = true; | ||
| return obj; | ||
| } | ||
|
|
||
| CodeMirror.defineMIME("text/x-ttcn-cfg", { | ||
| name: "ttcn-cfg", | ||
| keywords: words("Yes No LogFile FileMask ConsoleMask AppendFile" + | ||
| " TimeStampFormat LogEventTypes SourceInfoFormat" + | ||
| " LogEntityName LogSourceInfo DiskFullAction" + | ||
| " LogFileNumber LogFileSize MatchingHints Detailed" + | ||
| " Compact SubCategories Stack Single None Seconds" + | ||
| " DateTime Time Stop Error Retry Delete TCPPort KillTimer" + | ||
| " NumHCs UnixSocketsEnabled LocalAddress"), | ||
| fileNCtrlMaskOptions: words("TTCN_EXECUTOR TTCN_ERROR TTCN_WARNING" + | ||
| " TTCN_PORTEVENT TTCN_TIMEROP TTCN_VERDICTOP" + | ||
| " TTCN_DEFAULTOP TTCN_TESTCASE TTCN_ACTION" + | ||
| " TTCN_USER TTCN_FUNCTION TTCN_STATISTICS" + | ||
| " TTCN_PARALLEL TTCN_MATCHING TTCN_DEBUG" + | ||
| " EXECUTOR ERROR WARNING PORTEVENT TIMEROP" + | ||
| " VERDICTOP DEFAULTOP TESTCASE ACTION USER" + | ||
| " FUNCTION STATISTICS PARALLEL MATCHING DEBUG" + | ||
| " LOG_ALL LOG_NOTHING ACTION_UNQUALIFIED" + | ||
| " DEBUG_ENCDEC DEBUG_TESTPORT" + | ||
| " DEBUG_UNQUALIFIED DEFAULTOP_ACTIVATE" + | ||
| " DEFAULTOP_DEACTIVATE DEFAULTOP_EXIT" + | ||
| " DEFAULTOP_UNQUALIFIED ERROR_UNQUALIFIED" + | ||
| " EXECUTOR_COMPONENT EXECUTOR_CONFIGDATA" + | ||
| " EXECUTOR_EXTCOMMAND EXECUTOR_LOGOPTIONS" + | ||
| " EXECUTOR_RUNTIME EXECUTOR_UNQUALIFIED" + | ||
| " FUNCTION_RND FUNCTION_UNQUALIFIED" + | ||
| " MATCHING_DONE MATCHING_MCSUCCESS" + | ||
| " MATCHING_MCUNSUCC MATCHING_MMSUCCESS" + | ||
| " MATCHING_MMUNSUCC MATCHING_PCSUCCESS" + | ||
| " MATCHING_PCUNSUCC MATCHING_PMSUCCESS" + | ||
| " MATCHING_PMUNSUCC MATCHING_PROBLEM" + | ||
| " MATCHING_TIMEOUT MATCHING_UNQUALIFIED" + | ||
| " PARALLEL_PORTCONN PARALLEL_PORTMAP" + | ||
| " PARALLEL_PTC PARALLEL_UNQUALIFIED" + | ||
| " PORTEVENT_DUALRECV PORTEVENT_DUALSEND" + | ||
| " PORTEVENT_MCRECV PORTEVENT_MCSEND" + | ||
| " PORTEVENT_MMRECV PORTEVENT_MMSEND" + | ||
| " PORTEVENT_MQUEUE PORTEVENT_PCIN" + | ||
| " PORTEVENT_PCOUT PORTEVENT_PMIN" + | ||
| " PORTEVENT_PMOUT PORTEVENT_PQUEUE" + | ||
| " PORTEVENT_STATE PORTEVENT_UNQUALIFIED" + | ||
| " STATISTICS_UNQUALIFIED STATISTICS_VERDICT" + | ||
| " TESTCASE_FINISH TESTCASE_START" + | ||
| " TESTCASE_UNQUALIFIED TIMEROP_GUARD" + | ||
| " TIMEROP_READ TIMEROP_START TIMEROP_STOP" + | ||
| " TIMEROP_TIMEOUT TIMEROP_UNQUALIFIED" + | ||
| " USER_UNQUALIFIED VERDICTOP_FINAL" + | ||
| " VERDICTOP_GETVERDICT VERDICTOP_SETVERDICT" + | ||
| " VERDICTOP_UNQUALIFIED WARNING_UNQUALIFIED"), | ||
| externalCommands: words("BeginControlPart EndControlPart BeginTestCase" + | ||
| " EndTestCase"), | ||
| multiLineStrings: true | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: TTCN mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="ttcn.js"></script> | ||
| <style type="text/css"> | ||
| .CodeMirror { | ||
| border-top: 1px solid black; | ||
| border-bottom: 1px solid black; | ||
| } | ||
| </style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><h1>CodeMirror</h1> | ||
| <img id=logo src="../../doc/logo.png"> | ||
| </a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/codemirror/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="http://en.wikipedia.org/wiki/TTCN">TTCN</a> | ||
| </ul> | ||
| </div> | ||
| <article> | ||
| <h2>TTCN example</h2> | ||
| <div> | ||
| <textarea id="ttcn-code"> | ||
| module Templates { | ||
| /* import types from ASN.1 */ | ||
| import from Types language "ASN.1:1997" all; | ||
|
|
||
| /* During the conversion phase from ASN.1 to TTCN-3 */ | ||
| /* - the minus sign (Message-Type) within the identifiers will be replaced by underscore (Message_Type)*/ | ||
| /* - the ASN.1 identifiers matching a TTCN-3 keyword (objid) will be postfixed with an underscore (objid_)*/ | ||
|
|
||
| // simple types | ||
|
|
||
| template SenderID localObjid := objid {itu_t(0) identified_organization(4) etsi(0)}; | ||
|
|
||
| // complex types | ||
|
|
||
| /* ASN.1 Message-Type mapped to TTCN-3 Message_Type */ | ||
| template Message receiveMsg(template (present) Message_Type p_messageType) := { | ||
| header := p_messageType, | ||
| body := ? | ||
| } | ||
|
|
||
| /* ASN.1 objid mapped to TTCN-3 objid_ */ | ||
| template Message sendInviteMsg := { | ||
| header := inviteType, | ||
| body := { | ||
| /* optional fields may be assigned by omit or may be ignored/skipped */ | ||
| description := "Invite Message", | ||
| data := 'FF'O, | ||
| objid_ := localObjid | ||
| } | ||
| } | ||
|
|
||
| template Message sendAcceptMsg modifies sendInviteMsg := { | ||
| header := acceptType, | ||
| body := { | ||
| description := "Accept Message" | ||
| } | ||
| }; | ||
|
|
||
| template Message sendErrorMsg modifies sendInviteMsg := { | ||
| header := errorType, | ||
| body := { | ||
| description := "Error Message" | ||
| } | ||
| }; | ||
|
|
||
| template Message expectedErrorMsg := { | ||
| header := errorType, | ||
| body := ? | ||
| }; | ||
|
|
||
| template Message expectedInviteMsg modifies expectedErrorMsg := { | ||
| header := inviteType | ||
| }; | ||
|
|
||
| template Message expectedAcceptMsg modifies expectedErrorMsg := { | ||
| header := acceptType | ||
| }; | ||
|
|
||
| } with { encode "BER:1997" } | ||
| </textarea> | ||
| </div> | ||
|
|
||
| <script> | ||
| var ttcnEditor = CodeMirror.fromTextArea(document.getElementById("ttcn-code"), { | ||
| lineNumbers: true, | ||
| matchBrackets: true, | ||
| mode: "text/x-ttcn" | ||
| }); | ||
| ttcnEditor.setSize(600, 860); | ||
| var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; | ||
| CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; | ||
| </script> | ||
| <br/> | ||
| <p><strong>Language:</strong> Testing and Test Control Notation | ||
| (<a href="http://en.wikipedia.org/wiki/TTCN">TTCN</a>) | ||
| </p> | ||
| <p><strong>MIME types defined:</strong> <code>text/x-ttcn, | ||
| text/x-ttcn3, text/x-ttcnpp</code>.</p> | ||
| <br/> | ||
| <p>The development of this mode has been sponsored by <a href="http://www.ericsson.com/">Ericsson | ||
| </a>.</p> | ||
| <p>Coded by Asmelash Tsegay Gebretsadkan </p> | ||
| </article> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,283 @@ | ||
| // CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
| // Distributed under an MIT license: http://codemirror.net/LICENSE | ||
|
|
||
| (function(mod) { | ||
| if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
| mod(require("../../lib/codemirror")); | ||
| else if (typeof define == "function" && define.amd) // AMD | ||
| define(["../../lib/codemirror"], mod); | ||
| else // Plain browser env | ||
| mod(CodeMirror); | ||
| })(function(CodeMirror) { | ||
| "use strict"; | ||
|
|
||
| CodeMirror.defineMode("ttcn", function(config, parserConfig) { | ||
| var indentUnit = config.indentUnit, | ||
| keywords = parserConfig.keywords || {}, | ||
| builtin = parserConfig.builtin || {}, | ||
| timerOps = parserConfig.timerOps || {}, | ||
| portOps = parserConfig.portOps || {}, | ||
| configOps = parserConfig.configOps || {}, | ||
| verdictOps = parserConfig.verdictOps || {}, | ||
| sutOps = parserConfig.sutOps || {}, | ||
| functionOps = parserConfig.functionOps || {}, | ||
|
|
||
| verdictConsts = parserConfig.verdictConsts || {}, | ||
| booleanConsts = parserConfig.booleanConsts || {}, | ||
| otherConsts = parserConfig.otherConsts || {}, | ||
|
|
||
| types = parserConfig.types || {}, | ||
| visibilityModifiers = parserConfig.visibilityModifiers || {}, | ||
| templateMatch = parserConfig.templateMatch || {}, | ||
| multiLineStrings = parserConfig.multiLineStrings, | ||
| indentStatements = parserConfig.indentStatements !== false; | ||
| var isOperatorChar = /[+\-*&@=<>!\/]/; | ||
| var curPunc; | ||
|
|
||
| function tokenBase(stream, state) { | ||
| var ch = stream.next(); | ||
|
|
||
| if (ch == '"' || ch == "'") { | ||
| state.tokenize = tokenString(ch); | ||
| return state.tokenize(stream, state); | ||
| } | ||
| if (/[\[\]{}\(\),;\\:\?\.]/.test(ch)) { | ||
| curPunc = ch; | ||
| return "punctuation"; | ||
| } | ||
| if (ch == "#"){ | ||
| stream.skipToEnd(); | ||
| return "atom preprocessor"; | ||
| } | ||
| if (ch == "%"){ | ||
| stream.eatWhile(/\b/); | ||
| return "atom ttcn3Macros"; | ||
| } | ||
| if (/\d/.test(ch)) { | ||
| stream.eatWhile(/[\w\.]/); | ||
| return "number"; | ||
| } | ||
| if (ch == "/") { | ||
| if (stream.eat("*")) { | ||
| state.tokenize = tokenComment; | ||
| return tokenComment(stream, state); | ||
| } | ||
| if (stream.eat("/")) { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| } | ||
| if (isOperatorChar.test(ch)) { | ||
| if(ch == "@"){ | ||
| if(stream.match("try") || stream.match("catch") | ||
| || stream.match("lazy")){ | ||
| return "keyword"; | ||
| } | ||
| } | ||
| stream.eatWhile(isOperatorChar); | ||
| return "operator"; | ||
| } | ||
| stream.eatWhile(/[\w\$_\xa1-\uffff]/); | ||
| var cur = stream.current(); | ||
|
|
||
| if (keywords.propertyIsEnumerable(cur)) return "keyword"; | ||
| if (builtin.propertyIsEnumerable(cur)) return "builtin"; | ||
|
|
||
| if (timerOps.propertyIsEnumerable(cur)) return "def timerOps"; | ||
| if (configOps.propertyIsEnumerable(cur)) return "def configOps"; | ||
| if (verdictOps.propertyIsEnumerable(cur)) return "def verdictOps"; | ||
| if (portOps.propertyIsEnumerable(cur)) return "def portOps"; | ||
| if (sutOps.propertyIsEnumerable(cur)) return "def sutOps"; | ||
| if (functionOps.propertyIsEnumerable(cur)) return "def functionOps"; | ||
|
|
||
| if (verdictConsts.propertyIsEnumerable(cur)) return "string verdictConsts"; | ||
| if (booleanConsts.propertyIsEnumerable(cur)) return "string booleanConsts"; | ||
| if (otherConsts.propertyIsEnumerable(cur)) return "string otherConsts"; | ||
|
|
||
| if (types.propertyIsEnumerable(cur)) return "builtin types"; | ||
| if (visibilityModifiers.propertyIsEnumerable(cur)) | ||
| return "builtin visibilityModifiers"; | ||
| if (templateMatch.propertyIsEnumerable(cur)) return "atom templateMatch"; | ||
|
|
||
| return "variable"; | ||
| } | ||
|
|
||
| function tokenString(quote) { | ||
| return function(stream, state) { | ||
| var escaped = false, next, end = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next == quote && !escaped){ | ||
| var afterQuote = stream.peek(); | ||
| //look if the character after the quote is like the B in '10100010'B | ||
| if (afterQuote){ | ||
| afterQuote = afterQuote.toLowerCase(); | ||
| if(afterQuote == "b" || afterQuote == "h" || afterQuote == "o") | ||
| stream.next(); | ||
| } | ||
| end = true; break; | ||
| } | ||
| escaped = !escaped && next == "\\"; | ||
| } | ||
| if (end || !(escaped || multiLineStrings)) | ||
| state.tokenize = null; | ||
| return "string"; | ||
| }; | ||
| } | ||
|
|
||
| function tokenComment(stream, state) { | ||
| var maybeEnd = false, ch; | ||
| while (ch = stream.next()) { | ||
| if (ch == "/" && maybeEnd) { | ||
| state.tokenize = null; | ||
| break; | ||
| } | ||
| maybeEnd = (ch == "*"); | ||
| } | ||
| return "comment"; | ||
| } | ||
|
|
||
| function Context(indented, column, type, align, prev) { | ||
| this.indented = indented; | ||
| this.column = column; | ||
| this.type = type; | ||
| this.align = align; | ||
| this.prev = prev; | ||
| } | ||
|
|
||
| function pushContext(state, col, type) { | ||
| var indent = state.indented; | ||
| if (state.context && state.context.type == "statement") | ||
| indent = state.context.indented; | ||
| return state.context = new Context(indent, col, type, null, state.context); | ||
| } | ||
|
|
||
| function popContext(state) { | ||
| var t = state.context.type; | ||
| if (t == ")" || t == "]" || t == "}") | ||
| state.indented = state.context.indented; | ||
| return state.context = state.context.prev; | ||
| } | ||
|
|
||
| //Interface | ||
| return { | ||
| startState: function(basecolumn) { | ||
| return { | ||
| tokenize: null, | ||
| context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), | ||
| indented: 0, | ||
| startOfLine: true | ||
| }; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| var ctx = state.context; | ||
| if (stream.sol()) { | ||
| if (ctx.align == null) ctx.align = false; | ||
| state.indented = stream.indentation(); | ||
| state.startOfLine = true; | ||
| } | ||
| if (stream.eatSpace()) return null; | ||
| curPunc = null; | ||
| var style = (state.tokenize || tokenBase)(stream, state); | ||
| if (style == "comment") return style; | ||
| if (ctx.align == null) ctx.align = true; | ||
|
|
||
| if ((curPunc == ";" || curPunc == ":" || curPunc == ",") | ||
| && ctx.type == "statement"){ | ||
| popContext(state); | ||
| } | ||
| else if (curPunc == "{") pushContext(state, stream.column(), "}"); | ||
| else if (curPunc == "[") pushContext(state, stream.column(), "]"); | ||
| else if (curPunc == "(") pushContext(state, stream.column(), ")"); | ||
| else if (curPunc == "}") { | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| if (ctx.type == "}") ctx = popContext(state); | ||
| while (ctx.type == "statement") ctx = popContext(state); | ||
| } | ||
| else if (curPunc == ctx.type) popContext(state); | ||
| else if (indentStatements && | ||
| (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || | ||
| (ctx.type == "statement" && curPunc == "newstatement"))) | ||
| pushContext(state, stream.column(), "statement"); | ||
|
|
||
| state.startOfLine = false; | ||
|
|
||
| return style; | ||
| }, | ||
|
|
||
| electricChars: "{}", | ||
| blockCommentStart: "/*", | ||
| blockCommentEnd: "*/", | ||
| lineComment: "//", | ||
| fold: "brace" | ||
| }; | ||
| }); | ||
|
|
||
| function words(str) { | ||
| var obj = {}, words = str.split(" "); | ||
| for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | ||
| return obj; | ||
| } | ||
|
|
||
| function def(mimes, mode) { | ||
| if (typeof mimes == "string") mimes = [mimes]; | ||
| var words = []; | ||
| function add(obj) { | ||
| if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop)) | ||
| words.push(prop); | ||
| } | ||
|
|
||
| add(mode.keywords); | ||
| add(mode.builtin); | ||
| add(mode.timerOps); | ||
| add(mode.portOps); | ||
|
|
||
| if (words.length) { | ||
| mode.helperType = mimes[0]; | ||
| CodeMirror.registerHelper("hintWords", mimes[0], words); | ||
| } | ||
|
|
||
| for (var i = 0; i < mimes.length; ++i) | ||
| CodeMirror.defineMIME(mimes[i], mode); | ||
| } | ||
|
|
||
| def(["text/x-ttcn", "text/x-ttcn3", "text/x-ttcnpp"], { | ||
| name: "ttcn", | ||
| keywords: words("activate address alive all alt altstep and and4b any" + | ||
| " break case component const continue control deactivate" + | ||
| " display do else encode enumerated except exception" + | ||
| " execute extends extension external for from function" + | ||
| " goto group if import in infinity inout interleave" + | ||
| " label language length log match message mixed mod" + | ||
| " modifies module modulepar mtc noblock not not4b nowait" + | ||
| " of on optional or or4b out override param pattern port" + | ||
| " procedure record recursive rem repeat return runs select" + | ||
| " self sender set signature system template testcase to" + | ||
| " type union value valueof var variant while with xor xor4b"), | ||
| builtin: words("bit2hex bit2int bit2oct bit2str char2int char2oct encvalue" + | ||
| " decomp decvalue float2int float2str hex2bit hex2int" + | ||
| " hex2oct hex2str int2bit int2char int2float int2hex" + | ||
| " int2oct int2str int2unichar isbound ischosen ispresent" + | ||
| " isvalue lengthof log2str oct2bit oct2char oct2hex oct2int" + | ||
| " oct2str regexp replace rnd sizeof str2bit str2float" + | ||
| " str2hex str2int str2oct substr unichar2int unichar2char" + | ||
| " enum2int"), | ||
| types: words("anytype bitstring boolean char charstring default float" + | ||
| " hexstring integer objid octetstring universal verdicttype timer"), | ||
| timerOps: words("read running start stop timeout"), | ||
| portOps: words("call catch check clear getcall getreply halt raise receive" + | ||
| " reply send trigger"), | ||
| configOps: words("create connect disconnect done kill killed map unmap"), | ||
| verdictOps: words("getverdict setverdict"), | ||
| sutOps: words("action"), | ||
| functionOps: words("apply derefers refers"), | ||
|
|
||
| verdictConsts: words("error fail inconc none pass"), | ||
| booleanConsts: words("true false"), | ||
| otherConsts: words("null NULL omit"), | ||
|
|
||
| visibilityModifiers: words("private public friend"), | ||
| templateMatch: words("complement ifpresent subset superset permutation"), | ||
| multiLineStrings: true | ||
| }); | ||
| }); |