openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ttcn-cfg.js (7857B)


      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("ttcn-cfg", function(config, parserConfig) {
     15     var indentUnit = config.indentUnit,
     16         keywords = parserConfig.keywords || {},
     17         fileNCtrlMaskOptions = parserConfig.fileNCtrlMaskOptions || {},
     18         externalCommands = parserConfig.externalCommands || {},
     19         multiLineStrings = parserConfig.multiLineStrings,
     20         indentStatements = parserConfig.indentStatements !== false;
     21     var isOperatorChar = /[\|]/;
     22     var curPunc;
     23 
     24     function tokenBase(stream, state) {
     25       var ch = stream.next();
     26       if (ch == '"' || ch == "'") {
     27         state.tokenize = tokenString(ch);
     28         return state.tokenize(stream, state);
     29       }
     30       if (/[:=]/.test(ch)) {
     31         curPunc = ch;
     32         return "punctuation";
     33       }
     34       if (ch == "#"){
     35         stream.skipToEnd();
     36         return "comment";
     37       }
     38       if (/\d/.test(ch)) {
     39         stream.eatWhile(/[\w\.]/);
     40         return "number";
     41       }
     42       if (isOperatorChar.test(ch)) {
     43         stream.eatWhile(isOperatorChar);
     44         return "operator";
     45       }
     46       if (ch == "["){
     47         stream.eatWhile(/[\w_\]]/);
     48         return "number sectionTitle";
     49       }
     50 
     51       stream.eatWhile(/[\w\$_]/);
     52       var cur = stream.current();
     53       if (keywords.propertyIsEnumerable(cur)) return "keyword";
     54       if (fileNCtrlMaskOptions.propertyIsEnumerable(cur))
     55         return "negative fileNCtrlMaskOptions";
     56       if (externalCommands.propertyIsEnumerable(cur)) return "negative externalCommands";
     57 
     58       return "variable";
     59     }
     60 
     61     function tokenString(quote) {
     62       return function(stream, state) {
     63         var escaped = false, next, end = false;
     64         while ((next = stream.next()) != null) {
     65           if (next == quote && !escaped){
     66             var afterNext = stream.peek();
     67             //look if the character if the quote is like the B in '10100010'B
     68             if (afterNext){
     69               afterNext = afterNext.toLowerCase();
     70               if(afterNext == "b" || afterNext == "h" || afterNext == "o")
     71                 stream.next();
     72             }
     73             end = true; break;
     74           }
     75           escaped = !escaped && next == "\\";
     76         }
     77         if (end || !(escaped || multiLineStrings))
     78           state.tokenize = null;
     79         return "string";
     80       };
     81     }
     82 
     83     function Context(indented, column, type, align, prev) {
     84       this.indented = indented;
     85       this.column = column;
     86       this.type = type;
     87       this.align = align;
     88       this.prev = prev;
     89     }
     90     function pushContext(state, col, type) {
     91       var indent = state.indented;
     92       if (state.context && state.context.type == "statement")
     93         indent = state.context.indented;
     94       return state.context = new Context(indent, col, type, null, state.context);
     95     }
     96     function popContext(state) {
     97       var t = state.context.type;
     98       if (t == ")" || t == "]" || t == "}")
     99         state.indented = state.context.indented;
    100       return state.context = state.context.prev;
    101     }
    102 
    103     //Interface
    104     return {
    105       startState: function(basecolumn) {
    106         return {
    107           tokenize: null,
    108           context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
    109           indented: 0,
    110           startOfLine: true
    111         };
    112       },
    113 
    114       token: function(stream, state) {
    115         var ctx = state.context;
    116         if (stream.sol()) {
    117           if (ctx.align == null) ctx.align = false;
    118           state.indented = stream.indentation();
    119           state.startOfLine = true;
    120         }
    121         if (stream.eatSpace()) return null;
    122         curPunc = null;
    123         var style = (state.tokenize || tokenBase)(stream, state);
    124         if (style == "comment") return style;
    125         if (ctx.align == null) ctx.align = true;
    126 
    127         if ((curPunc == ";" || curPunc == ":" || curPunc == ",")
    128             && ctx.type == "statement"){
    129           popContext(state);
    130         }
    131         else if (curPunc == "{") pushContext(state, stream.column(), "}");
    132         else if (curPunc == "[") pushContext(state, stream.column(), "]");
    133         else if (curPunc == "(") pushContext(state, stream.column(), ")");
    134         else if (curPunc == "}") {
    135           while (ctx.type == "statement") ctx = popContext(state);
    136           if (ctx.type == "}") ctx = popContext(state);
    137           while (ctx.type == "statement") ctx = popContext(state);
    138         }
    139         else if (curPunc == ctx.type) popContext(state);
    140         else if (indentStatements && (((ctx.type == "}" || ctx.type == "top")
    141             && curPunc != ';') || (ctx.type == "statement"
    142             && curPunc == "newstatement")))
    143           pushContext(state, stream.column(), "statement");
    144         state.startOfLine = false;
    145         return style;
    146       },
    147 
    148       electricChars: "{}",
    149       lineComment: "#",
    150       fold: "brace"
    151     };
    152   });
    153 
    154   function words(str) {
    155     var obj = {}, words = str.split(" ");
    156     for (var i = 0; i < words.length; ++i)
    157       obj[words[i]] = true;
    158     return obj;
    159   }
    160 
    161   CodeMirror.defineMIME("text/x-ttcn-cfg", {
    162     name: "ttcn-cfg",
    163     keywords: words("Yes No LogFile FileMask ConsoleMask AppendFile" +
    164     " TimeStampFormat LogEventTypes SourceInfoFormat" +
    165     " LogEntityName LogSourceInfo DiskFullAction" +
    166     " LogFileNumber LogFileSize MatchingHints Detailed" +
    167     " Compact SubCategories Stack Single None Seconds" +
    168     " DateTime Time Stop Error Retry Delete TCPPort KillTimer" +
    169     " NumHCs UnixSocketsEnabled LocalAddress"),
    170     fileNCtrlMaskOptions: words("TTCN_EXECUTOR TTCN_ERROR TTCN_WARNING" +
    171     " TTCN_PORTEVENT TTCN_TIMEROP TTCN_VERDICTOP" +
    172     " TTCN_DEFAULTOP TTCN_TESTCASE TTCN_ACTION" +
    173     " TTCN_USER TTCN_FUNCTION TTCN_STATISTICS" +
    174     " TTCN_PARALLEL TTCN_MATCHING TTCN_DEBUG" +
    175     " EXECUTOR ERROR WARNING PORTEVENT TIMEROP" +
    176     " VERDICTOP DEFAULTOP TESTCASE ACTION USER" +
    177     " FUNCTION STATISTICS PARALLEL MATCHING DEBUG" +
    178     " LOG_ALL LOG_NOTHING ACTION_UNQUALIFIED" +
    179     " DEBUG_ENCDEC DEBUG_TESTPORT" +
    180     " DEBUG_UNQUALIFIED DEFAULTOP_ACTIVATE" +
    181     " DEFAULTOP_DEACTIVATE DEFAULTOP_EXIT" +
    182     " DEFAULTOP_UNQUALIFIED ERROR_UNQUALIFIED" +
    183     " EXECUTOR_COMPONENT EXECUTOR_CONFIGDATA" +
    184     " EXECUTOR_EXTCOMMAND EXECUTOR_LOGOPTIONS" +
    185     " EXECUTOR_RUNTIME EXECUTOR_UNQUALIFIED" +
    186     " FUNCTION_RND FUNCTION_UNQUALIFIED" +
    187     " MATCHING_DONE MATCHING_MCSUCCESS" +
    188     " MATCHING_MCUNSUCC MATCHING_MMSUCCESS" +
    189     " MATCHING_MMUNSUCC MATCHING_PCSUCCESS" +
    190     " MATCHING_PCUNSUCC MATCHING_PMSUCCESS" +
    191     " MATCHING_PMUNSUCC MATCHING_PROBLEM" +
    192     " MATCHING_TIMEOUT MATCHING_UNQUALIFIED" +
    193     " PARALLEL_PORTCONN PARALLEL_PORTMAP" +
    194     " PARALLEL_PTC PARALLEL_UNQUALIFIED" +
    195     " PORTEVENT_DUALRECV PORTEVENT_DUALSEND" +
    196     " PORTEVENT_MCRECV PORTEVENT_MCSEND" +
    197     " PORTEVENT_MMRECV PORTEVENT_MMSEND" +
    198     " PORTEVENT_MQUEUE PORTEVENT_PCIN" +
    199     " PORTEVENT_PCOUT PORTEVENT_PMIN" +
    200     " PORTEVENT_PMOUT PORTEVENT_PQUEUE" +
    201     " PORTEVENT_STATE PORTEVENT_UNQUALIFIED" +
    202     " STATISTICS_UNQUALIFIED STATISTICS_VERDICT" +
    203     " TESTCASE_FINISH TESTCASE_START" +
    204     " TESTCASE_UNQUALIFIED TIMEROP_GUARD" +
    205     " TIMEROP_READ TIMEROP_START TIMEROP_STOP" +
    206     " TIMEROP_TIMEOUT TIMEROP_UNQUALIFIED" +
    207     " USER_UNQUALIFIED VERDICTOP_FINAL" +
    208     " VERDICTOP_GETVERDICT VERDICTOP_SETVERDICT" +
    209     " VERDICTOP_UNQUALIFIED WARNING_UNQUALIFIED"),
    210     externalCommands: words("BeginControlPart EndControlPart BeginTestCase" +
    211     " EndTestCase"),
    212     multiLineStrings: true
    213   });
    214 });