mode-jack.js 25 KB

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