PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/bower_components/ace-builds/src-noconflict/mode-coffee.js

https://gitlab.com/baihaqyaviq/jspdf
JavaScript | 393 lines | 330 code | 63 blank | 0 comment | 42 complexity | 4de6290be5b470549462dadb5ee8c1f1 MD5 | raw file
  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 : "\\.{1,3}"
  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. this.lineCommentStart = "#";
  299. this.blockComment = {start: "###", end: "###"};
  300. this.getNextLineIndent = function(state, line, tab) {
  301. var indent = this.$getIndent(line);
  302. var tokens = this.getTokenizer().getLineTokens(line, state).tokens;
  303. if (!(tokens.length && tokens[tokens.length - 1].type === 'comment') &&
  304. state === 'start' && indenter.test(line))
  305. indent += tab;
  306. return indent;
  307. };
  308. this.checkOutdent = function(state, line, input) {
  309. return this.$outdent.checkOutdent(line, input);
  310. };
  311. this.autoOutdent = function(state, doc, row) {
  312. this.$outdent.autoOutdent(doc, row);
  313. };
  314. this.createWorker = function(session) {
  315. var worker = new WorkerClient(["ace"], "ace/mode/coffee_worker", "Worker");
  316. worker.attachToDocument(session.getDocument());
  317. worker.on("annotate", function(e) {
  318. session.setAnnotations(e.data);
  319. });
  320. worker.on("terminate", function() {
  321. session.clearAnnotations();
  322. });
  323. return worker;
  324. };
  325. this.$id = "ace/mode/coffee";
  326. }).call(Mode.prototype);
  327. exports.Mode = Mode;
  328. });