mode-haxe-uncompressed.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. define('ace/mode/haxe', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/haxe_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextMode = require("./text").Mode;
  5. var Tokenizer = require("../tokenizer").Tokenizer;
  6. var HaxeHighlightRules = require("./haxe_highlight_rules").HaxeHighlightRules;
  7. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  8. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  9. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  10. var Mode = function() {
  11. this.$tokenizer = new Tokenizer(new HaxeHighlightRules().getRules());
  12. this.$outdent = new MatchingBraceOutdent();
  13. this.$behaviour = new CstyleBehaviour();
  14. this.foldingRules = new CStyleFoldMode();
  15. };
  16. oop.inherits(Mode, TextMode);
  17. (function() {
  18. this.getNextLineIndent = function(state, line, tab) {
  19. var indent = this.$getIndent(line);
  20. var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
  21. var tokens = tokenizedLine.tokens;
  22. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  23. return indent;
  24. }
  25. if (state == "start") {
  26. var match = line.match(/^.*[\{\(\[]\s*$/);
  27. if (match) {
  28. indent += tab;
  29. }
  30. }
  31. return indent;
  32. };
  33. this.checkOutdent = function(state, line, input) {
  34. return this.$outdent.checkOutdent(line, input);
  35. };
  36. this.autoOutdent = function(state, doc, row) {
  37. this.$outdent.autoOutdent(doc, row);
  38. };
  39. this.createWorker = function(session) {
  40. return null;
  41. };
  42. }).call(Mode.prototype);
  43. exports.Mode = Mode;
  44. });
  45. define('ace/mode/haxe_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  46. "use strict";
  47. var oop = require("../lib/oop");
  48. var lang = require("../lib/lang");
  49. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  50. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  51. var HaxeHighlightRules = function() {
  52. var keywords = lang.arrayToMap(
  53. ("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").split("|")
  54. );
  55. var buildinConstants = lang.arrayToMap(
  56. ("null|true|false").split("|")
  57. );
  58. // regexp must not have capturing parentheses. Use (?:) instead.
  59. // regexps are ordered -> the first match is used
  60. this.$rules = {
  61. "start" : [
  62. {
  63. token : "comment",
  64. regex : "\\/\\/.*$"
  65. },
  66. new DocCommentHighlightRules().getStartRule("doc-start"),
  67. {
  68. token : "comment", // multi line comment
  69. regex : "\\/\\*",
  70. merge : true,
  71. next : "comment"
  72. }, {
  73. token : "string.regexp",
  74. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  75. }, {
  76. token : "string", // single line
  77. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  78. }, {
  79. token : "string", // single line
  80. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  81. }, {
  82. token : "constant.numeric", // hex
  83. regex : "0[xX][0-9a-fA-F]+\\b"
  84. }, {
  85. token : "constant.numeric", // float
  86. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  87. }, {
  88. token : "constant.language.boolean",
  89. regex : "(?:true|false)\\b"
  90. }, {
  91. token : function(value) {
  92. if (value == "this")
  93. return "variable.language";
  94. else if (keywords.hasOwnProperty(value))
  95. return "keyword";
  96. else if (buildinConstants.hasOwnProperty(value))
  97. return "constant.language";
  98. else
  99. return "identifier";
  100. },
  101. // TODO: Unicode escape sequences
  102. // TODO: Unicode identifiers
  103. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  104. }, {
  105. token : "keyword.operator",
  106. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  107. }, {
  108. token : "punctuation.operator",
  109. regex : "\\?|\\:|\\,|\\;|\\."
  110. }, {
  111. token : "paren.lparen",
  112. regex : "[[({<]"
  113. }, {
  114. token : "paren.rparen",
  115. regex : "[\\])}>]"
  116. }, {
  117. token : "text",
  118. regex : "\\s+"
  119. }
  120. ],
  121. "comment" : [
  122. {
  123. token : "comment", // closing comment
  124. regex : ".*?\\*\\/",
  125. next : "start"
  126. }, {
  127. token : "comment", // comment spanning whole line
  128. merge : true,
  129. regex : ".+"
  130. }
  131. ]
  132. };
  133. this.embedRules(DocCommentHighlightRules, "doc-",
  134. [ new DocCommentHighlightRules().getEndRule("start") ]);
  135. };
  136. oop.inherits(HaxeHighlightRules, TextHighlightRules);
  137. exports.HaxeHighlightRules = HaxeHighlightRules;
  138. });
  139. /* ***** BEGIN LICENSE BLOCK *****
  140. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  141. *
  142. * The contents of this file are subject to the Mozilla Public License Version
  143. * 1.1 (the "License"); you may not use this file except in compliance with
  144. * the License. You may obtain a copy of the License at
  145. * http://www.mozilla.org/MPL/
  146. *
  147. * Software distributed under the License is distributed on an "AS IS" basis,
  148. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  149. * for the specific language governing rights and limitations under the
  150. * License.
  151. *
  152. * The Original Code is Ajax.org Code Editor (ACE).
  153. *
  154. * The Initial Developer of the Original Code is
  155. * Ajax.org B.V.
  156. * Portions created by the Initial Developer are Copyright (C) 2010
  157. * the Initial Developer. All Rights Reserved.
  158. *
  159. * Contributor(s):
  160. * Fabian Jakobs <fabian AT ajax DOT org>
  161. *
  162. * Alternatively, the contents of this file may be used under the terms of
  163. * either the GNU General Public License Version 2 or later (the "GPL"), or
  164. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  165. * in which case the provisions of the GPL or the LGPL are applicable instead
  166. * of those above. If you wish to allow use of your version of this file only
  167. * under the terms of either the GPL or the LGPL, and not to allow others to
  168. * use your version of this file under the terms of the MPL, indicate your
  169. * decision by deleting the provisions above and replace them with the notice
  170. * and other provisions required by the GPL or the LGPL. If you do not delete
  171. * the provisions above, a recipient may use your version of this file under
  172. * the terms of any one of the MPL, the GPL or the LGPL.
  173. *
  174. * ***** END LICENSE BLOCK ***** */
  175. define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  176. "use strict";
  177. var oop = require("../lib/oop");
  178. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  179. var DocCommentHighlightRules = function() {
  180. this.$rules = {
  181. "start" : [ {
  182. token : "comment.doc.tag",
  183. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  184. }, {
  185. token : "comment.doc",
  186. merge : true,
  187. regex : "\\s+"
  188. }, {
  189. token : "comment.doc",
  190. merge : true,
  191. regex : "TODO"
  192. }, {
  193. token : "comment.doc",
  194. merge : true,
  195. regex : "[^@\\*]+"
  196. }, {
  197. token : "comment.doc",
  198. merge : true,
  199. regex : "."
  200. }]
  201. };
  202. };
  203. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  204. (function() {
  205. this.getStartRule = function(start) {
  206. return {
  207. token : "comment.doc", // doc comment
  208. merge : true,
  209. regex : "\\/\\*(?=\\*)",
  210. next : start
  211. };
  212. };
  213. this.getEndRule = function (start) {
  214. return {
  215. token : "comment.doc", // closing comment
  216. merge : true,
  217. regex : "\\*\\/",
  218. next : start
  219. };
  220. };
  221. }).call(DocCommentHighlightRules.prototype);
  222. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  223. });
  224. /* ***** BEGIN LICENSE BLOCK *****
  225. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  226. *
  227. * The contents of this file are subject to the Mozilla Public License Version
  228. * 1.1 (the "License"); you may not use this file except in compliance with
  229. * the License. You may obtain a copy of the License at
  230. * http://www.mozilla.org/MPL/
  231. *
  232. * Software distributed under the License is distributed on an "AS IS" basis,
  233. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  234. * for the specific language governing rights and limitations under the
  235. * License.
  236. *
  237. * The Original Code is Ajax.org Code Editor (ACE).
  238. *
  239. * The Initial Developer of the Original Code is
  240. * Ajax.org B.V.
  241. * Portions created by the Initial Developer are Copyright (C) 2010
  242. * the Initial Developer. All Rights Reserved.
  243. *
  244. * Contributor(s):
  245. * Fabian Jakobs <fabian AT ajax DOT org>
  246. *
  247. * Alternatively, the contents of this file may be used under the terms of
  248. * either the GNU General Public License Version 2 or later (the "GPL"), or
  249. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  250. * in which case the provisions of the GPL or the LGPL are applicable instead
  251. * of those above. If you wish to allow use of your version of this file only
  252. * under the terms of either the GPL or the LGPL, and not to allow others to
  253. * use your version of this file under the terms of the MPL, indicate your
  254. * decision by deleting the provisions above and replace them with the notice
  255. * and other provisions required by the GPL or the LGPL. If you do not delete
  256. * the provisions above, a recipient may use your version of this file under
  257. * the terms of any one of the MPL, the GPL or the LGPL.
  258. *
  259. * ***** END LICENSE BLOCK ***** */
  260. define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  261. "use strict";
  262. var Range = require("../range").Range;
  263. var MatchingBraceOutdent = function() {};
  264. (function() {
  265. this.checkOutdent = function(line, input) {
  266. if (! /^\s+$/.test(line))
  267. return false;
  268. return /^\s*\}/.test(input);
  269. };
  270. this.autoOutdent = function(doc, row) {
  271. var line = doc.getLine(row);
  272. var match = line.match(/^(\s*\})/);
  273. if (!match) return 0;
  274. var column = match[1].length;
  275. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  276. if (!openBracePos || openBracePos.row == row) return 0;
  277. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  278. doc.replace(new Range(row, 0, row, column-1), indent);
  279. };
  280. this.$getIndent = function(line) {
  281. var match = line.match(/^(\s+)/);
  282. if (match) {
  283. return match[1];
  284. }
  285. return "";
  286. };
  287. }).call(MatchingBraceOutdent.prototype);
  288. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  289. });
  290. /* vim:ts=4:sts=4:sw=4:
  291. * ***** BEGIN LICENSE BLOCK *****
  292. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  293. *
  294. * The contents of this file are subject to the Mozilla Public License Version
  295. * 1.1 (the "License"); you may not use this file except in compliance with
  296. * the License. You may obtain a copy of the License at
  297. * http://www.mozilla.org/MPL/
  298. *
  299. * Software distributed under the License is distributed on an "AS IS" basis,
  300. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  301. * for the specific language governing rights and limitations under the
  302. * License.
  303. *
  304. * The Original Code is Ajax.org Code Editor (ACE).
  305. *
  306. * The Initial Developer of the Original Code is
  307. * Ajax.org B.V.
  308. * Portions created by the Initial Developer are Copyright (C) 2010
  309. * the Initial Developer. All Rights Reserved.
  310. *
  311. * Contributor(s):
  312. * Chris Spencer <chris.ag.spencer AT googlemail DOT com>
  313. *
  314. * Alternatively, the contents of this file may be used under the terms of
  315. * either the GNU General Public License Version 2 or later (the "GPL"), or
  316. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  317. * in which case the provisions of the GPL or the LGPL are applicable instead
  318. * of those above. If you wish to allow use of your version of this file only
  319. * under the terms of either the GPL or the LGPL, and not to allow others to
  320. * use your version of this file under the terms of the MPL, indicate your
  321. * decision by deleting the provisions above and replace them with the notice
  322. * and other provisions required by the GPL or the LGPL. If you do not delete
  323. * the provisions above, a recipient may use your version of this file under
  324. * the terms of any one of the MPL, the GPL or the LGPL.
  325. *
  326. * ***** END LICENSE BLOCK ***** */
  327. define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour'], function(require, exports, module) {
  328. "use strict";
  329. var oop = require("../../lib/oop");
  330. var Behaviour = require('../behaviour').Behaviour;
  331. var CstyleBehaviour = function () {
  332. this.add("braces", "insertion", function (state, action, editor, session, text) {
  333. if (text == '{') {
  334. var selection = editor.getSelectionRange();
  335. var selected = session.doc.getTextRange(selection);
  336. if (selected !== "") {
  337. return {
  338. text: '{' + selected + '}',
  339. selection: false
  340. };
  341. } else {
  342. return {
  343. text: '{}',
  344. selection: [1, 1]
  345. };
  346. }
  347. } else if (text == '}') {
  348. var cursor = editor.getCursorPosition();
  349. var line = session.doc.getLine(cursor.row);
  350. var rightChar = line.substring(cursor.column, cursor.column + 1);
  351. if (rightChar == '}') {
  352. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  353. if (matching !== null) {
  354. return {
  355. text: '',
  356. selection: [1, 1]
  357. };
  358. }
  359. }
  360. } else if (text == "\n") {
  361. var cursor = editor.getCursorPosition();
  362. var line = session.doc.getLine(cursor.row);
  363. var rightChar = line.substring(cursor.column, cursor.column + 1);
  364. if (rightChar == '}') {
  365. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column + 1});
  366. if (!openBracePos)
  367. return null;
  368. var indent = this.getNextLineIndent(state, line.substring(0, line.length - 1), session.getTabString());
  369. var next_indent = this.$getIndent(session.doc.getLine(openBracePos.row));
  370. return {
  371. text: '\n' + indent + '\n' + next_indent,
  372. selection: [1, indent.length, 1, indent.length]
  373. };
  374. }
  375. }
  376. });
  377. this.add("braces", "deletion", function (state, action, editor, session, range) {
  378. var selected = session.doc.getTextRange(range);
  379. if (!range.isMultiLine() && selected == '{') {
  380. var line = session.doc.getLine(range.start.row);
  381. var rightChar = line.substring(range.end.column, range.end.column + 1);
  382. if (rightChar == '}') {
  383. range.end.column++;
  384. return range;
  385. }
  386. }
  387. });
  388. this.add("parens", "insertion", function (state, action, editor, session, text) {
  389. if (text == '(') {
  390. var selection = editor.getSelectionRange();
  391. var selected = session.doc.getTextRange(selection);
  392. if (selected !== "") {
  393. return {
  394. text: '(' + selected + ')',
  395. selection: false
  396. };
  397. } else {
  398. return {
  399. text: '()',
  400. selection: [1, 1]
  401. };
  402. }
  403. } else if (text == ')') {
  404. var cursor = editor.getCursorPosition();
  405. var line = session.doc.getLine(cursor.row);
  406. var rightChar = line.substring(cursor.column, cursor.column + 1);
  407. if (rightChar == ')') {
  408. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  409. if (matching !== null) {
  410. return {
  411. text: '',
  412. selection: [1, 1]
  413. };
  414. }
  415. }
  416. }
  417. });
  418. this.add("parens", "deletion", function (state, action, editor, session, range) {
  419. var selected = session.doc.getTextRange(range);
  420. if (!range.isMultiLine() && selected == '(') {
  421. var line = session.doc.getLine(range.start.row);
  422. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  423. if (rightChar == ')') {
  424. range.end.column++;
  425. return range;
  426. }
  427. }
  428. });
  429. this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
  430. if (text == '"' || text == "'") {
  431. var quote = text;
  432. var selection = editor.getSelectionRange();
  433. var selected = session.doc.getTextRange(selection);
  434. if (selected !== "") {
  435. return {
  436. text: quote + selected + quote,
  437. selection: false
  438. };
  439. } else {
  440. var cursor = editor.getCursorPosition();
  441. var line = session.doc.getLine(cursor.row);
  442. var leftChar = line.substring(cursor.column-1, cursor.column);
  443. // We're escaped.
  444. if (leftChar == '\\') {
  445. return null;
  446. }
  447. // Find what token we're inside.
  448. var tokens = session.getTokens(selection.start.row, selection.start.row)[0].tokens;
  449. var col = 0, token;
  450. var quotepos = -1; // Track whether we're inside an open quote.
  451. for (var x = 0; x < tokens.length; x++) {
  452. token = tokens[x];
  453. if (token.type == "string") {
  454. quotepos = -1;
  455. } else if (quotepos < 0) {
  456. quotepos = token.value.indexOf(quote);
  457. }
  458. if ((token.value.length + col) > selection.start.column) {
  459. break;
  460. }
  461. col += tokens[x].value.length;
  462. }
  463. // Try and be smart about when we auto insert.
  464. if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
  465. return {
  466. text: quote + quote,
  467. selection: [1,1]
  468. };
  469. } else if (token && token.type === "string") {
  470. // Ignore input and move right one if we're typing over the closing quote.
  471. var rightChar = line.substring(cursor.column, cursor.column + 1);
  472. if (rightChar == quote) {
  473. return {
  474. text: '',
  475. selection: [1, 1]
  476. };
  477. }
  478. }
  479. }
  480. }
  481. });
  482. this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
  483. var selected = session.doc.getTextRange(range);
  484. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  485. var line = session.doc.getLine(range.start.row);
  486. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  487. if (rightChar == '"') {
  488. range.end.column++;
  489. return range;
  490. }
  491. }
  492. });
  493. };
  494. oop.inherits(CstyleBehaviour, Behaviour);
  495. exports.CstyleBehaviour = CstyleBehaviour;
  496. });/* ***** BEGIN LICENSE BLOCK *****
  497. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  498. *
  499. * The contents of this file are subject to the Mozilla Public License Version
  500. * 1.1 (the "License"); you may not use this file except in compliance with
  501. * the License. You may obtain a copy of the License at
  502. * http://www.mozilla.org/MPL/
  503. *
  504. * Software distributed under the License is distributed on an "AS IS" basis,
  505. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  506. * for the specific language governing rights and limitations under the
  507. * License.
  508. *
  509. * The Original Code is Ajax.org Code Editor (ACE).
  510. *
  511. * The Initial Developer of the Original Code is
  512. * Ajax.org B.V.
  513. * Portions created by the Initial Developer are Copyright (C) 2010
  514. * the Initial Developer. All Rights Reserved.
  515. *
  516. * Contributor(s):
  517. * Fabian Jakobs <fabian AT ajax DOT org>
  518. *
  519. * Alternatively, the contents of this file may be used under the terms of
  520. * either the GNU General Public License Version 2 or later (the "GPL"), or
  521. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  522. * in which case the provisions of the GPL or the LGPL are applicable instead
  523. * of those above. If you wish to allow use of your version of this file only
  524. * under the terms of either the GPL or the LGPL, and not to allow others to
  525. * use your version of this file under the terms of the MPL, indicate your
  526. * decision by deleting the provisions above and replace them with the notice
  527. * and other provisions required by the GPL or the LGPL. If you do not delete
  528. * the provisions above, a recipient may use your version of this file under
  529. * the terms of any one of the MPL, the GPL or the LGPL.
  530. *
  531. * ***** END LICENSE BLOCK ***** */
  532. define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  533. "use strict";
  534. var oop = require("../../lib/oop");
  535. var Range = require("../../range").Range;
  536. var BaseFoldMode = require("./fold_mode").FoldMode;
  537. var FoldMode = exports.FoldMode = function() {};
  538. oop.inherits(FoldMode, BaseFoldMode);
  539. (function() {
  540. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  541. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  542. this.getFoldWidgetRange = function(session, foldStyle, row) {
  543. var line = session.getLine(row);
  544. var match = line.match(this.foldingStartMarker);
  545. if (match) {
  546. var i = match.index;
  547. if (match[1])
  548. return this.openingBracketBlock(session, match[1], row, i);
  549. var range = session.getCommentFoldRange(row, i + match[0].length);
  550. range.end.column -= 2;
  551. return range;
  552. }
  553. if (foldStyle !== "markbeginend")
  554. return;
  555. var match = line.match(this.foldingStopMarker);
  556. if (match) {
  557. var i = match.index + match[0].length;
  558. if (match[2]) {
  559. var range = session.getCommentFoldRange(row, i);
  560. range.end.column -= 2;
  561. return range;
  562. }
  563. var end = {row: row, column: i};
  564. var start = session.$findOpeningBracket(match[1], end);
  565. if (!start)
  566. return;
  567. start.column++;
  568. end.column--;
  569. return Range.fromPoints(start, end);
  570. }
  571. };
  572. }).call(FoldMode.prototype);
  573. });/* ***** BEGIN LICENSE BLOCK *****
  574. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  575. *
  576. * The contents of this file are subject to the Mozilla Public License Version
  577. * 1.1 (the "License"); you may not use this file except in compliance with
  578. * the License. You may obtain a copy of the License at
  579. * http://www.mozilla.org/MPL/
  580. *
  581. * Software distributed under the License is distributed on an "AS IS" basis,
  582. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  583. * for the specific language governing rights and limitations under the
  584. * License.
  585. *
  586. * The Original Code is Ajax.org Code Editor (ACE).
  587. *
  588. * The Initial Developer of the Original Code is
  589. * Ajax.org B.V.
  590. * Portions created by the Initial Developer are Copyright (C) 2010
  591. * the Initial Developer. All Rights Reserved.
  592. *
  593. * Contributor(s):
  594. * Fabian Jakobs <fabian AT ajax DOT org>
  595. *
  596. * Alternatively, the contents of this file may be used under the terms of
  597. * either the GNU General Public License Version 2 or later (the "GPL"), or
  598. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  599. * in which case the provisions of the GPL or the LGPL are applicable instead
  600. * of those above. If you wish to allow use of your version of this file only
  601. * under the terms of either the GPL or the LGPL, and not to allow others to
  602. * use your version of this file under the terms of the MPL, indicate your
  603. * decision by deleting the provisions above and replace them with the notice
  604. * and other provisions required by the GPL or the LGPL. If you do not delete
  605. * the provisions above, a recipient may use your version of this file under
  606. * the terms of any one of the MPL, the GPL or the LGPL.
  607. *
  608. * ***** END LICENSE BLOCK ***** */
  609. define('ace/mode/folding/fold_mode', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  610. "use strict";
  611. var Range = require("../../range").Range;
  612. var FoldMode = exports.FoldMode = function() {};
  613. (function() {
  614. this.foldingStartMarker = null;
  615. this.foldingStopMarker = null;
  616. // must return "" if there's no fold, to enable caching
  617. this.getFoldWidget = function(session, foldStyle, row) {
  618. var line = session.getLine(row);
  619. if (this.foldingStartMarker.test(line))
  620. return "start";
  621. if (foldStyle == "markbeginend"
  622. && this.foldingStopMarker
  623. && this.foldingStopMarker.test(line))
  624. return "end";
  625. return "";
  626. };
  627. this.getFoldWidgetRange = function(session, foldStyle, row) {
  628. return null;
  629. };
  630. this.indentationBlock = function(session, row, column) {
  631. var re = /^\s*/;
  632. var startRow = row;
  633. var endRow = row;
  634. var line = session.getLine(row);
  635. var startColumn = column || line.length;
  636. var startLevel = line.match(re)[0].length;
  637. var maxRow = session.getLength()
  638. while (++row < maxRow) {
  639. line = session.getLine(row);
  640. var level = line.match(re)[0].length;
  641. if (level == line.length)
  642. continue;
  643. if (level <= startLevel)
  644. break;
  645. endRow = row;
  646. }
  647. if (endRow > startRow) {
  648. var endColumn = session.getLine(endRow).length;
  649. return new Range(startRow, startColumn, endRow, endColumn);
  650. }
  651. };
  652. this.openingBracketBlock = function(session, bracket, row, column) {
  653. var start = {row: row, column: column + 1};
  654. var end = session.$findClosingBracket(bracket, start);
  655. if (!end)
  656. return;
  657. var fw = session.foldWidgets[end.row];
  658. if (fw == null)
  659. fw = this.getFoldWidget(session, end.row);
  660. if (fw == "start") {
  661. end.row --;
  662. end.column = session.getLine(end.row).length;
  663. }
  664. return Range.fromPoints(start, end);
  665. };
  666. }).call(FoldMode.prototype);
  667. });