mode-mipsassembler.js 6.1 KB

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