df14d63677343134a88e906bf460b997.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. ace.define("ace/mode/coffee_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. oop.inherits(CoffeeHighlightRules, TextHighlightRules);
  5. function CoffeeHighlightRules() {
  6. var identifier = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
  7. var keywords = ("this|throw|then|try|typeof|super|switch|return|break|by|continue|" +
  8. "catch|class|in|instanceof|is|isnt|if|else|extends|for|own|" +
  9. "finally|function|while|when|new|no|not|delete|debugger|do|loop|of|off|" +
  10. "or|on|unless|until|and|yes|yield|export|import|default");
  11. var langConstant = ("true|false|null|undefined|NaN|Infinity");
  12. var illegal = ("case|const|function|var|void|with|enum|implements|" +
  13. "interface|let|package|private|protected|public|static");
  14. var supportClass = ("Array|Boolean|Date|Function|Number|Object|RegExp|ReferenceError|String|" +
  15. "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" +
  16. "SyntaxError|TypeError|URIError|" +
  17. "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
  18. "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray");
  19. var supportFunction = ("Math|JSON|isNaN|isFinite|parseInt|parseFloat|encodeURI|" +
  20. "encodeURIComponent|decodeURI|decodeURIComponent|String|");
  21. var variableLanguage = ("window|arguments|prototype|document");
  22. var keywordMapper = this.createKeywordMapper({
  23. "keyword": keywords,
  24. "constant.language": langConstant,
  25. "invalid.illegal": illegal,
  26. "language.support.class": supportClass,
  27. "language.support.function": supportFunction,
  28. "variable.language": variableLanguage
  29. }, "identifier");
  30. var functionRule = {
  31. token: ["paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type"],
  32. regex: /(?:(\()((?:"[^")]*?"|'[^')]*?'|\/[^\/)]*?\/|[^()"'\/])*?)(\))(\s*))?([\-=]>)/.source
  33. };
  34. var stringEscape = /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)/;
  35. this.$rules = {
  36. start: [
  37. {
  38. token: "constant.numeric",
  39. regex: "(?:0x[\\da-fA-F]+|(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[eE][+-]?\\d+)?)"
  40. }, {
  41. stateName: "qdoc",
  42. token: "string", regex: "'''", next: [
  43. { token: "string", regex: "'''", next: "start" },
  44. { token: "constant.language.escape", regex: stringEscape },
  45. { defaultToken: "string" }
  46. ]
  47. }, {
  48. stateName: "qqdoc",
  49. token: "string",
  50. regex: '"""',
  51. next: [
  52. { token: "string", regex: '"""', next: "start" },
  53. { token: "paren.string", regex: '#{', push: "start" },
  54. { token: "constant.language.escape", regex: stringEscape },
  55. { defaultToken: "string" }
  56. ]
  57. }, {
  58. stateName: "qstring",
  59. token: "string", regex: "'", next: [
  60. { token: "string", regex: "'", next: "start" },
  61. { token: "constant.language.escape", regex: stringEscape },
  62. { defaultToken: "string" }
  63. ]
  64. }, {
  65. stateName: "qqstring",
  66. token: "string.start", regex: '"', next: [
  67. { token: "string.end", regex: '"', next: "start" },
  68. { token: "paren.string", regex: '#{', push: "start" },
  69. { token: "constant.language.escape", regex: stringEscape },
  70. { defaultToken: "string" }
  71. ]
  72. }, {
  73. stateName: "js",
  74. token: "string", regex: "`", next: [
  75. { token: "string", regex: "`", next: "start" },
  76. { token: "constant.language.escape", regex: stringEscape },
  77. { defaultToken: "string" }
  78. ]
  79. }, {
  80. regex: "[{}]", onMatch: function (val, state, stack) {
  81. this.next = "";
  82. if (val == "{" && stack.length) {
  83. stack.unshift("start", state);
  84. return "paren";
  85. }
  86. if (val == "}" && stack.length) {
  87. stack.shift();
  88. this.next = stack.shift() || "";
  89. if (this.next.indexOf("string") != -1)
  90. return "paren.string";
  91. }
  92. return "paren";
  93. }
  94. }, {
  95. token: "string.regex",
  96. regex: "///",
  97. next: "heregex"
  98. }, {
  99. token: "string.regex",
  100. regex: /(?:\/(?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/)(?:[imgy]{0,4})(?!\w)/
  101. }, {
  102. token: "comment",
  103. regex: "###(?!#)",
  104. next: "comment"
  105. }, {
  106. token: "comment",
  107. regex: "#.*"
  108. }, {
  109. token: ["punctuation.operator", "text", "identifier"],
  110. regex: "(\\.)(\\s*)(" + illegal + ")"
  111. }, {
  112. token: "punctuation.operator",
  113. regex: "\\.{1,3}"
  114. }, {
  115. token: ["keyword", "text", "language.support.class",
  116. "text", "keyword", "text", "language.support.class"],
  117. regex: "(class)(\\s+)(" + identifier + ")(?:(\\s+)(extends)(\\s+)(" + identifier + "))?"
  118. }, {
  119. token: ["entity.name.function", "text", "keyword.operator", "text"].concat(functionRule.token),
  120. regex: "(" + identifier + ")(\\s*)([=:])(\\s*)" + functionRule.regex
  121. },
  122. functionRule,
  123. {
  124. token: "variable",
  125. regex: "@(?:" + identifier + ")?"
  126. }, {
  127. token: keywordMapper,
  128. regex: identifier
  129. }, {
  130. token: "punctuation.operator",
  131. regex: "\\,|\\."
  132. }, {
  133. token: "storage.type",
  134. regex: "[\\-=]>"
  135. }, {
  136. token: "keyword.operator",
  137. regex: "(?:[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|[!*+-=><])"
  138. }, {
  139. token: "paren.lparen",
  140. regex: "[({[]"
  141. }, {
  142. token: "paren.rparen",
  143. regex: "[\\]})]"
  144. }, {
  145. token: "text",
  146. regex: "\\s+"
  147. }
  148. ],
  149. heregex: [{
  150. token: "string.regex",
  151. regex: '.*?///[imgy]{0,4}',
  152. next: "start"
  153. }, {
  154. token: "comment.regex",
  155. regex: "\\s+(?:#.*)?"
  156. }, {
  157. token: "string.regex",
  158. regex: "\\S+"
  159. }],
  160. comment: [{
  161. token: "comment",
  162. regex: '###',
  163. next: "start"
  164. }, {
  165. defaultToken: "comment"
  166. }]
  167. };
  168. this.normalizeRules();
  169. }
  170. exports.CoffeeHighlightRules = CoffeeHighlightRules;
  171. });
  172. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  173. var Range = require("../range").Range;
  174. var MatchingBraceOutdent = function () { };
  175. (function () {
  176. this.checkOutdent = function (line, input) {
  177. if (!/^\s+$/.test(line))
  178. return false;
  179. return /^\s*\}/.test(input);
  180. };
  181. this.autoOutdent = function (doc, row) {
  182. var line = doc.getLine(row);
  183. var match = line.match(/^(\s*\})/);
  184. if (!match)
  185. return 0;
  186. var column = match[1].length;
  187. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  188. if (!openBracePos || openBracePos.row == row)
  189. return 0;
  190. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  191. doc.replace(new Range(row, 0, row, column - 1), indent);
  192. };
  193. this.$getIndent = function (line) {
  194. return line.match(/^\s*/)[0];
  195. };
  196. }).call(MatchingBraceOutdent.prototype);
  197. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  198. });
  199. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module){"use strict";
  200. var oop = require("../../lib/oop");
  201. var BaseFoldMode = require("./fold_mode").FoldMode;
  202. var Range = require("../../range").Range;
  203. var FoldMode = exports.FoldMode = function () { };
  204. oop.inherits(FoldMode, BaseFoldMode);
  205. (function () {
  206. this.getFoldWidgetRange = function (session, foldStyle, row) {
  207. var range = this.indentationBlock(session, row);
  208. if (range)
  209. return range;
  210. var re = /\S/;
  211. var line = session.getLine(row);
  212. var startLevel = line.search(re);
  213. if (startLevel == -1 || line[startLevel] != "#")
  214. return;
  215. var startColumn = line.length;
  216. var maxRow = session.getLength();
  217. var startRow = row;
  218. var endRow = row;
  219. while (++row < maxRow) {
  220. line = session.getLine(row);
  221. var level = line.search(re);
  222. if (level == -1)
  223. continue;
  224. if (line[level] != "#")
  225. break;
  226. endRow = row;
  227. }
  228. if (endRow > startRow) {
  229. var endColumn = session.getLine(endRow).length;
  230. return new Range(startRow, startColumn, endRow, endColumn);
  231. }
  232. };
  233. this.getFoldWidget = function (session, foldStyle, row) {
  234. var line = session.getLine(row);
  235. var indent = line.search(/\S/);
  236. var next = session.getLine(row + 1);
  237. var prev = session.getLine(row - 1);
  238. var prevIndent = prev.search(/\S/);
  239. var nextIndent = next.search(/\S/);
  240. if (indent == -1) {
  241. session.foldWidgets[row - 1] = prevIndent != -1 && prevIndent < nextIndent ? "start" : "";
  242. return "";
  243. }
  244. if (prevIndent == -1) {
  245. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  246. session.foldWidgets[row - 1] = "";
  247. session.foldWidgets[row + 1] = "";
  248. return "start";
  249. }
  250. }
  251. else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  252. if (session.getLine(row - 2).search(/\S/) == -1) {
  253. session.foldWidgets[row - 1] = "start";
  254. session.foldWidgets[row + 1] = "";
  255. return "";
  256. }
  257. }
  258. if (prevIndent != -1 && prevIndent < indent)
  259. session.foldWidgets[row - 1] = "start";
  260. else
  261. session.foldWidgets[row - 1] = "";
  262. if (indent < nextIndent)
  263. return "start";
  264. else
  265. return "";
  266. };
  267. }).call(FoldMode.prototype);
  268. });
  269. ace.define("ace/mode/coffee",["require","exports","module","ace/mode/coffee_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/coffee","ace/range","ace/mode/text","ace/worker/worker_client","ace/lib/oop"], function(require, exports, module){"use strict";
  270. var Rules = require("./coffee_highlight_rules").CoffeeHighlightRules;
  271. var Outdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  272. var FoldMode = require("./folding/coffee").FoldMode;
  273. var Range = require("../range").Range;
  274. var TextMode = require("./text").Mode;
  275. var WorkerClient = require("../worker/worker_client").WorkerClient;
  276. var oop = require("../lib/oop");
  277. function Mode() {
  278. this.HighlightRules = Rules;
  279. this.$outdent = new Outdent();
  280. this.foldingRules = new FoldMode();
  281. }
  282. oop.inherits(Mode, TextMode);
  283. (function () {
  284. var indenter = /(?:[({[=:]|[-=]>|\b(?:else|try|(?:swi|ca)tch(?:\s+[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?|finally))\s*$|^\s*(else\b\s*)?(?:if|for|while|loop)\b(?!.*\bthen\b)/;
  285. this.lineCommentStart = "#";
  286. this.blockComment = { start: "###", end: "###" };
  287. this.getNextLineIndent = function (state, line, tab) {
  288. var indent = this.$getIndent(line);
  289. var tokens = this.getTokenizer().getLineTokens(line, state).tokens;
  290. if (!(tokens.length && tokens[tokens.length - 1].type === 'comment') &&
  291. state === 'start' && indenter.test(line))
  292. indent += tab;
  293. return indent;
  294. };
  295. this.checkOutdent = function (state, line, input) {
  296. return this.$outdent.checkOutdent(line, input);
  297. };
  298. this.autoOutdent = function (state, doc, row) {
  299. this.$outdent.autoOutdent(doc, row);
  300. };
  301. this.createWorker = function (session) {
  302. var worker = new WorkerClient(["ace"], "ace/mode/coffee_worker", "Worker");
  303. worker.attachToDocument(session.getDocument());
  304. worker.on("annotate", function (e) {
  305. session.setAnnotations(e.data);
  306. });
  307. worker.on("terminate", function () {
  308. session.clearAnnotations();
  309. });
  310. return worker;
  311. };
  312. this.$id = "ace/mode/coffee";
  313. this.snippetFileId = "ace/snippets/coffee";
  314. }).call(Mode.prototype);
  315. exports.Mode = Mode;
  316. }); (function() {
  317. ace.require(["ace/mode/coffee"], function(m) {
  318. if (typeof module == "object" && typeof exports == "object" && module) {
  319. module.exports = m;
  320. }
  321. });
  322. })();