Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. ace.define("ace/mode/doc_comment_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. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. }
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. 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) {
  42. var oop = require("../lib/oop");
  43. var lang = require("../lib/lang");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var JsxHighlightRules = function() {
  47. var keywords = lang.arrayToMap(
  48. ("break|do|instanceof|typeof|case|else|new|var|catch|finally|return|void|continue|for|switch|default|while|function|this|" +
  49. "if|throw|" +
  50. "delete|in|try|" +
  51. "class|extends|super|import|from|into|implements|interface|static|mixin|override|abstract|final|" +
  52. "number|int|string|boolean|variant|" +
  53. "log|assert").split("|")
  54. );
  55. var buildinConstants = lang.arrayToMap(
  56. ("null|true|false|NaN|Infinity|__FILE__|__LINE__|undefined").split("|")
  57. );
  58. var reserved = lang.arrayToMap(
  59. ("debugger|with|" +
  60. "const|export|" +
  61. "let|private|public|yield|protected|" +
  62. "extern|native|as|operator|__fake__|__readonly__").split("|")
  63. );
  64. var identifierRe = "[a-zA-Z_][a-zA-Z0-9_]*\\b";
  65. this.$rules = {
  66. "start" : [
  67. {
  68. token : "comment",
  69. regex : "\\/\\/.*$"
  70. },
  71. DocCommentHighlightRules.getStartRule("doc-start"),
  72. {
  73. token : "comment", // multi line comment
  74. regex : "\\/\\*",
  75. next : "comment"
  76. }, {
  77. token : "string.regexp",
  78. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  79. }, {
  80. token : "string", // single line
  81. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  82. }, {
  83. token : "string", // single line
  84. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  85. }, {
  86. token : "constant.numeric", // hex
  87. regex : "0[xX][0-9a-fA-F]+\\b"
  88. }, {
  89. token : "constant.numeric", // float
  90. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  91. }, {
  92. token : "constant.language.boolean",
  93. regex : "(?:true|false)\\b"
  94. }, {
  95. token : [
  96. "storage.type",
  97. "text",
  98. "entity.name.function"
  99. ],
  100. regex : "(function)(\\s+)(" + identifierRe + ")"
  101. }, {
  102. token : function(value) {
  103. if (value == "this")
  104. return "variable.language";
  105. else if (value == "function")
  106. return "storage.type";
  107. else if (keywords.hasOwnProperty(value) || reserved.hasOwnProperty(value))
  108. return "keyword";
  109. else if (buildinConstants.hasOwnProperty(value))
  110. return "constant.language";
  111. else if (/^_?[A-Z][a-zA-Z0-9_]*$/.test(value))
  112. return "language.support.class";
  113. else
  114. return "identifier";
  115. },
  116. regex : identifierRe
  117. }, {
  118. token : "keyword.operator",
  119. regex : "!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  120. }, {
  121. token : "punctuation.operator",
  122. regex : "\\?|\\:|\\,|\\;|\\."
  123. }, {
  124. token : "paren.lparen",
  125. regex : "[[({<]"
  126. }, {
  127. token : "paren.rparen",
  128. regex : "[\\])}>]"
  129. }, {
  130. token : "text",
  131. regex : "\\s+"
  132. }
  133. ],
  134. "comment" : [
  135. {
  136. token : "comment", // closing comment
  137. regex : ".*?\\*\\/",
  138. next : "start"
  139. }, {
  140. token : "comment", // comment spanning whole line
  141. regex : ".+"
  142. }
  143. ]
  144. };
  145. this.embedRules(DocCommentHighlightRules, "doc-",
  146. [ DocCommentHighlightRules.getEndRule("start") ]);
  147. };
  148. oop.inherits(JsxHighlightRules, TextHighlightRules);
  149. exports.JsxHighlightRules = JsxHighlightRules;
  150. });
  151. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  152. "use strict";
  153. var Range = require("../range").Range;
  154. var MatchingBraceOutdent = function() {};
  155. (function() {
  156. this.checkOutdent = function(line, input) {
  157. if (! /^\s+$/.test(line))
  158. return false;
  159. return /^\s*\}/.test(input);
  160. };
  161. this.autoOutdent = function(doc, row) {
  162. var line = doc.getLine(row);
  163. var match = line.match(/^(\s*\})/);
  164. if (!match) return 0;
  165. var column = match[1].length;
  166. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  167. if (!openBracePos || openBracePos.row == row) return 0;
  168. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  169. doc.replace(new Range(row, 0, row, column-1), indent);
  170. };
  171. this.$getIndent = function(line) {
  172. return line.match(/^\s*/)[0];
  173. };
  174. }).call(MatchingBraceOutdent.prototype);
  175. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  176. });
  177. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  178. "use strict";
  179. var oop = require("../../lib/oop");
  180. var Behaviour = require("../behaviour").Behaviour;
  181. var TokenIterator = require("../../token_iterator").TokenIterator;
  182. var lang = require("../../lib/lang");
  183. var SAFE_INSERT_IN_TOKENS =
  184. ["text", "paren.rparen", "punctuation.operator"];
  185. var SAFE_INSERT_BEFORE_TOKENS =
  186. ["text", "paren.rparen", "punctuation.operator", "comment"];
  187. var context;
  188. var contextCache = {};
  189. var initContext = function(editor) {
  190. var id = -1;
  191. if (editor.multiSelect) {
  192. id = editor.selection.index;
  193. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  194. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  195. }
  196. if (contextCache[id])
  197. return context = contextCache[id];
  198. context = contextCache[id] = {
  199. autoInsertedBrackets: 0,
  200. autoInsertedRow: -1,
  201. autoInsertedLineEnd: "",
  202. maybeInsertedBrackets: 0,
  203. maybeInsertedRow: -1,
  204. maybeInsertedLineStart: "",
  205. maybeInsertedLineEnd: ""
  206. };
  207. };
  208. var CstyleBehaviour = function() {
  209. this.add("braces", "insertion", function(state, action, editor, session, text) {
  210. var cursor = editor.getCursorPosition();
  211. var line = session.doc.getLine(cursor.row);
  212. if (text == '{') {
  213. initContext(editor);
  214. var selection = editor.getSelectionRange();
  215. var selected = session.doc.getTextRange(selection);
  216. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  217. return {
  218. text: '{' + selected + '}',
  219. selection: false
  220. };
  221. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  222. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  223. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  224. return {
  225. text: '{}',
  226. selection: [1, 1]
  227. };
  228. } else {
  229. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  230. return {
  231. text: '{',
  232. selection: [1, 1]
  233. };
  234. }
  235. }
  236. } else if (text == '}') {
  237. initContext(editor);
  238. var rightChar = line.substring(cursor.column, cursor.column + 1);
  239. if (rightChar == '}') {
  240. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  241. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  242. CstyleBehaviour.popAutoInsertedClosing();
  243. return {
  244. text: '',
  245. selection: [1, 1]
  246. };
  247. }
  248. }
  249. } else if (text == "\n" || text == "\r\n") {
  250. initContext(editor);
  251. var closing = "";
  252. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  253. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  254. CstyleBehaviour.clearMaybeInsertedClosing();
  255. }
  256. var rightChar = line.substring(cursor.column, cursor.column + 1);
  257. if (rightChar === '}') {
  258. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  259. if (!openBracePos)
  260. return null;
  261. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  262. } else if (closing) {
  263. var next_indent = this.$getIndent(line);
  264. } else {
  265. CstyleBehaviour.clearMaybeInsertedClosing();
  266. return;
  267. }
  268. var indent = next_indent + session.getTabString();
  269. return {
  270. text: '\n' + indent + '\n' + next_indent + closing,
  271. selection: [1, indent.length, 1, indent.length]
  272. };
  273. } else {
  274. CstyleBehaviour.clearMaybeInsertedClosing();
  275. }
  276. });
  277. this.add("braces", "deletion", function(state, action, editor, session, range) {
  278. var selected = session.doc.getTextRange(range);
  279. if (!range.isMultiLine() && selected == '{') {
  280. initContext(editor);
  281. var line = session.doc.getLine(range.start.row);
  282. var rightChar = line.substring(range.end.column, range.end.column + 1);
  283. if (rightChar == '}') {
  284. range.end.column++;
  285. return range;
  286. } else {
  287. context.maybeInsertedBrackets--;
  288. }
  289. }
  290. });
  291. this.add("parens", "insertion", function(state, action, editor, session, text) {
  292. if (text == '(') {
  293. initContext(editor);
  294. var selection = editor.getSelectionRange();
  295. var selected = session.doc.getTextRange(selection);
  296. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  297. return {
  298. text: '(' + selected + ')',
  299. selection: false
  300. };
  301. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  302. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  303. return {
  304. text: '()',
  305. selection: [1, 1]
  306. };
  307. }
  308. } else if (text == ')') {
  309. initContext(editor);
  310. var cursor = editor.getCursorPosition();
  311. var line = session.doc.getLine(cursor.row);
  312. var rightChar = line.substring(cursor.column, cursor.column + 1);
  313. if (rightChar == ')') {
  314. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  315. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  316. CstyleBehaviour.popAutoInsertedClosing();
  317. return {
  318. text: '',
  319. selection: [1, 1]
  320. };
  321. }
  322. }
  323. }
  324. });
  325. this.add("parens", "deletion", function(state, action, editor, session, range) {
  326. var selected = session.doc.getTextRange(range);
  327. if (!range.isMultiLine() && selected == '(') {
  328. initContext(editor);
  329. var line = session.doc.getLine(range.start.row);
  330. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  331. if (rightChar == ')') {
  332. range.end.column++;
  333. return range;
  334. }
  335. }
  336. });
  337. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  338. if (text == '[') {
  339. initContext(editor);
  340. var selection = editor.getSelectionRange();
  341. var selected = session.doc.getTextRange(selection);
  342. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  343. return {
  344. text: '[' + selected + ']',
  345. selection: false
  346. };
  347. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  348. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  349. return {
  350. text: '[]',
  351. selection: [1, 1]
  352. };
  353. }
  354. } else if (text == ']') {
  355. initContext(editor);
  356. var cursor = editor.getCursorPosition();
  357. var line = session.doc.getLine(cursor.row);
  358. var rightChar = line.substring(cursor.column, cursor.column + 1);
  359. if (rightChar == ']') {
  360. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  361. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  362. CstyleBehaviour.popAutoInsertedClosing();
  363. return {
  364. text: '',
  365. selection: [1, 1]
  366. };
  367. }
  368. }
  369. }
  370. });
  371. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  372. var selected = session.doc.getTextRange(range);
  373. if (!range.isMultiLine() && selected == '[') {
  374. initContext(editor);
  375. var line = session.doc.getLine(range.start.row);
  376. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  377. if (rightChar == ']') {
  378. range.end.column++;
  379. return range;
  380. }
  381. }
  382. });
  383. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  384. if (text == '"' || text == "'") {
  385. initContext(editor);
  386. var quote = text;
  387. var selection = editor.getSelectionRange();
  388. var selected = session.doc.getTextRange(selection);
  389. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  390. return {
  391. text: quote + selected + quote,
  392. selection: false
  393. };
  394. } else {
  395. var cursor = editor.getCursorPosition();
  396. var line = session.doc.getLine(cursor.row);
  397. var leftChar = line.substring(cursor.column-1, cursor.column);
  398. var rightChar = line.substring(cursor.column, cursor.column + 1);
  399. var token = session.getTokenAt(cursor.row, cursor.column);
  400. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  401. if (leftChar == "\\" && token && /escape/.test(token.type))
  402. return null;
  403. var stringBefore = token && /string/.test(token.type);
  404. var stringAfter = !rightToken || /string/.test(rightToken.type);
  405. var pair;
  406. if (rightChar == quote) {
  407. pair = stringBefore !== stringAfter;
  408. } else {
  409. if (stringBefore && !stringAfter)
  410. return null; // wrap string with different quote
  411. if (stringBefore && stringAfter)
  412. return null; // do not pair quotes inside strings
  413. var wordRe = session.$mode.tokenRe;
  414. wordRe.lastIndex = 0;
  415. var isWordBefore = wordRe.test(leftChar);
  416. wordRe.lastIndex = 0;
  417. var isWordAfter = wordRe.test(leftChar);
  418. if (isWordBefore || isWordAfter)
  419. return null; // before or after alphanumeric
  420. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  421. return null; // there is rightChar and it isn't closing
  422. pair = true;
  423. }
  424. return {
  425. text: pair ? quote + quote : "",
  426. selection: [1,1]
  427. };
  428. }
  429. }
  430. });
  431. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  432. var selected = session.doc.getTextRange(range);
  433. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  434. initContext(editor);
  435. var line = session.doc.getLine(range.start.row);
  436. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  437. if (rightChar == selected) {
  438. range.end.column++;
  439. return range;
  440. }
  441. }
  442. });
  443. };
  444. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  445. var cursor = editor.getCursorPosition();
  446. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  447. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  448. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  449. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  450. return false;
  451. }
  452. iterator.stepForward();
  453. return iterator.getCurrentTokenRow() !== cursor.row ||
  454. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  455. };
  456. CstyleBehaviour.$matchTokenType = function(token, types) {
  457. return types.indexOf(token.type || token) > -1;
  458. };
  459. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  460. var cursor = editor.getCursorPosition();
  461. var line = session.doc.getLine(cursor.row);
  462. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  463. context.autoInsertedBrackets = 0;
  464. context.autoInsertedRow = cursor.row;
  465. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  466. context.autoInsertedBrackets++;
  467. };
  468. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  469. var cursor = editor.getCursorPosition();
  470. var line = session.doc.getLine(cursor.row);
  471. if (!this.isMaybeInsertedClosing(cursor, line))
  472. context.maybeInsertedBrackets = 0;
  473. context.maybeInsertedRow = cursor.row;
  474. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  475. context.maybeInsertedLineEnd = line.substr(cursor.column);
  476. context.maybeInsertedBrackets++;
  477. };
  478. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  479. return context.autoInsertedBrackets > 0 &&
  480. cursor.row === context.autoInsertedRow &&
  481. bracket === context.autoInsertedLineEnd[0] &&
  482. line.substr(cursor.column) === context.autoInsertedLineEnd;
  483. };
  484. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  485. return context.maybeInsertedBrackets > 0 &&
  486. cursor.row === context.maybeInsertedRow &&
  487. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  488. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  489. };
  490. CstyleBehaviour.popAutoInsertedClosing = function() {
  491. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  492. context.autoInsertedBrackets--;
  493. };
  494. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  495. if (context) {
  496. context.maybeInsertedBrackets = 0;
  497. context.maybeInsertedRow = -1;
  498. }
  499. };
  500. oop.inherits(CstyleBehaviour, Behaviour);
  501. exports.CstyleBehaviour = CstyleBehaviour;
  502. });
  503. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  504. "use strict";
  505. var oop = require("../../lib/oop");
  506. var Range = require("../../range").Range;
  507. var BaseFoldMode = require("./fold_mode").FoldMode;
  508. var FoldMode = exports.FoldMode = function(commentRegex) {
  509. if (commentRegex) {
  510. this.foldingStartMarker = new RegExp(
  511. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  512. );
  513. this.foldingStopMarker = new RegExp(
  514. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  515. );
  516. }
  517. };
  518. oop.inherits(FoldMode, BaseFoldMode);
  519. (function() {
  520. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  521. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  522. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  523. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  524. this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
  525. this._getFoldWidgetBase = this.getFoldWidget;
  526. this.getFoldWidget = function(session, foldStyle, row) {
  527. var line = session.getLine(row);
  528. if (this.singleLineBlockCommentRe.test(line)) {
  529. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  530. return "";
  531. }
  532. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  533. if (!fw && this.startRegionRe.test(line))
  534. return "start"; // lineCommentRegionStart
  535. return fw;
  536. };
  537. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  538. var line = session.getLine(row);
  539. if (this.startRegionRe.test(line))
  540. return this.getCommentRegionBlock(session, line, row);
  541. var match = line.match(this.foldingStartMarker);
  542. if (match) {
  543. var i = match.index;
  544. if (match[1])
  545. return this.openingBracketBlock(session, match[1], row, i);
  546. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  547. if (range && !range.isMultiLine()) {
  548. if (forceMultiline) {
  549. range = this.getSectionRange(session, row);
  550. } else if (foldStyle != "all")
  551. range = null;
  552. }
  553. return range;
  554. }
  555. if (foldStyle === "markbegin")
  556. return;
  557. var match = line.match(this.foldingStopMarker);
  558. if (match) {
  559. var i = match.index + match[0].length;
  560. if (match[1])
  561. return this.closingBracketBlock(session, match[1], row, i);
  562. return session.getCommentFoldRange(row, i, -1);
  563. }
  564. };
  565. this.getSectionRange = function(session, row) {
  566. var line = session.getLine(row);
  567. var startIndent = line.search(/\S/);
  568. var startRow = row;
  569. var startColumn = line.length;
  570. row = row + 1;
  571. var endRow = row;
  572. var maxRow = session.getLength();
  573. while (++row < maxRow) {
  574. line = session.getLine(row);
  575. var indent = line.search(/\S/);
  576. if (indent === -1)
  577. continue;
  578. if (startIndent > indent)
  579. break;
  580. var subRange = this.getFoldWidgetRange(session, "all", row);
  581. if (subRange) {
  582. if (subRange.start.row <= startRow) {
  583. break;
  584. } else if (subRange.isMultiLine()) {
  585. row = subRange.end.row;
  586. } else if (startIndent == indent) {
  587. break;
  588. }
  589. }
  590. endRow = row;
  591. }
  592. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  593. };
  594. this.getCommentRegionBlock = function(session, line, row) {
  595. var startColumn = line.search(/\s*$/);
  596. var maxRow = session.getLength();
  597. var startRow = row;
  598. var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
  599. var depth = 1;
  600. while (++row < maxRow) {
  601. line = session.getLine(row);
  602. var m = re.exec(line);
  603. if (!m) continue;
  604. if (m[1]) depth--;
  605. else depth++;
  606. if (!depth) break;
  607. }
  608. var endRow = row;
  609. if (endRow > startRow) {
  610. return new Range(startRow, startColumn, endRow, line.length);
  611. }
  612. };
  613. }).call(FoldMode.prototype);
  614. });
  615. 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) {
  616. "use strict";
  617. var oop = require("../lib/oop");
  618. var TextMode = require("./text").Mode;
  619. var JsxHighlightRules = require("./jsx_highlight_rules").JsxHighlightRules;
  620. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  621. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  622. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  623. function Mode() {
  624. this.HighlightRules = JsxHighlightRules;
  625. this.$outdent = new MatchingBraceOutdent();
  626. this.$behaviour = new CstyleBehaviour();
  627. this.foldingRules = new CStyleFoldMode();
  628. }
  629. oop.inherits(Mode, TextMode);
  630. (function() {
  631. this.lineCommentStart = "//";
  632. this.blockComment = {start: "/*", end: "*/"};
  633. this.getNextLineIndent = function(state, line, tab) {
  634. var indent = this.$getIndent(line);
  635. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  636. var tokens = tokenizedLine.tokens;
  637. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  638. return indent;
  639. }
  640. if (state == "start") {
  641. var match = line.match(/^.*[\{\(\[]\s*$/);
  642. if (match) {
  643. indent += tab;
  644. }
  645. }
  646. return indent;
  647. };
  648. this.checkOutdent = function(state, line, input) {
  649. return this.$outdent.checkOutdent(line, input);
  650. };
  651. this.autoOutdent = function(state, doc, row) {
  652. this.$outdent.autoOutdent(doc, row);
  653. };
  654. this.$id = "ace/mode/jsx";
  655. }).call(Mode.prototype);
  656. exports.Mode = Mode;
  657. });