mode-scad.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. ace.define("ace/mode/doc_comment_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",[], 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. defaultToken : "comment"
  114. }
  115. ],
  116. "qqstring" : [
  117. {
  118. token : "string",
  119. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  120. next : "start"
  121. }, {
  122. token : "string",
  123. regex : '.+'
  124. }
  125. ],
  126. "qstring" : [
  127. {
  128. token : "string",
  129. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  130. next : "start"
  131. }, {
  132. token : "string",
  133. regex : '.+'
  134. }
  135. ]
  136. };
  137. this.embedRules(DocCommentHighlightRules, "doc-",
  138. [ DocCommentHighlightRules.getEndRule("start") ]);
  139. };
  140. oop.inherits(scadHighlightRules, TextHighlightRules);
  141. exports.scadHighlightRules = scadHighlightRules;
  142. });
  143. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  144. "use strict";
  145. var Range = require("../range").Range;
  146. var MatchingBraceOutdent = function() {};
  147. (function() {
  148. this.checkOutdent = function(line, input) {
  149. if (! /^\s+$/.test(line))
  150. return false;
  151. return /^\s*\}/.test(input);
  152. };
  153. this.autoOutdent = function(doc, row) {
  154. var line = doc.getLine(row);
  155. var match = line.match(/^(\s*\})/);
  156. if (!match) return 0;
  157. var column = match[1].length;
  158. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  159. if (!openBracePos || openBracePos.row == row) return 0;
  160. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  161. doc.replace(new Range(row, 0, row, column-1), indent);
  162. };
  163. this.$getIndent = function(line) {
  164. return line.match(/^\s*/)[0];
  165. };
  166. }).call(MatchingBraceOutdent.prototype);
  167. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  168. });
  169. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  170. "use strict";
  171. var oop = require("../../lib/oop");
  172. var Range = require("../../range").Range;
  173. var BaseFoldMode = require("./fold_mode").FoldMode;
  174. var FoldMode = exports.FoldMode = function(commentRegex) {
  175. if (commentRegex) {
  176. this.foldingStartMarker = new RegExp(
  177. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  178. );
  179. this.foldingStopMarker = new RegExp(
  180. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  181. );
  182. }
  183. };
  184. oop.inherits(FoldMode, BaseFoldMode);
  185. (function() {
  186. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  187. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  188. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  189. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  190. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  191. this._getFoldWidgetBase = this.getFoldWidget;
  192. this.getFoldWidget = function(session, foldStyle, row) {
  193. var line = session.getLine(row);
  194. if (this.singleLineBlockCommentRe.test(line)) {
  195. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  196. return "";
  197. }
  198. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  199. if (!fw && this.startRegionRe.test(line))
  200. return "start"; // lineCommentRegionStart
  201. return fw;
  202. };
  203. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  204. var line = session.getLine(row);
  205. if (this.startRegionRe.test(line))
  206. return this.getCommentRegionBlock(session, line, row);
  207. var match = line.match(this.foldingStartMarker);
  208. if (match) {
  209. var i = match.index;
  210. if (match[1])
  211. return this.openingBracketBlock(session, match[1], row, i);
  212. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  213. if (range && !range.isMultiLine()) {
  214. if (forceMultiline) {
  215. range = this.getSectionRange(session, row);
  216. } else if (foldStyle != "all")
  217. range = null;
  218. }
  219. return range;
  220. }
  221. if (foldStyle === "markbegin")
  222. return;
  223. var match = line.match(this.foldingStopMarker);
  224. if (match) {
  225. var i = match.index + match[0].length;
  226. if (match[1])
  227. return this.closingBracketBlock(session, match[1], row, i);
  228. return session.getCommentFoldRange(row, i, -1);
  229. }
  230. };
  231. this.getSectionRange = function(session, row) {
  232. var line = session.getLine(row);
  233. var startIndent = line.search(/\S/);
  234. var startRow = row;
  235. var startColumn = line.length;
  236. row = row + 1;
  237. var endRow = row;
  238. var maxRow = session.getLength();
  239. while (++row < maxRow) {
  240. line = session.getLine(row);
  241. var indent = line.search(/\S/);
  242. if (indent === -1)
  243. continue;
  244. if (startIndent > indent)
  245. break;
  246. var subRange = this.getFoldWidgetRange(session, "all", row);
  247. if (subRange) {
  248. if (subRange.start.row <= startRow) {
  249. break;
  250. } else if (subRange.isMultiLine()) {
  251. row = subRange.end.row;
  252. } else if (startIndent == indent) {
  253. break;
  254. }
  255. }
  256. endRow = row;
  257. }
  258. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  259. };
  260. this.getCommentRegionBlock = function(session, line, row) {
  261. var startColumn = line.search(/\s*$/);
  262. var maxRow = session.getLength();
  263. var startRow = row;
  264. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  265. var depth = 1;
  266. while (++row < maxRow) {
  267. line = session.getLine(row);
  268. var m = re.exec(line);
  269. if (!m) continue;
  270. if (m[1]) depth--;
  271. else depth++;
  272. if (!depth) break;
  273. }
  274. var endRow = row;
  275. if (endRow > startRow) {
  276. return new Range(startRow, startColumn, endRow, line.length);
  277. }
  278. };
  279. }).call(FoldMode.prototype);
  280. });
  281. ace.define("ace/mode/scad",[], function(require, exports, module) {
  282. "use strict";
  283. var oop = require("../lib/oop");
  284. var TextMode = require("./text").Mode;
  285. var scadHighlightRules = require("./scad_highlight_rules").scadHighlightRules;
  286. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  287. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  288. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  289. var Mode = function() {
  290. this.HighlightRules = scadHighlightRules;
  291. this.$outdent = new MatchingBraceOutdent();
  292. this.$behaviour = new CstyleBehaviour();
  293. this.foldingRules = new CStyleFoldMode();
  294. };
  295. oop.inherits(Mode, TextMode);
  296. (function() {
  297. this.lineCommentStart = "//";
  298. this.blockComment = {start: "/*", end: "*/"};
  299. this.getNextLineIndent = function(state, line, tab) {
  300. var indent = this.$getIndent(line);
  301. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  302. var tokens = tokenizedLine.tokens;
  303. var endState = tokenizedLine.state;
  304. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  305. return indent;
  306. }
  307. if (state == "start") {
  308. var match = line.match(/^.*[\{\(\[]\s*$/);
  309. if (match) {
  310. indent += tab;
  311. }
  312. } else if (state == "doc-start") {
  313. if (endState == "start") {
  314. return "";
  315. }
  316. var match = line.match(/^\s*(\/?)\*/);
  317. if (match) {
  318. if (match[1]) {
  319. indent += " ";
  320. }
  321. indent += "* ";
  322. }
  323. }
  324. return indent;
  325. };
  326. this.checkOutdent = function(state, line, input) {
  327. return this.$outdent.checkOutdent(line, input);
  328. };
  329. this.autoOutdent = function(state, doc, row) {
  330. this.$outdent.autoOutdent(doc, row);
  331. };
  332. this.$id = "ace/mode/scad";
  333. }).call(Mode.prototype);
  334. exports.Mode = Mode;
  335. });
  336. (function() {
  337. ace.require(["ace/mode/scad"], function(m) {
  338. if (typeof module == "object" && typeof exports == "object" && module) {
  339. module.exports = m;
  340. }
  341. });
  342. })();