mode-scad.js 27 KB

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