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.

287 lines
9.5 KiB

12 months ago
  1. ace.define("ace/mode/c9search_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"], function(acequire, exports, module) {
  2. "use strict";
  3. var oop = acequire("../lib/oop");
  4. var lang = acequire("../lib/lang");
  5. var TextHighlightRules = acequire("./text_highlight_rules").TextHighlightRules;
  6. function safeCreateRegexp(source, flag) {
  7. try {
  8. return new RegExp(source, flag);
  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, replace;
  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. replace = parts[i];
  75. tokens.push({
  76. value: "'" + parts[i++] + "'",
  77. type: "text"
  78. }, {
  79. value: parts[i++],
  80. type: "text"
  81. });
  82. }
  83. tokens.push({
  84. value: " " + parts[i++] + " ",
  85. type: "text"
  86. });
  87. if (parts[i+1]) {
  88. options = parts[i+1];
  89. tokens.push({
  90. value: "(" + parts[i+1] + ")",
  91. type: "text"
  92. });
  93. i += 1;
  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(
  110. "(" + search + ")",
  111. / sensitive/.test(options) ? "g" : "ig"
  112. );
  113. if (regex) {
  114. stack[0] = state;
  115. stack[1] = regex;
  116. }
  117. return tokens;
  118. }
  119. },
  120. {
  121. regex : "^(?=Found \\d+ matches)",
  122. token : "text",
  123. next : "numbers"
  124. },
  125. {
  126. token : "string", // single line
  127. regex : "^\\S:?[^:]+",
  128. next : "numbers"
  129. }
  130. ],
  131. numbers:[{
  132. regex : "\\d+",
  133. token : "constant.numeric"
  134. }, {
  135. regex : "$",
  136. token : "text",
  137. next : "start"
  138. }]
  139. };
  140. this.normalizeRules();
  141. };
  142. oop.inherits(C9SearchHighlightRules, TextHighlightRules);
  143. exports.C9SearchHighlightRules = C9SearchHighlightRules;
  144. });
  145. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(acequire, exports, module) {
  146. "use strict";
  147. var Range = acequire("../range").Range;
  148. var MatchingBraceOutdent = function() {};
  149. (function() {
  150. this.checkOutdent = function(line, input) {
  151. if (! /^\s+$/.test(line))
  152. return false;
  153. return /^\s*\}/.test(input);
  154. };
  155. this.autoOutdent = function(doc, row) {
  156. var line = doc.getLine(row);
  157. var match = line.match(/^(\s*\})/);
  158. if (!match) return 0;
  159. var column = match[1].length;
  160. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  161. if (!openBracePos || openBracePos.row == row) return 0;
  162. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  163. doc.replace(new Range(row, 0, row, column-1), indent);
  164. };
  165. this.$getIndent = function(line) {
  166. return line.match(/^\s*/)[0];
  167. };
  168. }).call(MatchingBraceOutdent.prototype);
  169. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  170. });
  171. ace.define("ace/mode/folding/c9search",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(acequire, exports, module) {
  172. "use strict";
  173. var oop = acequire("../../lib/oop");
  174. var Range = acequire("../../range").Range;
  175. var BaseFoldMode = acequire("./fold_mode").FoldMode;
  176. var FoldMode = exports.FoldMode = function() {};
  177. oop.inherits(FoldMode, BaseFoldMode);
  178. (function() {
  179. this.foldingStartMarker = /^(\S.*:|Searching for.*)$/;
  180. this.foldingStopMarker = /^(\s+|Found.*)$/;
  181. this.getFoldWidgetRange = function(session, foldStyle, row) {
  182. var lines = session.doc.getAllLines(row);
  183. var line = lines[row];
  184. var level1 = /^(Found.*|Searching for.*)$/;
  185. var level2 = /^(\S.*:|\s*)$/;
  186. var re = level1.test(line) ? level1 : level2;
  187. var startRow = row;
  188. var endRow = row;
  189. if (this.foldingStartMarker.test(line)) {
  190. for (var i = row + 1, l = session.getLength(); i < l; i++) {
  191. if (re.test(lines[i]))
  192. break;
  193. }
  194. endRow = i;
  195. }
  196. else if (this.foldingStopMarker.test(line)) {
  197. for (var i = row - 1; i >= 0; i--) {
  198. line = lines[i];
  199. if (re.test(line))
  200. break;
  201. }
  202. startRow = i;
  203. }
  204. if (startRow != endRow) {
  205. var col = line.length;
  206. if (re === level1)
  207. col = line.search(/\(Found[^)]+\)$|$/);
  208. return new Range(startRow, col, endRow, 0);
  209. }
  210. };
  211. }).call(FoldMode.prototype);
  212. });
  213. 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(acequire, exports, module) {
  214. "use strict";
  215. var oop = acequire("../lib/oop");
  216. var TextMode = acequire("./text").Mode;
  217. var C9SearchHighlightRules = acequire("./c9search_highlight_rules").C9SearchHighlightRules;
  218. var MatchingBraceOutdent = acequire("./matching_brace_outdent").MatchingBraceOutdent;
  219. var C9StyleFoldMode = acequire("./folding/c9search").FoldMode;
  220. var Mode = function() {
  221. this.HighlightRules = C9SearchHighlightRules;
  222. this.$outdent = new MatchingBraceOutdent();
  223. this.foldingRules = new C9StyleFoldMode();
  224. };
  225. oop.inherits(Mode, TextMode);
  226. (function() {
  227. this.getNextLineIndent = function(state, line, tab) {
  228. var indent = this.$getIndent(line);
  229. return indent;
  230. };
  231. this.checkOutdent = function(state, line, input) {
  232. return this.$outdent.checkOutdent(line, input);
  233. };
  234. this.autoOutdent = function(state, doc, row) {
  235. this.$outdent.autoOutdent(doc, row);
  236. };
  237. this.$id = "ace/mode/c9search";
  238. }).call(Mode.prototype);
  239. exports.Mode = Mode;
  240. });