Ei kuvausta
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-jack.js 25KB

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 CstyleBehaviour = function() {
  163. this.add("braces", "insertion", function(state, action, editor, session, text) {
  164. var cursor = editor.getCursorPosition();
  165. var line = session.doc.getLine(cursor.row);
  166. if (text == '{') {
  167. initContext(editor);
  168. var selection = editor.getSelectionRange();
  169. var selected = session.doc.getTextRange(selection);
  170. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  171. return {
  172. text: '{' + selected + '}',
  173. selection: false
  174. };
  175. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  176. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  177. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  178. return {
  179. text: '{}',
  180. selection: [1, 1]
  181. };
  182. } else {
  183. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  184. return {
  185. text: '{',
  186. selection: [1, 1]
  187. };
  188. }
  189. }
  190. } else if (text == '}') {
  191. initContext(editor);
  192. var rightChar = line.substring(cursor.column, cursor.column + 1);
  193. if (rightChar == '}') {
  194. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  195. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  196. CstyleBehaviour.popAutoInsertedClosing();
  197. return {
  198. text: '',
  199. selection: [1, 1]
  200. };
  201. }
  202. }
  203. } else if (text == "\n" || text == "\r\n") {
  204. initContext(editor);
  205. var closing = "";
  206. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  207. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  208. CstyleBehaviour.clearMaybeInsertedClosing();
  209. }
  210. var rightChar = line.substring(cursor.column, cursor.column + 1);
  211. if (rightChar === '}') {
  212. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  213. if (!openBracePos)
  214. return null;
  215. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  216. } else if (closing) {
  217. var next_indent = this.$getIndent(line);
  218. } else {
  219. CstyleBehaviour.clearMaybeInsertedClosing();
  220. return;
  221. }
  222. var indent = next_indent + session.getTabString();
  223. return {
  224. text: '\n' + indent + '\n' + next_indent + closing,
  225. selection: [1, indent.length, 1, indent.length]
  226. };
  227. } else {
  228. CstyleBehaviour.clearMaybeInsertedClosing();
  229. }
  230. });
  231. this.add("braces", "deletion", function(state, action, editor, session, range) {
  232. var selected = session.doc.getTextRange(range);
  233. if (!range.isMultiLine() && selected == '{') {
  234. initContext(editor);
  235. var line = session.doc.getLine(range.start.row);
  236. var rightChar = line.substring(range.end.column, range.end.column + 1);
  237. if (rightChar == '}') {
  238. range.end.column++;
  239. return range;
  240. } else {
  241. context.maybeInsertedBrackets--;
  242. }
  243. }
  244. });
  245. this.add("parens", "insertion", function(state, action, editor, session, text) {
  246. if (text == '(') {
  247. initContext(editor);
  248. var selection = editor.getSelectionRange();
  249. var selected = session.doc.getTextRange(selection);
  250. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  251. return {
  252. text: '(' + selected + ')',
  253. selection: false
  254. };
  255. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  256. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  257. return {
  258. text: '()',
  259. selection: [1, 1]
  260. };
  261. }
  262. } else if (text == ')') {
  263. initContext(editor);
  264. var cursor = editor.getCursorPosition();
  265. var line = session.doc.getLine(cursor.row);
  266. var rightChar = line.substring(cursor.column, cursor.column + 1);
  267. if (rightChar == ')') {
  268. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  269. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  270. CstyleBehaviour.popAutoInsertedClosing();
  271. return {
  272. text: '',
  273. selection: [1, 1]
  274. };
  275. }
  276. }
  277. }
  278. });
  279. this.add("parens", "deletion", function(state, action, editor, session, range) {
  280. var selected = session.doc.getTextRange(range);
  281. if (!range.isMultiLine() && selected == '(') {
  282. initContext(editor);
  283. var line = session.doc.getLine(range.start.row);
  284. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  285. if (rightChar == ')') {
  286. range.end.column++;
  287. return range;
  288. }
  289. }
  290. });
  291. this.add("brackets", "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("brackets", "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("string_dquotes", "insertion", function(state, action, editor, session, text) {
  338. if (text == '"' || text == "'") {
  339. initContext(editor);
  340. var quote = text;
  341. var selection = editor.getSelectionRange();
  342. var selected = session.doc.getTextRange(selection);
  343. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  344. return {
  345. text: quote + selected + quote,
  346. selection: false
  347. };
  348. } else {
  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/.test(token.type);
  358. var stringAfter = !rightToken || /string/.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. });