26fa04eabe6ca96832d5652350a2fb46.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. ace.define("ace/mode/c9search_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var lang = require("../lib/lang");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. function safeCreateRegexp(source, flag) {
  6. try {
  7. return new RegExp(source, flag);
  8. }
  9. catch (e) { }
  10. }
  11. var C9SearchHighlightRules = function () {
  12. this.$rules = {
  13. "start": [
  14. {
  15. tokenNames: ["c9searchresults.constant.numeric", "c9searchresults.text", "c9searchresults.text", "c9searchresults.keyword"],
  16. regex: /(^\s+[0-9]+)(:)(\d*\s?)([^\r\n]+)/,
  17. onMatch: function (val, state, stack) {
  18. var values = this.splitRegex.exec(val);
  19. var types = this.tokenNames;
  20. var tokens = [{
  21. type: types[0],
  22. value: values[1]
  23. }, {
  24. type: types[1],
  25. value: values[2]
  26. }];
  27. if (values[3]) {
  28. if (values[3] == " ")
  29. tokens[1] = { type: types[1], value: values[2] + " " };
  30. else
  31. tokens.push({ type: types[1], value: values[3] });
  32. }
  33. var regex = stack[1];
  34. var str = values[4];
  35. var m;
  36. var last = 0;
  37. if (regex && regex.exec) {
  38. regex.lastIndex = 0;
  39. while (m = regex.exec(str)) {
  40. var skipped = str.substring(last, m.index);
  41. last = regex.lastIndex;
  42. if (skipped)
  43. tokens.push({ type: types[2], value: skipped });
  44. if (m[0])
  45. tokens.push({ type: types[3], value: m[0] });
  46. else if (!skipped)
  47. break;
  48. }
  49. }
  50. if (last < str.length)
  51. tokens.push({ type: types[2], value: str.substr(last) });
  52. return tokens;
  53. }
  54. },
  55. {
  56. regex: "^Searching for [^\\r\\n]*$",
  57. onMatch: function (val, state, stack) {
  58. var parts = val.split("\x01");
  59. if (parts.length < 3)
  60. return "text";
  61. var options, search;
  62. var i = 0;
  63. var tokens = [{
  64. value: parts[i++] + "'",
  65. type: "text"
  66. }, {
  67. value: search = parts[i++],
  68. type: "text" // "c9searchresults.keyword"
  69. }, {
  70. value: "'" + parts[i++],
  71. type: "text"
  72. }];
  73. if (parts[2] !== " in") {
  74. tokens.push({
  75. value: "'" + parts[i++] + "'",
  76. type: "text"
  77. }, {
  78. value: parts[i++],
  79. type: "text"
  80. });
  81. }
  82. tokens.push({
  83. value: " " + parts[i++] + " ",
  84. type: "text"
  85. });
  86. if (parts[i + 1]) {
  87. options = parts[i + 1];
  88. tokens.push({
  89. value: "(" + parts[i + 1] + ")",
  90. type: "text"
  91. });
  92. i += 1;
  93. }
  94. else {
  95. i -= 1;
  96. }
  97. while (i++ < parts.length) {
  98. parts[i] && tokens.push({
  99. value: parts[i],
  100. type: "text"
  101. });
  102. }
  103. if (search) {
  104. if (!/regex/.test(options))
  105. search = lang.escapeRegExp(search);
  106. if (/whole/.test(options))
  107. search = "\\b" + search + "\\b";
  108. }
  109. var regex = search && safeCreateRegexp("(" + search + ")", / sensitive/.test(options) ? "g" : "ig");
  110. if (regex) {
  111. stack[0] = state;
  112. stack[1] = regex;
  113. }
  114. return tokens;
  115. }
  116. },
  117. {
  118. regex: "^(?=Found \\d+ matches)",
  119. token: "text",
  120. next: "numbers"
  121. },
  122. {
  123. token: "string",
  124. regex: "^\\S:?[^:]+",
  125. next: "numbers"
  126. }
  127. ],
  128. numbers: [{
  129. regex: "\\d+",
  130. token: "constant.numeric"
  131. }, {
  132. regex: "$",
  133. token: "text",
  134. next: "start"
  135. }]
  136. };
  137. this.normalizeRules();
  138. };
  139. oop.inherits(C9SearchHighlightRules, TextHighlightRules);
  140. exports.C9SearchHighlightRules = C9SearchHighlightRules;
  141. });
  142. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  143. var Range = require("../range").Range;
  144. var MatchingBraceOutdent = function () { };
  145. (function () {
  146. this.checkOutdent = function (line, input) {
  147. if (!/^\s+$/.test(line))
  148. return false;
  149. return /^\s*\}/.test(input);
  150. };
  151. this.autoOutdent = function (doc, row) {
  152. var line = doc.getLine(row);
  153. var match = line.match(/^(\s*\})/);
  154. if (!match)
  155. return 0;
  156. var column = match[1].length;
  157. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  158. if (!openBracePos || openBracePos.row == row)
  159. return 0;
  160. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  161. doc.replace(new Range(row, 0, row, column - 1), indent);
  162. };
  163. this.$getIndent = function (line) {
  164. return line.match(/^\s*/)[0];
  165. };
  166. }).call(MatchingBraceOutdent.prototype);
  167. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  168. });
  169. ace.define("ace/mode/folding/c9search",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  170. var oop = require("../../lib/oop");
  171. var Range = require("../../range").Range;
  172. var BaseFoldMode = require("./fold_mode").FoldMode;
  173. var FoldMode = exports.FoldMode = function () { };
  174. oop.inherits(FoldMode, BaseFoldMode);
  175. (function () {
  176. this.foldingStartMarker = /^(\S.*:|Searching for.*)$/;
  177. this.foldingStopMarker = /^(\s+|Found.*)$/;
  178. this.getFoldWidgetRange = function (session, foldStyle, row) {
  179. var lines = session.doc.getAllLines(row);
  180. var line = lines[row];
  181. var level1 = /^(Found.*|Searching for.*)$/;
  182. var level2 = /^(\S.*:|\s*)$/;
  183. var re = level1.test(line) ? level1 : level2;
  184. var startRow = row;
  185. var endRow = row;
  186. if (this.foldingStartMarker.test(line)) {
  187. for (var i = row + 1, l = session.getLength(); i < l; i++) {
  188. if (re.test(lines[i]))
  189. break;
  190. }
  191. endRow = i;
  192. }
  193. else if (this.foldingStopMarker.test(line)) {
  194. for (var i = row - 1; i >= 0; i--) {
  195. line = lines[i];
  196. if (re.test(line))
  197. break;
  198. }
  199. startRow = i;
  200. }
  201. if (startRow != endRow) {
  202. var col = line.length;
  203. if (re === level1)
  204. col = line.search(/\(Found[^)]+\)$|$/);
  205. return new Range(startRow, col, endRow, 0);
  206. }
  207. };
  208. }).call(FoldMode.prototype);
  209. });
  210. ace.define("ace/mode/c9search",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/c9search_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/c9search"], function(require, exports, module){"use strict";
  211. var oop = require("../lib/oop");
  212. var TextMode = require("./text").Mode;
  213. var C9SearchHighlightRules = require("./c9search_highlight_rules").C9SearchHighlightRules;
  214. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  215. var C9StyleFoldMode = require("./folding/c9search").FoldMode;
  216. var Mode = function () {
  217. this.HighlightRules = C9SearchHighlightRules;
  218. this.$outdent = new MatchingBraceOutdent();
  219. this.foldingRules = new C9StyleFoldMode();
  220. };
  221. oop.inherits(Mode, TextMode);
  222. (function () {
  223. this.getNextLineIndent = function (state, line, tab) {
  224. var indent = this.$getIndent(line);
  225. return indent;
  226. };
  227. this.checkOutdent = function (state, line, input) {
  228. return this.$outdent.checkOutdent(line, input);
  229. };
  230. this.autoOutdent = function (state, doc, row) {
  231. this.$outdent.autoOutdent(doc, row);
  232. };
  233. this.$id = "ace/mode/c9search";
  234. }).call(Mode.prototype);
  235. exports.Mode = Mode;
  236. }); (function() {
  237. ace.require(["ace/mode/c9search"], function(m) {
  238. if (typeof module == "object" && typeof exports == "object" && module) {
  239. module.exports = m;
  240. }
  241. });
  242. })();