Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mode-scad.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. }
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. ace.define("ace/mode/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. ace.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. 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) {
  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 CstyleBehaviour = function() {
  202. this.add("braces", "insertion", function(state, action, editor, session, text) {
  203. var cursor = editor.getCursorPosition();
  204. var line = session.doc.getLine(cursor.row);
  205. if (text == '{') {
  206. initContext(editor);
  207. var selection = editor.getSelectionRange();
  208. var selected = session.doc.getTextRange(selection);
  209. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  210. return {
  211. text: '{' + selected + '}',
  212. selection: false
  213. };
  214. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  215. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  216. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  217. return {
  218. text: '{}',
  219. selection: [1, 1]
  220. };
  221. } else {
  222. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  223. return {
  224. text: '{',
  225. selection: [1, 1]
  226. };
  227. }
  228. }
  229. } else if (text == '}') {
  230. initContext(editor);
  231. var rightChar = line.substring(cursor.column, cursor.column + 1);
  232. if (rightChar == '}') {
  233. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  234. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  235. CstyleBehaviour.popAutoInsertedClosing();
  236. return {
  237. text: '',
  238. selection: [1, 1]
  239. };
  240. }
  241. }
  242. } else if (text == "\n" || text == "\r\n") {
  243. initContext(editor);
  244. var closing = "";
  245. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  246. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  247. CstyleBehaviour.clearMaybeInsertedClosing();
  248. }
  249. var rightChar = line.substring(cursor.column, cursor.column + 1);
  250. if (rightChar === '}') {
  251. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  252. if (!openBracePos)
  253. return null;
  254. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  255. } else if (closing) {
  256. var next_indent = this.$getIndent(line);
  257. } else {
  258. CstyleBehaviour.clearMaybeInsertedClosing();
  259. return;
  260. }
  261. var indent = next_indent + session.getTabString();
  262. return {
  263. text: '\n' + indent + '\n' + next_indent + closing,
  264. selection: [1, indent.length, 1, indent.length]
  265. };
  266. } else {
  267. CstyleBehaviour.clearMaybeInsertedClosing();
  268. }
  269. });
  270. this.add("braces", "deletion", function(state, action, editor, session, range) {
  271. var selected = session.doc.getTextRange(range);
  272. if (!range.isMultiLine() && selected == '{') {
  273. initContext(editor);
  274. var line = session.doc.getLine(range.start.row);
  275. var rightChar = line.substring(range.end.column, range.end.column + 1);
  276. if (rightChar == '}') {
  277. range.end.column++;
  278. return range;
  279. } else {
  280. context.maybeInsertedBrackets--;
  281. }
  282. }
  283. });
  284. this.add("parens", "insertion", function(state, action, editor, session, text) {
  285. if (text == '(') {
  286. initContext(editor);
  287. var selection = editor.getSelectionRange();
  288. var selected = session.doc.getTextRange(selection);
  289. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  290. return {
  291. text: '(' + selected + ')',
  292. selection: false
  293. };
  294. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  295. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  296. return {
  297. text: '()',
  298. selection: [1, 1]
  299. };
  300. }
  301. } else if (text == ')') {
  302. initContext(editor);
  303. var cursor = editor.getCursorPosition();
  304. var line = session.doc.getLine(cursor.row);
  305. var rightChar = line.substring(cursor.column, cursor.column + 1);
  306. if (rightChar == ')') {
  307. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  308. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  309. CstyleBehaviour.popAutoInsertedClosing();
  310. return {
  311. text: '',
  312. selection: [1, 1]
  313. };
  314. }
  315. }
  316. }
  317. });
  318. this.add("parens", "deletion", function(state, action, editor, session, range) {
  319. var selected = session.doc.getTextRange(range);
  320. if (!range.isMultiLine() && selected == '(') {
  321. initContext(editor);
  322. var line = session.doc.getLine(range.start.row);
  323. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  324. if (rightChar == ')') {
  325. range.end.column++;
  326. return range;
  327. }
  328. }
  329. });
  330. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  331. if (text == '[') {
  332. initContext(editor);
  333. var selection = editor.getSelectionRange();
  334. var selected = session.doc.getTextRange(selection);
  335. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  336. return {
  337. text: '[' + selected + ']',
  338. selection: false
  339. };
  340. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  341. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  342. return {
  343. text: '[]',
  344. selection: [1, 1]
  345. };
  346. }
  347. } else if (text == ']') {
  348. initContext(editor);
  349. var cursor = editor.getCursorPosition();
  350. var line = session.doc.getLine(cursor.row);
  351. var rightChar = line.substring(cursor.column, cursor.column + 1);
  352. if (rightChar == ']') {
  353. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  354. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  355. CstyleBehaviour.popAutoInsertedClosing();
  356. return {
  357. text: '',
  358. selection: [1, 1]
  359. };
  360. }
  361. }
  362. }
  363. });
  364. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  365. var selected = session.doc.getTextRange(range);
  366. if (!range.isMultiLine() && selected == '[') {
  367. initContext(editor);
  368. var line = session.doc.getLine(range.start.row);
  369. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  370. if (rightChar == ']') {
  371. range.end.column++;
  372. return range;
  373. }
  374. }
  375. });
  376. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  377. if (text == '"' || text == "'") {
  378. initContext(editor);
  379. var quote = text;
  380. var selection = editor.getSelectionRange();
  381. var selected = session.doc.getTextRange(selection);
  382. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  383. return {
  384. text: quote + selected + quote,
  385. selection: false
  386. };
  387. } else {
  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/.test(token.type);
  397. var stringAfter = !rightToken || /string/.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. ace.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. ace.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. });