You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
7.7 KiB

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