mode-maze.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. ace.define("ace/mode/maze_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 MazeHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. token: "keyword.control",
  9. regex: /##|``/,
  10. comment: "Wall"
  11. }, {
  12. token: "entity.name.tag",
  13. regex: /\.\./,
  14. comment: "Path"
  15. }, {
  16. token: "keyword.control",
  17. regex: /<>/,
  18. comment: "Splitter"
  19. }, {
  20. token: "entity.name.tag",
  21. regex: /\*[\*A-Za-z0-9]/,
  22. comment: "Signal"
  23. }, {
  24. token: "constant.numeric",
  25. regex: /[0-9]{2}/,
  26. comment: "Pause"
  27. }, {
  28. token: "keyword.control",
  29. regex: /\^\^/,
  30. comment: "Start"
  31. }, {
  32. token: "keyword.control",
  33. regex: /\(\)/,
  34. comment: "Hole"
  35. }, {
  36. token: "support.function",
  37. regex: />>/,
  38. comment: "Out"
  39. }, {
  40. token: "support.function",
  41. regex: />\//,
  42. comment: "Ln Out"
  43. }, {
  44. token: "support.function",
  45. regex: /<</,
  46. comment: "In"
  47. }, {
  48. token: "keyword.control",
  49. regex: /--/,
  50. comment: "One use"
  51. }, {
  52. token: "constant.language",
  53. regex: /%[LRUDNlrudn]/,
  54. comment: "Direction"
  55. }, {
  56. token: [
  57. "entity.name.function",
  58. "keyword.other",
  59. "keyword.operator",
  60. "keyword.other",
  61. "keyword.operator",
  62. "constant.numeric",
  63. "keyword.operator",
  64. "keyword.other",
  65. "keyword.operator",
  66. "constant.numeric",
  67. "string.quoted.double",
  68. "string.quoted.single"
  69. ],
  70. regex: /([A-Za-z][A-Za-z0-9])( *-> *)(?:([-+*\/]=)( *)((?:-)?)([0-9]+)|(=)( *)(?:((?:-)?)([0-9]+)|("[^"]*")|('[^']*')))/,
  71. comment: "Assignment function"
  72. }, {
  73. token: [
  74. "entity.name.function",
  75. "keyword.other",
  76. "keyword.control",
  77. "keyword.other",
  78. "keyword.operator",
  79. "keyword.other",
  80. "keyword.operator",
  81. "constant.numeric",
  82. "entity.name.tag",
  83. "keyword.other",
  84. "keyword.control",
  85. "keyword.other",
  86. "constant.language",
  87. "keyword.other",
  88. "keyword.control",
  89. "keyword.other",
  90. "constant.language"
  91. ],
  92. regex: /([A-Za-z][A-Za-z0-9])( *-> *)(IF|if)( *)(?:([<>]=?|==)( *)((?:-)?)([0-9]+)|(\*[\*A-Za-z0-9]))( *)(THEN|then)( *)(%[LRUDNlrudn])(?:( *)(ELSE|else)( *)(%[LRUDNlrudn]))?/,
  93. comment: "Equality Function"
  94. }, {
  95. token: "entity.name.function",
  96. regex: /[A-Za-z][A-Za-z0-9]/,
  97. comment: "Function cell"
  98. }, {
  99. token: "comment.line.double-slash",
  100. regex: / *\/\/.*/,
  101. comment: "Comment"
  102. }]
  103. };
  104. this.normalizeRules();
  105. };
  106. MazeHighlightRules.metaData = {
  107. fileTypes: ["mz"],
  108. name: "Maze",
  109. scopeName: "source.maze"
  110. };
  111. oop.inherits(MazeHighlightRules, TextHighlightRules);
  112. exports.MazeHighlightRules = MazeHighlightRules;
  113. });
  114. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  115. "use strict";
  116. var oop = require("../../lib/oop");
  117. var Range = require("../../range").Range;
  118. var BaseFoldMode = require("./fold_mode").FoldMode;
  119. var FoldMode = exports.FoldMode = function(commentRegex) {
  120. if (commentRegex) {
  121. this.foldingStartMarker = new RegExp(
  122. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  123. );
  124. this.foldingStopMarker = new RegExp(
  125. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  126. );
  127. }
  128. };
  129. oop.inherits(FoldMode, BaseFoldMode);
  130. (function() {
  131. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  132. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  133. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  134. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  135. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  136. this._getFoldWidgetBase = this.getFoldWidget;
  137. this.getFoldWidget = function(session, foldStyle, row) {
  138. var line = session.getLine(row);
  139. if (this.singleLineBlockCommentRe.test(line)) {
  140. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  141. return "";
  142. }
  143. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  144. if (!fw && this.startRegionRe.test(line))
  145. return "start"; // lineCommentRegionStart
  146. return fw;
  147. };
  148. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  149. var line = session.getLine(row);
  150. if (this.startRegionRe.test(line))
  151. return this.getCommentRegionBlock(session, line, row);
  152. var match = line.match(this.foldingStartMarker);
  153. if (match) {
  154. var i = match.index;
  155. if (match[1])
  156. return this.openingBracketBlock(session, match[1], row, i);
  157. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  158. if (range && !range.isMultiLine()) {
  159. if (forceMultiline) {
  160. range = this.getSectionRange(session, row);
  161. } else if (foldStyle != "all")
  162. range = null;
  163. }
  164. return range;
  165. }
  166. if (foldStyle === "markbegin")
  167. return;
  168. var match = line.match(this.foldingStopMarker);
  169. if (match) {
  170. var i = match.index + match[0].length;
  171. if (match[1])
  172. return this.closingBracketBlock(session, match[1], row, i);
  173. return session.getCommentFoldRange(row, i, -1);
  174. }
  175. };
  176. this.getSectionRange = function(session, row) {
  177. var line = session.getLine(row);
  178. var startIndent = line.search(/\S/);
  179. var startRow = row;
  180. var startColumn = line.length;
  181. row = row + 1;
  182. var endRow = row;
  183. var maxRow = session.getLength();
  184. while (++row < maxRow) {
  185. line = session.getLine(row);
  186. var indent = line.search(/\S/);
  187. if (indent === -1)
  188. continue;
  189. if (startIndent > indent)
  190. break;
  191. var subRange = this.getFoldWidgetRange(session, "all", row);
  192. if (subRange) {
  193. if (subRange.start.row <= startRow) {
  194. break;
  195. } else if (subRange.isMultiLine()) {
  196. row = subRange.end.row;
  197. } else if (startIndent == indent) {
  198. break;
  199. }
  200. }
  201. endRow = row;
  202. }
  203. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  204. };
  205. this.getCommentRegionBlock = function(session, line, row) {
  206. var startColumn = line.search(/\s*$/);
  207. var maxRow = session.getLength();
  208. var startRow = row;
  209. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  210. var depth = 1;
  211. while (++row < maxRow) {
  212. line = session.getLine(row);
  213. var m = re.exec(line);
  214. if (!m) continue;
  215. if (m[1]) depth--;
  216. else depth++;
  217. if (!depth) break;
  218. }
  219. var endRow = row;
  220. if (endRow > startRow) {
  221. return new Range(startRow, startColumn, endRow, line.length);
  222. }
  223. };
  224. }).call(FoldMode.prototype);
  225. });
  226. ace.define("ace/mode/maze",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/maze_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  227. "use strict";
  228. var oop = require("../lib/oop");
  229. var TextMode = require("./text").Mode;
  230. var MazeHighlightRules = require("./maze_highlight_rules").MazeHighlightRules;
  231. var FoldMode = require("./folding/cstyle").FoldMode;
  232. var Mode = function() {
  233. this.HighlightRules = MazeHighlightRules;
  234. this.foldingRules = new FoldMode();
  235. this.$behaviour = this.$defaultBehaviour;
  236. };
  237. oop.inherits(Mode, TextMode);
  238. (function() {
  239. this.lineCommentStart = "//";
  240. this.$id = "ace/mode/maze";
  241. }).call(Mode.prototype);
  242. exports.Mode = Mode;
  243. });