mode-mavens_mate_log.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../../lib/oop");
  4. var Range = require("../../range").Range;
  5. var BaseFoldMode = require("./fold_mode").FoldMode;
  6. var FoldMode = exports.FoldMode = function(commentRegex) {
  7. if (commentRegex) {
  8. this.foldingStartMarker = new RegExp(
  9. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  10. );
  11. this.foldingStopMarker = new RegExp(
  12. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  13. );
  14. }
  15. };
  16. oop.inherits(FoldMode, BaseFoldMode);
  17. (function() {
  18. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  19. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  20. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  21. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  22. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  23. this._getFoldWidgetBase = this.getFoldWidget;
  24. this.getFoldWidget = function(session, foldStyle, row) {
  25. var line = session.getLine(row);
  26. if (this.singleLineBlockCommentRe.test(line)) {
  27. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  28. return "";
  29. }
  30. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  31. if (!fw && this.startRegionRe.test(line))
  32. return "start"; // lineCommentRegionStart
  33. return fw;
  34. };
  35. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  36. var line = session.getLine(row);
  37. if (this.startRegionRe.test(line))
  38. return this.getCommentRegionBlock(session, line, row);
  39. var match = line.match(this.foldingStartMarker);
  40. if (match) {
  41. var i = match.index;
  42. if (match[1])
  43. return this.openingBracketBlock(session, match[1], row, i);
  44. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  45. if (range && !range.isMultiLine()) {
  46. if (forceMultiline) {
  47. range = this.getSectionRange(session, row);
  48. } else if (foldStyle != "all")
  49. range = null;
  50. }
  51. return range;
  52. }
  53. if (foldStyle === "markbegin")
  54. return;
  55. var match = line.match(this.foldingStopMarker);
  56. if (match) {
  57. var i = match.index + match[0].length;
  58. if (match[1])
  59. return this.closingBracketBlock(session, match[1], row, i);
  60. return session.getCommentFoldRange(row, i, -1);
  61. }
  62. };
  63. this.getSectionRange = function(session, row) {
  64. var line = session.getLine(row);
  65. var startIndent = line.search(/\S/);
  66. var startRow = row;
  67. var startColumn = line.length;
  68. row = row + 1;
  69. var endRow = row;
  70. var maxRow = session.getLength();
  71. while (++row < maxRow) {
  72. line = session.getLine(row);
  73. var indent = line.search(/\S/);
  74. if (indent === -1)
  75. continue;
  76. if (startIndent > indent)
  77. break;
  78. var subRange = this.getFoldWidgetRange(session, "all", row);
  79. if (subRange) {
  80. if (subRange.start.row <= startRow) {
  81. break;
  82. } else if (subRange.isMultiLine()) {
  83. row = subRange.end.row;
  84. } else if (startIndent == indent) {
  85. break;
  86. }
  87. }
  88. endRow = row;
  89. }
  90. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  91. };
  92. this.getCommentRegionBlock = function(session, line, row) {
  93. var startColumn = line.search(/\s*$/);
  94. var maxRow = session.getLength();
  95. var startRow = row;
  96. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  97. var depth = 1;
  98. while (++row < maxRow) {
  99. line = session.getLine(row);
  100. var m = re.exec(line);
  101. if (!m) continue;
  102. if (m[1]) depth--;
  103. else depth++;
  104. if (!depth) break;
  105. }
  106. var endRow = row;
  107. if (endRow > startRow) {
  108. return new Range(startRow, startColumn, endRow, line.length);
  109. }
  110. };
  111. }).call(FoldMode.prototype);
  112. });
  113. ace.define("ace/mode/mavens_mate_log",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/mavens_mate_log_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  114. "use strict";
  115. var oop = require("../lib/oop");
  116. var TextMode = require("./text").Mode;
  117. var MavensMateLogHighlightRules = require("./mavens_mate_log_highlight_rules").MavensMateLogHighlightRules;
  118. var FoldMode = require("./folding/cstyle").FoldMode;
  119. var Mode = function() {
  120. this.HighlightRules = MavensMateLogHighlightRules;
  121. this.foldingRules = new FoldMode();
  122. };
  123. oop.inherits(Mode, TextMode);
  124. (function() {
  125. this.$id = "ace/mode/mavens_mate_log"
  126. }).call(Mode.prototype);
  127. exports.Mode = Mode;
  128. });