Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mode-coffee.js 15KB

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