Bez popisu
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.

mode-haxe.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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/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. ace.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. 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) {
  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 CstyleBehaviour = function() {
  182. this.add("braces", "insertion", function(state, action, editor, session, text) {
  183. var cursor = editor.getCursorPosition();
  184. var line = session.doc.getLine(cursor.row);
  185. if (text == '{') {
  186. initContext(editor);
  187. var selection = editor.getSelectionRange();
  188. var selected = session.doc.getTextRange(selection);
  189. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  190. return {
  191. text: '{' + selected + '}',
  192. selection: false
  193. };
  194. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  195. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  196. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  197. return {
  198. text: '{}',
  199. selection: [1, 1]
  200. };
  201. } else {
  202. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  203. return {
  204. text: '{',
  205. selection: [1, 1]
  206. };
  207. }
  208. }
  209. } else if (text == '}') {
  210. initContext(editor);
  211. var rightChar = line.substring(cursor.column, cursor.column + 1);
  212. if (rightChar == '}') {
  213. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  214. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  215. CstyleBehaviour.popAutoInsertedClosing();
  216. return {
  217. text: '',
  218. selection: [1, 1]
  219. };
  220. }
  221. }
  222. } else if (text == "\n" || text == "\r\n") {
  223. initContext(editor);
  224. var closing = "";
  225. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  226. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  227. CstyleBehaviour.clearMaybeInsertedClosing();
  228. }
  229. var rightChar = line.substring(cursor.column, cursor.column + 1);
  230. if (rightChar === '}') {
  231. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  232. if (!openBracePos)
  233. return null;
  234. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  235. } else if (closing) {
  236. var next_indent = this.$getIndent(line);
  237. } else {
  238. CstyleBehaviour.clearMaybeInsertedClosing();
  239. return;
  240. }
  241. var indent = next_indent + session.getTabString();
  242. return {
  243. text: '\n' + indent + '\n' + next_indent + closing,
  244. selection: [1, indent.length, 1, indent.length]
  245. };
  246. } else {
  247. CstyleBehaviour.clearMaybeInsertedClosing();
  248. }
  249. });
  250. this.add("braces", "deletion", function(state, action, editor, session, range) {
  251. var selected = session.doc.getTextRange(range);
  252. if (!range.isMultiLine() && selected == '{') {
  253. initContext(editor);
  254. var line = session.doc.getLine(range.start.row);
  255. var rightChar = line.substring(range.end.column, range.end.column + 1);
  256. if (rightChar == '}') {
  257. range.end.column++;
  258. return range;
  259. } else {
  260. context.maybeInsertedBrackets--;
  261. }
  262. }
  263. });
  264. this.add("parens", "insertion", function(state, action, editor, session, text) {
  265. if (text == '(') {
  266. initContext(editor);
  267. var selection = editor.getSelectionRange();
  268. var selected = session.doc.getTextRange(selection);
  269. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  270. return {
  271. text: '(' + selected + ')',
  272. selection: false
  273. };
  274. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  275. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  276. return {
  277. text: '()',
  278. selection: [1, 1]
  279. };
  280. }
  281. } else if (text == ')') {
  282. initContext(editor);
  283. var cursor = editor.getCursorPosition();
  284. var line = session.doc.getLine(cursor.row);
  285. var rightChar = line.substring(cursor.column, cursor.column + 1);
  286. if (rightChar == ')') {
  287. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  288. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  289. CstyleBehaviour.popAutoInsertedClosing();
  290. return {
  291. text: '',
  292. selection: [1, 1]
  293. };
  294. }
  295. }
  296. }
  297. });
  298. this.add("parens", "deletion", function(state, action, editor, session, range) {
  299. var selected = session.doc.getTextRange(range);
  300. if (!range.isMultiLine() && selected == '(') {
  301. initContext(editor);
  302. var line = session.doc.getLine(range.start.row);
  303. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  304. if (rightChar == ')') {
  305. range.end.column++;
  306. return range;
  307. }
  308. }
  309. });
  310. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  311. if (text == '[') {
  312. initContext(editor);
  313. var selection = editor.getSelectionRange();
  314. var selected = session.doc.getTextRange(selection);
  315. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  316. return {
  317. text: '[' + selected + ']',
  318. selection: false
  319. };
  320. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  321. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  322. return {
  323. text: '[]',
  324. selection: [1, 1]
  325. };
  326. }
  327. } else if (text == ']') {
  328. initContext(editor);
  329. var cursor = editor.getCursorPosition();
  330. var line = session.doc.getLine(cursor.row);
  331. var rightChar = line.substring(cursor.column, cursor.column + 1);
  332. if (rightChar == ']') {
  333. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  334. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  335. CstyleBehaviour.popAutoInsertedClosing();
  336. return {
  337. text: '',
  338. selection: [1, 1]
  339. };
  340. }
  341. }
  342. }
  343. });
  344. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  345. var selected = session.doc.getTextRange(range);
  346. if (!range.isMultiLine() && selected == '[') {
  347. initContext(editor);
  348. var line = session.doc.getLine(range.start.row);
  349. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  350. if (rightChar == ']') {
  351. range.end.column++;
  352. return range;
  353. }
  354. }
  355. });
  356. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  357. if (text == '"' || text == "'") {
  358. initContext(editor);
  359. var quote = text;
  360. var selection = editor.getSelectionRange();
  361. var selected = session.doc.getTextRange(selection);
  362. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  363. return {
  364. text: quote + selected + quote,
  365. selection: false
  366. };
  367. } else {
  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/.test(token.type);
  377. var stringAfter = !rightToken || /string/.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. ace.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. ace.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. });