mode-jack.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. ace.define("ace/mode/jack_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 JackHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [
  8. {
  9. token : "string",
  10. regex : '"',
  11. next : "string2"
  12. }, {
  13. token : "string",
  14. regex : "'",
  15. next : "string1"
  16. }, {
  17. token : "constant.numeric", // hex
  18. regex: "-?0[xX][0-9a-fA-F]+\\b"
  19. }, {
  20. token : "constant.numeric", // float
  21. regex : "(?:0|[-+]?[1-9][0-9]*)\\b"
  22. }, {
  23. token : "constant.binary",
  24. regex : "<[0-9A-Fa-f][0-9A-Fa-f](\\s+[0-9A-Fa-f][0-9A-Fa-f])*>"
  25. }, {
  26. token : "constant.language.boolean",
  27. regex : "(?:true|false)\\b"
  28. }, {
  29. token : "constant.language.null",
  30. regex : "null\\b"
  31. }, {
  32. token : "storage.type",
  33. regex: "(?:Integer|Boolean|Null|String|Buffer|Tuple|List|Object|Function|Coroutine|Form)\\b"
  34. }, {
  35. token : "keyword",
  36. regex : "(?:return|abort|vars|for|delete|in|is|escape|exec|split|and|if|elif|else|while)\\b"
  37. }, {
  38. token : "language.builtin",
  39. regex : "(?:lines|source|parse|read-stream|interval|substr|parseint|write|print|range|rand|inspect|bind|i-values|i-pairs|i-map|i-filter|i-chunk|i-all\\?|i-any\\?|i-collect|i-zip|i-merge|i-each)\\b"
  40. }, {
  41. token : "comment",
  42. regex : "--.*$"
  43. }, {
  44. token : "paren.lparen",
  45. regex : "[[({]"
  46. }, {
  47. token : "paren.rparen",
  48. regex : "[\\])}]"
  49. }, {
  50. token : "storage.form",
  51. regex : "@[a-z]+"
  52. }, {
  53. token : "constant.other.symbol",
  54. regex : ':+[a-zA-Z_]([-]?[a-zA-Z0-9_])*[?!]?'
  55. }, {
  56. token : "variable",
  57. regex : '[a-zA-Z_]([-]?[a-zA-Z0-9_])*[?!]?'
  58. }, {
  59. token : "keyword.operator",
  60. regex : "\\|\\||\\^\\^|&&|!=|==|<=|<|>=|>|\\+|-|\\*|\\/|\\^|\\%|\\#|\\!"
  61. }, {
  62. token : "text",
  63. regex : "\\s+"
  64. }
  65. ],
  66. "string1" : [
  67. {
  68. token : "constant.language.escape",
  69. regex : /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|['"\\\/bfnrt])/
  70. }, {
  71. token : "string",
  72. regex : "[^'\\\\]+"
  73. }, {
  74. token : "string",
  75. regex : "'",
  76. next : "start"
  77. }, {
  78. token : "string",
  79. regex : "",
  80. next : "start"
  81. }
  82. ],
  83. "string2" : [
  84. {
  85. token : "constant.language.escape",
  86. regex : /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|['"\\\/bfnrt])/
  87. }, {
  88. token : "string",
  89. regex : '[^"\\\\]+'
  90. }, {
  91. token : "string",
  92. regex : '"',
  93. next : "start"
  94. }, {
  95. token : "string",
  96. regex : "",
  97. next : "start"
  98. }
  99. ]
  100. };
  101. };
  102. oop.inherits(JackHighlightRules, TextHighlightRules);
  103. exports.JackHighlightRules = JackHighlightRules;
  104. });
  105. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  106. "use strict";
  107. var Range = require("../range").Range;
  108. var MatchingBraceOutdent = function() {};
  109. (function() {
  110. this.checkOutdent = function(line, input) {
  111. if (! /^\s+$/.test(line))
  112. return false;
  113. return /^\s*\}/.test(input);
  114. };
  115. this.autoOutdent = function(doc, row) {
  116. var line = doc.getLine(row);
  117. var match = line.match(/^(\s*\})/);
  118. if (!match) return 0;
  119. var column = match[1].length;
  120. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  121. if (!openBracePos || openBracePos.row == row) return 0;
  122. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  123. doc.replace(new Range(row, 0, row, column-1), indent);
  124. };
  125. this.$getIndent = function(line) {
  126. return line.match(/^\s*/)[0];
  127. };
  128. }).call(MatchingBraceOutdent.prototype);
  129. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  130. });
  131. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  132. "use strict";
  133. var oop = require("../../lib/oop");
  134. var Range = require("../../range").Range;
  135. var BaseFoldMode = require("./fold_mode").FoldMode;
  136. var FoldMode = exports.FoldMode = function(commentRegex) {
  137. if (commentRegex) {
  138. this.foldingStartMarker = new RegExp(
  139. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  140. );
  141. this.foldingStopMarker = new RegExp(
  142. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  143. );
  144. }
  145. };
  146. oop.inherits(FoldMode, BaseFoldMode);
  147. (function() {
  148. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  149. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  150. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  151. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  152. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  153. this._getFoldWidgetBase = this.getFoldWidget;
  154. this.getFoldWidget = function(session, foldStyle, row) {
  155. var line = session.getLine(row);
  156. if (this.singleLineBlockCommentRe.test(line)) {
  157. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  158. return "";
  159. }
  160. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  161. if (!fw && this.startRegionRe.test(line))
  162. return "start"; // lineCommentRegionStart
  163. return fw;
  164. };
  165. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  166. var line = session.getLine(row);
  167. if (this.startRegionRe.test(line))
  168. return this.getCommentRegionBlock(session, line, row);
  169. var match = line.match(this.foldingStartMarker);
  170. if (match) {
  171. var i = match.index;
  172. if (match[1])
  173. return this.openingBracketBlock(session, match[1], row, i);
  174. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  175. if (range && !range.isMultiLine()) {
  176. if (forceMultiline) {
  177. range = this.getSectionRange(session, row);
  178. } else if (foldStyle != "all")
  179. range = null;
  180. }
  181. return range;
  182. }
  183. if (foldStyle === "markbegin")
  184. return;
  185. var match = line.match(this.foldingStopMarker);
  186. if (match) {
  187. var i = match.index + match[0].length;
  188. if (match[1])
  189. return this.closingBracketBlock(session, match[1], row, i);
  190. return session.getCommentFoldRange(row, i, -1);
  191. }
  192. };
  193. this.getSectionRange = function(session, row) {
  194. var line = session.getLine(row);
  195. var startIndent = line.search(/\S/);
  196. var startRow = row;
  197. var startColumn = line.length;
  198. row = row + 1;
  199. var endRow = row;
  200. var maxRow = session.getLength();
  201. while (++row < maxRow) {
  202. line = session.getLine(row);
  203. var indent = line.search(/\S/);
  204. if (indent === -1)
  205. continue;
  206. if (startIndent > indent)
  207. break;
  208. var subRange = this.getFoldWidgetRange(session, "all", row);
  209. if (subRange) {
  210. if (subRange.start.row <= startRow) {
  211. break;
  212. } else if (subRange.isMultiLine()) {
  213. row = subRange.end.row;
  214. } else if (startIndent == indent) {
  215. break;
  216. }
  217. }
  218. endRow = row;
  219. }
  220. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  221. };
  222. this.getCommentRegionBlock = function(session, line, row) {
  223. var startColumn = line.search(/\s*$/);
  224. var maxRow = session.getLength();
  225. var startRow = row;
  226. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  227. var depth = 1;
  228. while (++row < maxRow) {
  229. line = session.getLine(row);
  230. var m = re.exec(line);
  231. if (!m) continue;
  232. if (m[1]) depth--;
  233. else depth++;
  234. if (!depth) break;
  235. }
  236. var endRow = row;
  237. if (endRow > startRow) {
  238. return new Range(startRow, startColumn, endRow, line.length);
  239. }
  240. };
  241. }).call(FoldMode.prototype);
  242. });
  243. ace.define("ace/mode/jack",[], function(require, exports, module) {
  244. "use strict";
  245. var oop = require("../lib/oop");
  246. var TextMode = require("./text").Mode;
  247. var HighlightRules = require("./jack_highlight_rules").JackHighlightRules;
  248. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  249. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  250. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  251. var Mode = function() {
  252. this.HighlightRules = HighlightRules;
  253. this.$outdent = new MatchingBraceOutdent();
  254. this.$behaviour = new CstyleBehaviour();
  255. this.foldingRules = new CStyleFoldMode();
  256. };
  257. oop.inherits(Mode, TextMode);
  258. (function() {
  259. this.lineCommentStart = "--";
  260. this.getNextLineIndent = function(state, line, tab) {
  261. var indent = this.$getIndent(line);
  262. if (state == "start") {
  263. var match = line.match(/^.*[\{\(\[]\s*$/);
  264. if (match) {
  265. indent += tab;
  266. }
  267. }
  268. return indent;
  269. };
  270. this.checkOutdent = function(state, line, input) {
  271. return this.$outdent.checkOutdent(line, input);
  272. };
  273. this.autoOutdent = function(state, doc, row) {
  274. this.$outdent.autoOutdent(doc, row);
  275. };
  276. this.$id = "ace/mode/jack";
  277. }).call(Mode.prototype);
  278. exports.Mode = Mode;
  279. });
  280. (function() {
  281. ace.require(["ace/mode/jack"], function(m) {
  282. if (typeof module == "object" && typeof exports == "object" && module) {
  283. module.exports = m;
  284. }
  285. });
  286. })();