123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Modeling UI (C) Copyright IBM Corp. 2018, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- // this is a model defining the syntax highlighting rules and the code complete list
- // for the sql modeler
- // it uses the text mode as its base mode/highlighter
- ace.define(
- "ace/mode/modeler_sql_highlight_rules",
- [
- "require",
- "exports",
- "module",
- "ace/mode/modeler_resources",
- "ace/lib/oop",
- "ace/lib/lang",
- "ace/mode/text_highlight_rules"
- ], function(
- require,
- exports,
- module
- ) {
- var oop = require("../lib/oop");
- var Resources = require("ace/mode/modeler_resources");
- require("../lib/lang");
- // get the text highlight so we can use it as our base, so we get bracet matching and what not
- var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
- // this list comes from RQPSQLKWYWORD.JAVA from XQE
- var keyWordsGroup = {
- name: Resources.get('keywordsGroup'),
- val: ["absolute","action","add","admin","after","alias","all","allocate","alter","and","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","left","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","or","order","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","right","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","union","unknown","unnest","update","usage","using","values","variable","varying","view","whenever","where","with","without","work","write","zone"]
- };
- // build the regex string for the keywords
- var keyWordsRegExStr = "\\b(" + keyWordsGroup.val.join("|") + ")\\b";
- // these are the actually rules, add more as you see fit, the token is basically the CSS styling class that
- // will be used for the matched text, if the token value "foo" it means it will apply one class calls foo, if
- // it is "foo.bar" it means it will apply 2 classes foo and bar
- var ModelerHighlightRules = function() {
- var mapper = function(map, defaultToken, ignoreCase, splitChar) {
- var keywords = Object.create(null);
- Object.keys(map).forEach(function(className) {
- var a = map[className];
- if (ignoreCase)
- a = a.toLowerCase();
- var list = a.split(splitChar || "|");
- for (var i = list.length; i--; )
- keywords[list[i]] = className;
- });
- if (Object.getPrototypeOf(keywords)) {
- keywords.__proto__ = null;
- }
- this.$keywordList = Object.keys(keywords);
- map = null;
- return ignoreCase
- ? function(value) {return keywords[value.toLowerCase()] || defaultToken; }
- : function(value) {return keywords[value] || defaultToken; };
- };
- this.setKeywords = function(kwMap) {
- this.keywordRule.onMatch = mapper(kwMap, "identifier", true)
- }
- this.keywordRule = {
- regex : "[\\w\\-\\.]+",
- onMatch : function() {return "text"}
- }
- this.$rules = {
- start : [
- {
- token : 'comment',
- regex : '--.*$'
- },{
- token : 'comment-block',
- start : '/\\*',
- end : '\\*/'
- },{
- token : 'macro-block',
- start : '\\#',
- end : '\\#'
- },{
- token : 'keyword',
- regex : keyWordsRegExStr,
- caseInsensitive : true
- },{
- token : 'operator',
- regex : '\\+|\\-|\\*|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|='
- },{
- token : 'paren.lparen',
- regex : '\\(|\\[|\\{'
- },{
- token : 'paren.rparen',
- regex : '\\)|\\]|\\}'
- },{
- token : 'string',
- regex : /".*?"/
- },{
- token : 'string',
- regex : /'.*?'/
- },
- this.keywordRule
- ]
- };
- this.normalizeRules()
- };
- // do the actual inheritance
- oop.inherits(ModelerHighlightRules, TextHighlightRules);
- ModelerHighlightRules._keyWordsGroup = keyWordsGroup;
- exports.ModelerHighlightRules = ModelerHighlightRules;
- });
- ace.define("ace/mode/folding/modeler_sql_rules", [], function(require, exports, module) {
- "use strict";
- var oop = require("../../lib/oop");
- var Range = require("../../range").Range;
- var BaseFoldMode = require("./fold_mode").FoldMode;
- var FoldMode = exports.FoldMode = function() {};
- oop.inherits(FoldMode, BaseFoldMode);
- (function() {
- this.foldingStartMarker = /(\()/;
- this.foldingEndMarker = /(\))/;
- var shouldFold = function(line) {
- var lineStartMarkerCount = (line.match(/\(/g) || []).length;
- var lineEndMarkerCount = (line.match(/\)/g) || []).length;
- return (lineStartMarkerCount > lineEndMarkerCount);
- }
- this.getFoldWidgetRange = function(session, foldStyle, row) {
- var line = session.getLine(row);
- if(shouldFold(line)) {
- var match = line.match(this.foldingStartMarker);
- if (match && match[1]) {
- return this.openingBracketBlock(session, match[1], row, match.index);
- }
- } else {
- var range = this.indentationBlock(session, row);
- if (range)
- return range;
-
- var re = /\S/;
- var startLevel = line.search(re);
- if (startLevel == -1)
- return;
-
- var startColumn = line.length;
- var maxRow = session.getLength();
- var startRow = row;
- var endRow = row;
-
- while (++row < maxRow) {
- line = session.getLine(row);
- var level = line.search(re);
-
- if (level == -1)
- continue;
-
- endRow = row;
- }
-
- if (endRow > startRow) {
- var endColumn = session.getLine(endRow).length;
- return new Range(startRow, startColumn, endRow, endColumn);
- }
- }
-
- };
-
- // must return "" if there's no fold, to enable caching
- this.getFoldWidget = function(session, foldStyle, row) {
- var line = session.getLine(row);
- var indent = line.search(/\S/);
- var next = session.getLine(row + 1);
- var prev = session.getLine(row - 1);
- var prevIndent = prev.search(/\S/);
- var nextIndent = next.search(/\S/);
- if(shouldFold(line)) {
- return "start";
- }
-
- if (indent == -1) {
- session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
- return "";
- }
-
- if (prevIndent!= -1 && prevIndent < indent && !prev.search(/\(/))
- session.foldWidgets[row - 1] = "start";
-
- if (indent < nextIndent)
- return "start";
- else
- return "";
- };
- }).call(FoldMode.prototype);
- });
- ace.define("ace/mode/modeler-sql",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/modeler_sql_highlight_rules","ace/ext-language_tools", "ace/mode/folding/rules"], function(require, exports, module) {
- var oop = require("../lib/oop");
- var Range = require("../range").Range;
- // get the base text mode so we can inherit it
- var TextMode = require("./text").Mode;
- // get the highlight rules we defined
- var ModelerHighlightRules = require("./modeler_sql_highlight_rules").ModelerHighlightRules;
- var MyFoldMode = require("./folding/modeler_sql_rules").FoldMode;
- // prepare the Mode function
- var Mode = function() {
- this.HighlightRules = ModelerHighlightRules;
- this.foldingRules = new MyFoldMode();
- };
- // do the actual inheritance for the mode
- oop.inherits(Mode, TextMode);
- (function() {
- this.$id = "ace/mode/modeler-sql";
- this.lineCommentStart = "--";
- }).call(Mode.prototype);
- exports.Mode = Mode;
- });
- ace.define("ace/snippets/text",["require","exports","module"], function(require, exports, module) {
- exports.snippetText =undefined;
- exports.scope = "text";
- });
- window.define(function() {
- return {
- setResources: function(res) {
- ace.define("ace/mode/modeler_resources",["require","exports","module"], function(require, exports, module) {
- exports.get = function(str) {
- return res.getString(str);
- };
- });
- }
- };
- });
|