mode-haxe.js 27 KB

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