mode-logiql.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. ace.define("ace/mode/logiql_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var LogiQLHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { token: 'comment.block',
  8. regex: '/\\*',
  9. push:
  10. [ { token: 'comment.block', regex: '\\*/', next: 'pop' },
  11. { defaultToken: 'comment.block' } ]
  12. },
  13. { token: 'comment.single',
  14. regex: '//.*'
  15. },
  16. { token: 'constant.numeric',
  17. regex: '\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?[fd]?'
  18. },
  19. { token: 'string',
  20. regex: '"',
  21. push:
  22. [ { token: 'string', regex: '"', next: 'pop' },
  23. { defaultToken: 'string' } ]
  24. },
  25. { token: 'constant.language',
  26. regex: '\\b(true|false)\\b'
  27. },
  28. { token: 'entity.name.type.logicblox',
  29. regex: '`[a-zA-Z_:]+(\\d|\\a)*\\b'
  30. },
  31. { token: 'keyword.start', regex: '->', comment: 'Constraint' },
  32. { token: 'keyword.start', regex: '-->', comment: 'Level 1 Constraint'},
  33. { token: 'keyword.start', regex: '<-', comment: 'Rule' },
  34. { token: 'keyword.start', regex: '<--', comment: 'Level 1 Rule' },
  35. { token: 'keyword.end', regex: '\\.', comment: 'Terminator' },
  36. { token: 'keyword.other', regex: '!', comment: 'Negation' },
  37. { token: 'keyword.other', regex: ',', comment: 'Conjunction' },
  38. { token: 'keyword.other', regex: ';', comment: 'Disjunction' },
  39. { token: 'keyword.operator', regex: '<=|>=|!=|<|>', comment: 'Equality'},
  40. { token: 'keyword.other', regex: '@', comment: 'Equality' },
  41. { token: 'keyword.operator', regex: '\\+|-|\\*|/', comment: 'Arithmetic operations'},
  42. { token: 'keyword', regex: '::', comment: 'Colon colon' },
  43. { token: 'support.function',
  44. regex: '\\b(agg\\s*<<)',
  45. push:
  46. [ { include: '$self' },
  47. { token: 'support.function',
  48. regex: '>>',
  49. next: 'pop' } ]
  50. },
  51. { token: 'storage.modifier',
  52. regex: '\\b(lang:[\\w:]*)'
  53. },
  54. { token: [ 'storage.type', 'text' ],
  55. regex: '(export|sealed|clauses|block|alias|alias_all)(\\s*\\()(?=`)'
  56. },
  57. { token: 'entity.name',
  58. regex: '[a-zA-Z_][a-zA-Z_0-9:]*(@prev|@init|@final)?(?=(\\(|\\[))'
  59. },
  60. { token: 'variable.parameter',
  61. regex: '([a-zA-Z][a-zA-Z_0-9]*|_)\\s*(?=(,|\\.|<-|->|\\)|\\]|=))'
  62. } ] }
  63. this.normalizeRules();
  64. };
  65. oop.inherits(LogiQLHighlightRules, TextHighlightRules);
  66. exports.LogiQLHighlightRules = LogiQLHighlightRules;
  67. });
  68. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  69. "use strict";
  70. var oop = require("../../lib/oop");
  71. var BaseFoldMode = require("./fold_mode").FoldMode;
  72. var Range = require("../../range").Range;
  73. var FoldMode = exports.FoldMode = function() {};
  74. oop.inherits(FoldMode, BaseFoldMode);
  75. (function() {
  76. this.getFoldWidgetRange = function(session, foldStyle, row) {
  77. var range = this.indentationBlock(session, row);
  78. if (range)
  79. return range;
  80. var re = /\S/;
  81. var line = session.getLine(row);
  82. var startLevel = line.search(re);
  83. if (startLevel == -1 || line[startLevel] != "#")
  84. return;
  85. var startColumn = line.length;
  86. var maxRow = session.getLength();
  87. var startRow = row;
  88. var endRow = row;
  89. while (++row < maxRow) {
  90. line = session.getLine(row);
  91. var level = line.search(re);
  92. if (level == -1)
  93. continue;
  94. if (line[level] != "#")
  95. break;
  96. endRow = row;
  97. }
  98. if (endRow > startRow) {
  99. var endColumn = session.getLine(endRow).length;
  100. return new Range(startRow, startColumn, endRow, endColumn);
  101. }
  102. };
  103. this.getFoldWidget = function(session, foldStyle, row) {
  104. var line = session.getLine(row);
  105. var indent = line.search(/\S/);
  106. var next = session.getLine(row + 1);
  107. var prev = session.getLine(row - 1);
  108. var prevIndent = prev.search(/\S/);
  109. var nextIndent = next.search(/\S/);
  110. if (indent == -1) {
  111. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  112. return "";
  113. }
  114. if (prevIndent == -1) {
  115. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  116. session.foldWidgets[row - 1] = "";
  117. session.foldWidgets[row + 1] = "";
  118. return "start";
  119. }
  120. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  121. if (session.getLine(row - 2).search(/\S/) == -1) {
  122. session.foldWidgets[row - 1] = "start";
  123. session.foldWidgets[row + 1] = "";
  124. return "";
  125. }
  126. }
  127. if (prevIndent!= -1 && prevIndent < indent)
  128. session.foldWidgets[row - 1] = "start";
  129. else
  130. session.foldWidgets[row - 1] = "";
  131. if (indent < nextIndent)
  132. return "start";
  133. else
  134. return "";
  135. };
  136. }).call(FoldMode.prototype);
  137. });
  138. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  139. "use strict";
  140. var Range = require("../range").Range;
  141. var MatchingBraceOutdent = function() {};
  142. (function() {
  143. this.checkOutdent = function(line, input) {
  144. if (! /^\s+$/.test(line))
  145. return false;
  146. return /^\s*\}/.test(input);
  147. };
  148. this.autoOutdent = function(doc, row) {
  149. var line = doc.getLine(row);
  150. var match = line.match(/^(\s*\})/);
  151. if (!match) return 0;
  152. var column = match[1].length;
  153. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  154. if (!openBracePos || openBracePos.row == row) return 0;
  155. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  156. doc.replace(new Range(row, 0, row, column-1), indent);
  157. };
  158. this.$getIndent = function(line) {
  159. return line.match(/^\s*/)[0];
  160. };
  161. }).call(MatchingBraceOutdent.prototype);
  162. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  163. });
  164. ace.define("ace/mode/logiql",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/logiql_highlight_rules","ace/mode/folding/coffee","ace/token_iterator","ace/range","ace/mode/behaviour/cstyle","ace/mode/matching_brace_outdent"], function(require, exports, module) {
  165. "use strict";
  166. var oop = require("../lib/oop");
  167. var TextMode = require("./text").Mode;
  168. var LogiQLHighlightRules = require("./logiql_highlight_rules").LogiQLHighlightRules;
  169. var FoldMode = require("./folding/coffee").FoldMode;
  170. var TokenIterator = require("../token_iterator").TokenIterator;
  171. var Range = require("../range").Range;
  172. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  173. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  174. var Mode = function() {
  175. this.HighlightRules = LogiQLHighlightRules;
  176. this.foldingRules = new FoldMode();
  177. this.$outdent = new MatchingBraceOutdent();
  178. this.$behaviour = new CstyleBehaviour();
  179. };
  180. oop.inherits(Mode, TextMode);
  181. (function() {
  182. this.lineCommentStart = "//";
  183. this.blockComment = {start: "/*", end: "*/"};
  184. this.getNextLineIndent = function(state, line, tab) {
  185. var indent = this.$getIndent(line);
  186. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  187. var tokens = tokenizedLine.tokens;
  188. var endState = tokenizedLine.state;
  189. if (/comment|string/.test(endState))
  190. return indent;
  191. if (tokens.length && tokens[tokens.length - 1].type == "comment.single")
  192. return indent;
  193. var match = line.match();
  194. if (/(-->|<--|<-|->|{)\s*$/.test(line))
  195. indent += tab;
  196. return indent;
  197. };
  198. this.checkOutdent = function(state, line, input) {
  199. if (this.$outdent.checkOutdent(line, input))
  200. return true;
  201. if (input !== "\n" && input !== "\r\n")
  202. return false;
  203. if (!/^\s+/.test(line))
  204. return false;
  205. return true;
  206. };
  207. this.autoOutdent = function(state, doc, row) {
  208. if (this.$outdent.autoOutdent(doc, row))
  209. return;
  210. var prevLine = doc.getLine(row);
  211. var match = prevLine.match(/^\s+/);
  212. var column = prevLine.lastIndexOf(".") + 1;
  213. if (!match || !row || !column) return 0;
  214. var line = doc.getLine(row + 1);
  215. var startRange = this.getMatching(doc, {row: row, column: column});
  216. if (!startRange || startRange.start.row == row) return 0;
  217. column = match[0].length;
  218. var indent = this.$getIndent(doc.getLine(startRange.start.row));
  219. doc.replace(new Range(row + 1, 0, row + 1, column), indent);
  220. };
  221. this.getMatching = function(session, row, column) {
  222. if (row == undefined)
  223. row = session.selection.lead
  224. if (typeof row == "object") {
  225. column = row.column;
  226. row = row.row;
  227. }
  228. var startToken = session.getTokenAt(row, column);
  229. var KW_START = "keyword.start", KW_END = "keyword.end";
  230. var tok;
  231. if (!startToken)
  232. return;
  233. if (startToken.type == KW_START) {
  234. var it = new TokenIterator(session, row, column);
  235. it.step = it.stepForward;
  236. } else if (startToken.type == KW_END) {
  237. var it = new TokenIterator(session, row, column);
  238. it.step = it.stepBackward;
  239. } else
  240. return;
  241. while (tok = it.step()) {
  242. if (tok.type == KW_START || tok.type == KW_END)
  243. break;
  244. }
  245. if (!tok || tok.type == startToken.type)
  246. return;
  247. var col = it.getCurrentTokenColumn();
  248. var row = it.getCurrentTokenRow();
  249. return new Range(row, col, row, col + tok.value.length);
  250. };
  251. this.$id = "ace/mode/logiql";
  252. }).call(Mode.prototype);
  253. exports.Mode = Mode;
  254. });