023f0a6de254bc2caa975f56d4b61243.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. ace.define("ace/mode/crystal_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. var CrystalHighlightRules = function () {
  5. var builtinFunctions = ("puts|initialize|previous_def|typeof|as|pointerof|sizeof|instance_sizeof");
  6. var keywords = ("if|end|else|elsif|unless|case|when|break|while|next|until|def|return|class|new|getter|setter|property|lib"
  7. + "|fun|do|struct|private|protected|public|module|super|abstract|include|extend|begin|enum|raise|yield|with"
  8. + "|alias|rescue|ensure|macro|uninitialized|union|type|require");
  9. var buildinConstants = ("true|TRUE|false|FALSE|nil|NIL|__LINE__|__END_LINE__|__FILE__|__DIR__");
  10. var builtinVariables = ("$DEBUG|$defout|$FILENAME|$LOAD_PATH|$SAFE|$stdin|$stdout|$stderr|$VERBOSE|" +
  11. "root_url|flash|session|cookies|params|request|response|logger|self");
  12. var keywordMapper = this.$keywords = this.createKeywordMapper({
  13. "keyword": keywords,
  14. "constant.language": buildinConstants,
  15. "variable.language": builtinVariables,
  16. "support.function": builtinFunctions
  17. }, "identifier");
  18. var hexNumber = "(?:0[xX][\\dA-Fa-f]+)";
  19. var decNumber = "(?:[0-9][\\d_]*)";
  20. var octNumber = "(?:0o[0-7][0-7]*)";
  21. var binNumber = "(?:0[bB][01]+)";
  22. var intNumber = "(?:[+-]?)(?:" + hexNumber + "|" + decNumber + "|" + octNumber + "|" + binNumber + ")(?:_?[iIuU](?:8|16|32|64))?\\b";
  23. var escapeExpression = /\\(?:[nsrtvfbae'"\\]|[0-7]{3}|x[\da-fA-F]{2}|u[\da-fA-F]{4}|u{[\da-fA-F]{1,6}})/;
  24. var extEscapeExspresssion = /\\(?:[nsrtvfbae'"\\]|[0-7]{3}|x[\da-fA-F]{2}|u[\da-fA-F]{4}|u{[\da-fA-F]{1,6}}|u{(:?[\da-fA-F]{2}\s)*[\da-fA-F]{2}})/;
  25. this.$rules = {
  26. "start": [
  27. {
  28. token: "comment",
  29. regex: "#.*$"
  30. }, {
  31. token: "string.regexp",
  32. regex: "[/]",
  33. push: [{
  34. token: "constant.language.escape",
  35. regex: extEscapeExspresssion
  36. }, {
  37. token: "string.regexp",
  38. regex: "[/][imx]*(?=[).,;\\s]|$)",
  39. next: "pop"
  40. }, {
  41. defaultToken: "string.regexp"
  42. }]
  43. },
  44. [{
  45. regex: "[{}]", onMatch: function (val, state, stack) {
  46. this.next = val == "{" ? this.nextState : "";
  47. if (val == "{" && stack.length) {
  48. stack.unshift("start", state);
  49. return "paren.lparen";
  50. }
  51. if (val == "}" && stack.length) {
  52. stack.shift();
  53. this.next = stack.shift();
  54. if (this.next.indexOf("string") != -1)
  55. return "paren.end";
  56. }
  57. return val == "{" ? "paren.lparen" : "paren.rparen";
  58. },
  59. nextState: "start"
  60. }, {
  61. token: "string.start",
  62. regex: /"/,
  63. push: [{
  64. token: "constant.language.escape",
  65. regex: extEscapeExspresssion
  66. }, {
  67. token: "string",
  68. regex: /\\#{/
  69. }, {
  70. token: "paren.start",
  71. regex: /#{/,
  72. push: "start"
  73. }, {
  74. token: "string.end",
  75. regex: /"/,
  76. next: "pop"
  77. }, {
  78. defaultToken: "string"
  79. }]
  80. }, {
  81. token: "string.start",
  82. regex: /`/,
  83. push: [{
  84. token: "constant.language.escape",
  85. regex: extEscapeExspresssion
  86. }, {
  87. token: "string",
  88. regex: /\\#{/
  89. }, {
  90. token: "paren.start",
  91. regex: /#{/,
  92. push: "start"
  93. }, {
  94. token: "string.end",
  95. regex: /`/,
  96. next: "pop"
  97. }, {
  98. defaultToken: "string"
  99. }]
  100. }, {
  101. stateName: "rpstring",
  102. token: "string.start",
  103. regex: /%[Qx]?\(/,
  104. push: [{
  105. token: "constant.language.escape",
  106. regex: extEscapeExspresssion
  107. }, {
  108. token: "string.start",
  109. regex: /\(/,
  110. push: "rpstring"
  111. }, {
  112. token: "string.end",
  113. regex: /\)/,
  114. next: "pop"
  115. }, {
  116. token: "paren.start",
  117. regex: /#{/,
  118. push: "start"
  119. }, {
  120. defaultToken: "string"
  121. }]
  122. }, {
  123. stateName: "spstring",
  124. token: "string.start",
  125. regex: /%[Qx]?\[/,
  126. push: [{
  127. token: "constant.language.escape",
  128. regex: extEscapeExspresssion
  129. }, {
  130. token: "string.start",
  131. regex: /\[/,
  132. push: "spstring"
  133. }, {
  134. token: "string.end",
  135. regex: /]/,
  136. next: "pop"
  137. }, {
  138. token: "paren.start",
  139. regex: /#{/,
  140. push: "start"
  141. }, {
  142. defaultToken: "string"
  143. }]
  144. }, {
  145. stateName: "fpstring",
  146. token: "string.start",
  147. regex: /%[Qx]?{/,
  148. push: [{
  149. token: "constant.language.escape",
  150. regex: extEscapeExspresssion
  151. }, {
  152. token: "string.start",
  153. regex: /{/,
  154. push: "fpstring"
  155. }, {
  156. token: "string.end",
  157. regex: /}/,
  158. next: "pop"
  159. }, {
  160. token: "paren.start",
  161. regex: /#{/,
  162. push: "start"
  163. }, {
  164. defaultToken: "string"
  165. }]
  166. }, {
  167. stateName: "tpstring",
  168. token: "string.start",
  169. regex: /%[Qx]?</,
  170. push: [{
  171. token: "constant.language.escape",
  172. regex: extEscapeExspresssion
  173. }, {
  174. token: "string.start",
  175. regex: /</,
  176. push: "tpstring"
  177. }, {
  178. token: "string.end",
  179. regex: />/,
  180. next: "pop"
  181. }, {
  182. token: "paren.start",
  183. regex: /#{/,
  184. push: "start"
  185. }, {
  186. defaultToken: "string"
  187. }]
  188. }, {
  189. stateName: "ppstring",
  190. token: "string.start",
  191. regex: /%[Qx]?\|/,
  192. push: [{
  193. token: "constant.language.escape",
  194. regex: extEscapeExspresssion
  195. }, {
  196. token: "string.end",
  197. regex: /\|/,
  198. next: "pop"
  199. }, {
  200. token: "paren.start",
  201. regex: /#{/,
  202. push: "start"
  203. }, {
  204. defaultToken: "string"
  205. }]
  206. }, {
  207. stateName: "rpqstring",
  208. token: "string.start",
  209. regex: /%[qwir]\(/,
  210. push: [{
  211. token: "string.start",
  212. regex: /\(/,
  213. push: "rpqstring"
  214. }, {
  215. token: "string.end",
  216. regex: /\)/,
  217. next: "pop"
  218. }, {
  219. defaultToken: "string"
  220. }]
  221. }, {
  222. stateName: "spqstring",
  223. token: "string.start",
  224. regex: /%[qwir]\[/,
  225. push: [{
  226. token: "string.start",
  227. regex: /\[/,
  228. push: "spqstring"
  229. }, {
  230. token: "string.end",
  231. regex: /]/,
  232. next: "pop"
  233. }, {
  234. defaultToken: "string"
  235. }]
  236. }, {
  237. stateName: "fpqstring",
  238. token: "string.start",
  239. regex: /%[qwir]{/,
  240. push: [{
  241. token: "string.start",
  242. regex: /{/,
  243. push: "fpqstring"
  244. }, {
  245. token: "string.end",
  246. regex: /}/,
  247. next: "pop"
  248. }, {
  249. defaultToken: "string"
  250. }]
  251. }, {
  252. stateName: "tpqstring",
  253. token: "string.start",
  254. regex: /%[qwir]</,
  255. push: [{
  256. token: "string.start",
  257. regex: /</,
  258. push: "tpqstring"
  259. }, {
  260. token: "string.end",
  261. regex: />/,
  262. next: "pop"
  263. }, {
  264. defaultToken: "string"
  265. }]
  266. }, {
  267. stateName: "ppqstring",
  268. token: "string.start",
  269. regex: /%[qwir]\|/,
  270. push: [{
  271. token: "string.end",
  272. regex: /\|/,
  273. next: "pop"
  274. }, {
  275. defaultToken: "string"
  276. }]
  277. }, {
  278. token: "string.start",
  279. regex: /'/,
  280. push: [{
  281. token: "constant.language.escape",
  282. regex: escapeExpression
  283. }, {
  284. token: "string.end",
  285. regex: /'|$/,
  286. next: "pop"
  287. }, {
  288. defaultToken: "string"
  289. }]
  290. }], {
  291. token: "text",
  292. regex: "::"
  293. }, {
  294. token: "variable.instance",
  295. regex: "@{1,2}[a-zA-Z_\\d]+"
  296. }, {
  297. token: "variable.fresh",
  298. regex: "%[a-zA-Z_\\d]+"
  299. }, {
  300. token: "support.class",
  301. regex: "[A-Z][a-zA-Z_\\d]+"
  302. }, {
  303. token: "constant.other.symbol",
  304. regex: "[:](?:(?:===|<=>|\\[]\\?|\\[]=|\\[]|>>|\\*\\*|<<|==|!=|>=|<=|!~|=~|<|\\+|-|\\*|\\/|%|&|\\||\\^|>|!|~)|(?:(?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?))"
  305. }, {
  306. token: "constant.numeric",
  307. regex: "[+-]?\\d(?:\\d|_(?=\\d))*(?:(?:\\.\\d(?:\\d|_(?=\\d))*)?(?:[eE][+-]?\\d+)?)?(?:_?[fF](?:32|64))?\\b"
  308. }, {
  309. token: "constant.numeric",
  310. regex: intNumber
  311. }, {
  312. token: "constant.other.symbol",
  313. regex: ':"',
  314. push: [{
  315. token: "constant.language.escape",
  316. regex: extEscapeExspresssion
  317. }, {
  318. token: "constant.other.symbol",
  319. regex: '"',
  320. next: "pop"
  321. }, {
  322. defaultToken: "constant.other.symbol"
  323. }]
  324. }, {
  325. token: "constant.language.boolean",
  326. regex: "(?:true|false)\\b"
  327. }, {
  328. token: "support.function",
  329. regex: "(?:is_a\\?|nil\\?|responds_to\\?|as\\?)"
  330. }, {
  331. token: keywordMapper,
  332. regex: "[a-zA-Z_$][a-zA-Z0-9_$!?]*\\b"
  333. }, {
  334. token: "variable.system",
  335. regex: "\\$\\!|\\$\\?"
  336. }, {
  337. token: "punctuation.separator.key-value",
  338. regex: "=>"
  339. }, {
  340. stateName: "heredoc",
  341. onMatch: function (value, currentState, stack) {
  342. var next = "heredoc";
  343. var tokens = value.split(this.splitRegex);
  344. stack.push(next, tokens[3]);
  345. return [
  346. { type: "constant", value: tokens[1] },
  347. { type: "string", value: tokens[2] },
  348. { type: "support.class", value: tokens[3] },
  349. { type: "string", value: tokens[4] }
  350. ];
  351. },
  352. regex: "(<<-)([']?)([\\w]+)([']?)",
  353. rules: {
  354. heredoc: [{
  355. token: "string",
  356. regex: "^ +"
  357. }, {
  358. onMatch: function (value, currentState, stack) {
  359. if (value === stack[1]) {
  360. stack.shift();
  361. stack.shift();
  362. this.next = stack[0] || "start";
  363. return "support.class";
  364. }
  365. this.next = "";
  366. return "string";
  367. },
  368. regex: ".*$",
  369. next: "start"
  370. }]
  371. }
  372. }, {
  373. regex: "$",
  374. token: "empty",
  375. next: function (currentState, stack) {
  376. if (stack[0] === "heredoc")
  377. return stack[0];
  378. return currentState;
  379. }
  380. }, {
  381. token: "punctuation.operator",
  382. regex: /[.]\s*(?![.])/,
  383. push: [{
  384. token: "punctuation.operator",
  385. regex: /[.]\s*(?![.])/
  386. }, {
  387. token: "support.function",
  388. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  389. }, {
  390. regex: "",
  391. token: "empty",
  392. next: "pop"
  393. }]
  394. }, {
  395. token: "keyword.operator",
  396. regex: "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|\\?|\\:|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\^|\\|"
  397. }, {
  398. token: "punctuation.operator",
  399. regex: /[?:,;.]/
  400. }, {
  401. token: "paren.lparen",
  402. regex: "[[({]"
  403. }, {
  404. token: "paren.rparen",
  405. regex: "[\\])}]"
  406. }, {
  407. token: "text",
  408. regex: "\\s+"
  409. }
  410. ]
  411. };
  412. this.normalizeRules();
  413. };
  414. oop.inherits(CrystalHighlightRules, TextHighlightRules);
  415. exports.CrystalHighlightRules = CrystalHighlightRules;
  416. });
  417. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  418. var Range = require("../range").Range;
  419. var MatchingBraceOutdent = function () { };
  420. (function () {
  421. this.checkOutdent = function (line, input) {
  422. if (!/^\s+$/.test(line))
  423. return false;
  424. return /^\s*\}/.test(input);
  425. };
  426. this.autoOutdent = function (doc, row) {
  427. var line = doc.getLine(row);
  428. var match = line.match(/^(\s*\})/);
  429. if (!match)
  430. return 0;
  431. var column = match[1].length;
  432. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  433. if (!openBracePos || openBracePos.row == row)
  434. return 0;
  435. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  436. doc.replace(new Range(row, 0, row, column - 1), indent);
  437. };
  438. this.$getIndent = function (line) {
  439. return line.match(/^\s*/)[0];
  440. };
  441. }).call(MatchingBraceOutdent.prototype);
  442. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  443. });
  444. 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";
  445. var oop = require("../../lib/oop");
  446. var BaseFoldMode = require("./fold_mode").FoldMode;
  447. var Range = require("../../range").Range;
  448. var FoldMode = exports.FoldMode = function () { };
  449. oop.inherits(FoldMode, BaseFoldMode);
  450. (function () {
  451. this.getFoldWidgetRange = function (session, foldStyle, row) {
  452. var range = this.indentationBlock(session, row);
  453. if (range)
  454. return range;
  455. var re = /\S/;
  456. var line = session.getLine(row);
  457. var startLevel = line.search(re);
  458. if (startLevel == -1 || line[startLevel] != "#")
  459. return;
  460. var startColumn = line.length;
  461. var maxRow = session.getLength();
  462. var startRow = row;
  463. var endRow = row;
  464. while (++row < maxRow) {
  465. line = session.getLine(row);
  466. var level = line.search(re);
  467. if (level == -1)
  468. continue;
  469. if (line[level] != "#")
  470. break;
  471. endRow = row;
  472. }
  473. if (endRow > startRow) {
  474. var endColumn = session.getLine(endRow).length;
  475. return new Range(startRow, startColumn, endRow, endColumn);
  476. }
  477. };
  478. this.getFoldWidget = function (session, foldStyle, row) {
  479. var line = session.getLine(row);
  480. var indent = line.search(/\S/);
  481. var next = session.getLine(row + 1);
  482. var prev = session.getLine(row - 1);
  483. var prevIndent = prev.search(/\S/);
  484. var nextIndent = next.search(/\S/);
  485. if (indent == -1) {
  486. session.foldWidgets[row - 1] = prevIndent != -1 && prevIndent < nextIndent ? "start" : "";
  487. return "";
  488. }
  489. if (prevIndent == -1) {
  490. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  491. session.foldWidgets[row - 1] = "";
  492. session.foldWidgets[row + 1] = "";
  493. return "start";
  494. }
  495. }
  496. else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  497. if (session.getLine(row - 2).search(/\S/) == -1) {
  498. session.foldWidgets[row - 1] = "start";
  499. session.foldWidgets[row + 1] = "";
  500. return "";
  501. }
  502. }
  503. if (prevIndent != -1 && prevIndent < indent)
  504. session.foldWidgets[row - 1] = "start";
  505. else
  506. session.foldWidgets[row - 1] = "";
  507. if (indent < nextIndent)
  508. return "start";
  509. else
  510. return "";
  511. };
  512. }).call(FoldMode.prototype);
  513. });
  514. ace.define("ace/mode/crystal",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/crystal_highlight_rules","ace/mode/matching_brace_outdent","ace/range","ace/mode/behaviour/cstyle","ace/mode/folding/coffee"], function(require, exports, module){"use strict";
  515. var oop = require("../lib/oop");
  516. var TextMode = require("./text").Mode;
  517. var CrystalHighlightRules = require("./crystal_highlight_rules").CrystalHighlightRules;
  518. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  519. var Range = require("../range").Range;
  520. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  521. var FoldMode = require("./folding/coffee").FoldMode;
  522. var Mode = function () {
  523. this.HighlightRules = CrystalHighlightRules;
  524. this.$outdent = new MatchingBraceOutdent();
  525. this.$behaviour = new CstyleBehaviour();
  526. this.foldingRules = new FoldMode();
  527. };
  528. oop.inherits(Mode, TextMode);
  529. (function () {
  530. this.lineCommentStart = "#";
  531. this.getNextLineIndent = function (state, line, tab) {
  532. var indent = this.$getIndent(line);
  533. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  534. var tokens = tokenizedLine.tokens;
  535. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  536. return indent;
  537. }
  538. if (state == "start") {
  539. var match = line.match(/^.*[\{\(\[]\s*$/);
  540. var startingClassOrMethod = line.match(/^\s*(class|def|module)\s.*$/);
  541. var startingDoBlock = line.match(/.*do(\s*|\s+\|.*\|\s*)$/);
  542. var startingConditional = line.match(/^\s*(if|else|when)\s*/);
  543. if (match || startingClassOrMethod || startingDoBlock || startingConditional) {
  544. indent += tab;
  545. }
  546. }
  547. return indent;
  548. };
  549. this.checkOutdent = function (state, line, input) {
  550. return /^\s+(end|else)$/.test(line + input) || this.$outdent.checkOutdent(line, input);
  551. };
  552. this.autoOutdent = function (state, session, row) {
  553. var line = session.getLine(row);
  554. if (/}/.test(line))
  555. return this.$outdent.autoOutdent(session, row);
  556. var indent = this.$getIndent(line);
  557. var prevLine = session.getLine(row - 1);
  558. var prevIndent = this.$getIndent(prevLine);
  559. var tab = session.getTabString();
  560. if (prevIndent.length <= indent.length) {
  561. if (indent.slice(-tab.length) == tab)
  562. session.remove(new Range(row, indent.length - tab.length, row, indent.length));
  563. }
  564. };
  565. this.$id = "ace/mode/crystal";
  566. }).call(Mode.prototype);
  567. exports.Mode = Mode;
  568. }); (function() {
  569. ace.require(["ace/mode/crystal"], function(m) {
  570. if (typeof module == "object" && typeof exports == "object" && module) {
  571. module.exports = m;
  572. }
  573. });
  574. })();