mode-modeler.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * Licensed Materials - Property of IBM
  3. * IBM Cognos Products: Modeling UI (C) Copyright IBM Corp. 2015, 2019
  4. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5. */
  6. // this is a model defining the syntax highlighting rules and the code complete list
  7. // for the modeler
  8. // it uses the text mode as its base mode/highlighter
  9. ace.define(
  10. "ace/mode/modeler_highlight_rules",
  11. [
  12. "require",
  13. "exports",
  14. "module",
  15. "ace/mode/modeler_resources",
  16. "ace/lib/oop",
  17. "ace/lib/lang",
  18. "ace/mode/text_highlight_rules"
  19. ], function(
  20. require,
  21. exports,
  22. module
  23. ) {
  24. var oop = require("../lib/oop");
  25. var Resources = require("ace/mode/modeler_resources");
  26. require("../lib/lang");
  27. // get the text highlight so we can use it as our base, so we get bracet matching and what not
  28. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  29. // this list comes from RQPSQLKWYWORD.JAVA from XQE
  30. var keyWordsGroup = {
  31. name: Resources.get('keywordsGroup'),
  32. val: ["absolute","action","add","admin","after","alias","all","allocate","alter","any","are","array","as","asc","assertion","at","authorization","before","begin","binary","bit","blob","boolean","both","breadth","by","call","cascade","cascaded","catalog","character","check","class","clob","close","collate","collation","column","commit","completion","connect","connection","constraint","constraints","constructor","continue","corresponding","create","cross","cube","current","current_path","current_role","current_user","cursor","cycle","deallocate","declare","deferrable","deferred","delete","depth","deref","desc","describe","descriptor","destroy","destructor","deterministic","dictionary","diagnostics","disconnect","domain","drop","dynamic","each","end-exec","every","exception","exec","execute","external","false","fetch","first","foreign","found","from","free","full","function","general","get","global","go","goto","grant","group","grouping","having","host","identity","ignore","immediate","indicator","initialize","initially","inner","inout","input","into","is","isolation","iterate","join","key","language","large","last","lateral","leading","less","limit","local","locator","map","match","modifies","modify","module","names","national","natural","nchar","nclob","new","next","no","none","numeric","object","of","off","old","on","only","open","operation","option","ordinality","out","outer","output","pad","parameter","parameters","partial","path","postfix","precision","prefix","preorder","prepare","preserve","primary","prior","privileges","procedure","public","read","reads","recursive","ref","references","referencing","relative","restrict","result","return","returns","revoke","rollback","rollup","routine","savepoint","scroll","scope","search","section","select","sequence","sets","size","some","specific","specifictype","sql","sqlexception","sqlstate","sqlwarning","start","state","statement","static","structure","table","temporary","terminate","than","timezone_hour","timezone_minute","to","trailing","transaction","translation","treat","trigger","true","under","unknown","unnest","update","usage","using","values","variable","varying","view","whenever","where","with","without","work","write","zone"]
  33. };
  34. // build the regex string for the keywords
  35. var keyWordsRegExStr = "\\b(" + keyWordsGroup.val.join("|") + ")\\b";
  36. // these are the actually rules, add more as you see fit, the token is basically the CSS styling class that
  37. // will be used for the matched text, if the token value "foo" it means it will apply one class calls foo, if
  38. // it is "foo.bar" it means it will apply 2 classes foo and bar
  39. var ModelerHighlightRules = function() {
  40. var mapper = function(map, defaultToken, ignoreCase, splitChar) {
  41. var keywords = Object.create(null);
  42. Object.keys(map).forEach(function(className) {
  43. var a = map[className];
  44. if (ignoreCase)
  45. a = a.toLowerCase();
  46. var list = a.split(splitChar || "|");
  47. for (var i = list.length; i--; )
  48. keywords[list[i]] = className;
  49. });
  50. if (Object.getPrototypeOf(keywords)) {
  51. keywords.__proto__ = null;
  52. }
  53. this.$keywordList = Object.keys(keywords);
  54. map = null;
  55. return ignoreCase
  56. ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
  57. : function(value) {return keywords[value] || defaultToken; };
  58. };
  59. this.setKeywords = function(kwMap) {
  60. this.keywordRule.onMatch = mapper(kwMap, "identifier", true)
  61. }
  62. this.keywordRule = {
  63. regex : "[\\w\\-\\.]+",
  64. onMatch : function() {return "text"}
  65. }
  66. this.$rules = {
  67. start : [
  68. {
  69. token : 'comment',
  70. regex : '//.*$'
  71. },{
  72. token : 'comment-block',
  73. start : '/\\*',
  74. end : '\\*/'
  75. },{
  76. token : 'macro-block',
  77. start : '\\#',
  78. end : '\\#'
  79. },{
  80. token : 'keyword',
  81. regex : keyWordsRegExStr,
  82. caseInsensitive : true
  83. },{
  84. token : 'operator',
  85. regex : '\\+|\\-|\\*|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|='
  86. },{
  87. token : 'paren.lparen',
  88. regex : '\\(|\\[|\\{'
  89. },{
  90. token : 'paren.rparen',
  91. regex : '\\)|\\]|\\}'
  92. },{
  93. token : 'string',
  94. regex : /".*?"/
  95. },{
  96. token : 'string',
  97. regex : /'.*?'/
  98. },
  99. this.keywordRule
  100. ]
  101. };
  102. this.normalizeRules()
  103. };
  104. // do the actual inheritance
  105. oop.inherits(ModelerHighlightRules, TextHighlightRules);
  106. ModelerHighlightRules._keyWordsGroup = keyWordsGroup;
  107. exports.ModelerHighlightRules = ModelerHighlightRules;
  108. });
  109. ace.define("ace/mode/folding/modeler_rules", [], function(require, exports, module) {
  110. "use strict";
  111. var oop = require("../../lib/oop");
  112. var Range = require("../../range").Range;
  113. var BaseFoldMode = require("./fold_mode").FoldMode;
  114. var FoldMode = exports.FoldMode = function() {};
  115. oop.inherits(FoldMode, BaseFoldMode);
  116. (function() {
  117. this.foldingStartMarker = /(\()/;
  118. this.foldingEndMarker = /(\))/;
  119. var shouldFold = function(line) {
  120. var lineStartMarkerCount = (line.match(/\(/g) || []).length;
  121. var lineEndMarkerCount = (line.match(/\)/g) || []).length;
  122. return (lineStartMarkerCount > lineEndMarkerCount);
  123. };
  124. this.getFoldWidget = function(session, foldStyle, row) {
  125. return shouldFold(session.getLine(row)) ? "start" : "";
  126. };
  127. this.getFoldWidgetRange = function(session, foldStyle, row) {
  128. var line = session.getLine(row);
  129. if (shouldFold(line)) {
  130. var match = line.match(this.foldingStartMarker);
  131. if (match && match[1]) {
  132. return this.openingBracketBlock(session, match[1], row, match.index);
  133. }
  134. }
  135. };
  136. }).call(FoldMode.prototype);
  137. });
  138. ace.define("ace/mode/modeler",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/modeler_highlight_rules","ace/ext-language_tools", "ace/mode/folding/rules"], function(require, exports, module) {
  139. var oop = require("../lib/oop");
  140. var Range = require("../range").Range;
  141. // get the base text mode so we can inherit it
  142. var TextMode = require("./text").Mode;
  143. // get the highlight rules we defined
  144. var ModelerHighlightRules = require("./modeler_highlight_rules").ModelerHighlightRules;
  145. var MyFoldMode = require("./folding/modeler_rules").FoldMode;
  146. // prepare the Mode function
  147. var Mode = function() {
  148. this.HighlightRules = ModelerHighlightRules;
  149. this.foldingRules = new MyFoldMode();
  150. };
  151. // do the actual inheritance for the mode
  152. oop.inherits(Mode, TextMode);
  153. (function() {
  154. this.$id = "ace/mode/modeler";
  155. this.lineCommentStart = "//";
  156. }).call(Mode.prototype);
  157. exports.Mode = Mode;
  158. });
  159. ace.define("ace/snippets/text",["require","exports","module"], function(require, exports, module) {
  160. exports.snippetText =undefined;
  161. exports.scope = "text";
  162. });
  163. window.define(function() {
  164. return {
  165. setResources: function(res) {
  166. ace.define("ace/mode/modeler_resources",["require","exports","module"], function(require, exports, module) {
  167. exports.get = function(str) {
  168. return res.getString(str);
  169. };
  170. });
  171. }
  172. };
  173. });