89ebd0e0e6e5662cea81597f2e4ba9b7.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. ace.define("ace/mode/doc_comment_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 DocCommentHighlightRules = function () {
  5. this.$rules = {
  6. "start": [{
  7. token: "comment.doc.tag",
  8. regex: "@[\\w\\d_]+" // TODO: fix email addresses
  9. },
  10. DocCommentHighlightRules.getTagRule(),
  11. {
  12. defaultToken: "comment.doc",
  13. caseInsensitive: true
  14. }]
  15. };
  16. };
  17. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  18. DocCommentHighlightRules.getTagRule = function (start) {
  19. return {
  20. token: "comment.doc.tag.storage.type",
  21. regex: "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  22. };
  23. };
  24. DocCommentHighlightRules.getStartRule = function (start) {
  25. return {
  26. token: "comment.doc",
  27. regex: "\\/\\*(?=\\*)",
  28. next: start
  29. };
  30. };
  31. DocCommentHighlightRules.getEndRule = function (start) {
  32. return {
  33. token: "comment.doc",
  34. regex: "\\*\\/",
  35. next: start
  36. };
  37. };
  38. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  39. });
  40. ace.define("ace/mode/jsx_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module){var oop = require("../lib/oop");
  41. var lang = require("../lib/lang");
  42. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  43. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  44. var JsxHighlightRules = function () {
  45. var keywords = lang.arrayToMap(("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
  46. "if|throw|" +
  47. "delete|in|try|" +
  48. "class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
  49. "number|int|string|boolean|variant|" +
  50. "log|assert").split("|"));
  51. var buildinConstants = lang.arrayToMap(("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|"));
  52. var reserved = lang.arrayToMap(("debugger|with|" +
  53. "const|export|" +
  54. "let|private|public|yield|protected|" +
  55. "extern|native|as|operator|__fake__|__readonly__").split("|"));
  56. var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
  57. this.$rules = {
  58. "start": [
  59. {
  60. token: "comment",
  61. regex: "\\/\\/.*$"
  62. },
  63. DocCommentHighlightRules.getStartRule("doc-start"),
  64. {
  65. token: "comment",
  66. regex: "\\/\\*",
  67. next: "comment"
  68. }, {
  69. token: "string.regexp",
  70. regex: "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  71. }, {
  72. token: "string",
  73. regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  74. }, {
  75. token: "string",
  76. regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  77. }, {
  78. token: "constant.numeric",
  79. regex: "0[xX][0-9a-fA-F]+\\b"
  80. }, {
  81. token: "constant.numeric",
  82. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  83. }, {
  84. token: "constant.language.boolean",
  85. regex: "(?:true|false)\\b"
  86. }, {
  87. token: [
  88. "storage.type",
  89. "text",
  90. "entity.name.function"
  91. ],
  92. regex: "(function)(\\s+)(" + identifierRe + ")"
  93. }, {
  94. token: function (value) {
  95. if (value == "this")
  96. return "variable.language";
  97. else if (value == "function")
  98. return "storage.type";
  99. else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
  100. return "keyword";
  101. else if (buildinConstants.hasOwnProperty(value))
  102. return "constant.language";
  103. else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
  104. return "language.support.class";
  105. else
  106. return "identifier";
  107. },
  108. regex: identifierRe
  109. }, {
  110. token: "keyword.operator",
  111. regex: "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  112. }, {
  113. token: "punctuation.operator",
  114. regex: "\\?|\\:|\\,|\\;|\\."
  115. }, {
  116. token: "paren.lparen",
  117. regex: "[[({<]"
  118. }, {
  119. token: "paren.rparen",
  120. regex: "[\\])}>]"
  121. }, {
  122. token: "text",
  123. regex: "\\s+"
  124. }
  125. ],
  126. "comment": [
  127. {
  128. token: "comment",
  129. regex: "\\*\\/",
  130. next: "start"
  131. }, {
  132. defaultToken: "comment"
  133. }
  134. ]
  135. };
  136. this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
  137. };
  138. oop.inherits(JsxHighlightRules, TextHighlightRules);
  139. exports.JsxHighlightRules = JsxHighlightRules;
  140. });
  141. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  142. var Range = require("../range").Range;
  143. var MatchingBraceOutdent = function () { };
  144. (function () {
  145. this.checkOutdent = function (line, input) {
  146. if (!/^\s+$/.test(line))
  147. return false;
  148. return /^\s*\}/.test(input);
  149. };
  150. this.autoOutdent = function (doc, row) {
  151. var line = doc.getLine(row);
  152. var match = line.match(/^(\s*\})/);
  153. if (!match)
  154. return 0;
  155. var column = match[1].length;
  156. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  157. if (!openBracePos || openBracePos.row == row)
  158. return 0;
  159. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  160. doc.replace(new Range(row, 0, row, column - 1), indent);
  161. };
  162. this.$getIndent = function (line) {
  163. return line.match(/^\s*/)[0];
  164. };
  165. }).call(MatchingBraceOutdent.prototype);
  166. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  167. });
  168. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  169. var oop = require("../../lib/oop");
  170. var Range = require("../../range").Range;
  171. var BaseFoldMode = require("./fold_mode").FoldMode;
  172. var FoldMode = exports.FoldMode = function (commentRegex) {
  173. if (commentRegex) {
  174. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  175. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  176. }
  177. };
  178. oop.inherits(FoldMode, BaseFoldMode);
  179. (function () {
  180. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  181. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  182. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  183. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  184. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  185. this._getFoldWidgetBase = this.getFoldWidget;
  186. this.getFoldWidget = function (session, foldStyle, row) {
  187. var line = session.getLine(row);
  188. if (this.singleLineBlockCommentRe.test(line)) {
  189. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  190. return "";
  191. }
  192. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  193. if (!fw && this.startRegionRe.test(line))
  194. return "start"; // lineCommentRegionStart
  195. return fw;
  196. };
  197. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  198. var line = session.getLine(row);
  199. if (this.startRegionRe.test(line))
  200. return this.getCommentRegionBlock(session, line, row);
  201. var match = line.match(this.foldingStartMarker);
  202. if (match) {
  203. var i = match.index;
  204. if (match[1])
  205. return this.openingBracketBlock(session, match[1], row, i);
  206. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  207. if (range && !range.isMultiLine()) {
  208. if (forceMultiline) {
  209. range = this.getSectionRange(session, row);
  210. }
  211. else if (foldStyle != "all")
  212. range = null;
  213. }
  214. return range;
  215. }
  216. if (foldStyle === "markbegin")
  217. return;
  218. var match = line.match(this.foldingStopMarker);
  219. if (match) {
  220. var i = match.index + match[0].length;
  221. if (match[1])
  222. return this.closingBracketBlock(session, match[1], row, i);
  223. return session.getCommentFoldRange(row, i, -1);
  224. }
  225. };
  226. this.getSectionRange = function (session, row) {
  227. var line = session.getLine(row);
  228. var startIndent = line.search(/\S/);
  229. var startRow = row;
  230. var startColumn = line.length;
  231. row = row + 1;
  232. var endRow = row;
  233. var maxRow = session.getLength();
  234. while (++row < maxRow) {
  235. line = session.getLine(row);
  236. var indent = line.search(/\S/);
  237. if (indent === -1)
  238. continue;
  239. if (startIndent > indent)
  240. break;
  241. var subRange = this.getFoldWidgetRange(session, "all", row);
  242. if (subRange) {
  243. if (subRange.start.row <= startRow) {
  244. break;
  245. }
  246. else if (subRange.isMultiLine()) {
  247. row = subRange.end.row;
  248. }
  249. else if (startIndent == indent) {
  250. break;
  251. }
  252. }
  253. endRow = row;
  254. }
  255. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  256. };
  257. this.getCommentRegionBlock = function (session, line, row) {
  258. var startColumn = line.search(/\s*$/);
  259. var maxRow = session.getLength();
  260. var startRow = row;
  261. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  262. var depth = 1;
  263. while (++row < maxRow) {
  264. line = session.getLine(row);
  265. var m = re.exec(line);
  266. if (!m)
  267. continue;
  268. if (m[1])
  269. depth--;
  270. else
  271. depth++;
  272. if (!depth)
  273. break;
  274. }
  275. var endRow = row;
  276. if (endRow > startRow) {
  277. return new Range(startRow, startColumn, endRow, line.length);
  278. }
  279. };
  280. }).call(FoldMode.prototype);
  281. });
  282. ace.define("ace/mode/jsx",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/jsx_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
  283. var oop = require("../lib/oop");
  284. var TextMode = require("./text").Mode;
  285. var JsxHighlightRules = require("./jsx_highlight_rules").JsxHighlightRules;
  286. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  287. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  288. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  289. function Mode() {
  290. this.HighlightRules = JsxHighlightRules;
  291. this.$outdent = new MatchingBraceOutdent();
  292. this.$behaviour = new CstyleBehaviour();
  293. this.foldingRules = new CStyleFoldMode();
  294. }
  295. oop.inherits(Mode, TextMode);
  296. (function () {
  297. this.lineCommentStart = "//";
  298. this.blockComment = { start: "/*", end: "*/" };
  299. this.getNextLineIndent = function (state, line, tab) {
  300. var indent = this.$getIndent(line);
  301. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  302. var tokens = tokenizedLine.tokens;
  303. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  304. return indent;
  305. }
  306. if (state == "start") {
  307. var match = line.match(/^.*[\{\(\[]\s*$/);
  308. if (match) {
  309. indent += tab;
  310. }
  311. }
  312. return indent;
  313. };
  314. this.checkOutdent = function (state, line, input) {
  315. return this.$outdent.checkOutdent(line, input);
  316. };
  317. this.autoOutdent = function (state, doc, row) {
  318. this.$outdent.autoOutdent(doc, row);
  319. };
  320. this.$id = "ace/mode/jsx";
  321. }).call(Mode.prototype);
  322. exports.Mode = Mode;
  323. }); (function() {
  324. ace.require(["ace/mode/jsx"], function(m) {
  325. if (typeof module == "object" && typeof exports == "object" && module) {
  326. module.exports = m;
  327. }
  328. });
  329. })();