mode-tcl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../../lib/oop");
  4. var Range = ace_require("../../range").Range;
  5. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  6. var FoldMode = exports.FoldMode = function(commentRegex) {
  7. if (commentRegex) {
  8. this.foldingStartMarker = new RegExp(
  9. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  10. );
  11. this.foldingStopMarker = new RegExp(
  12. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  13. );
  14. }
  15. };
  16. oop.inherits(FoldMode, BaseFoldMode);
  17. (function() {
  18. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  19. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  20. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  21. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  22. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  23. this._getFoldWidgetBase = this.getFoldWidget;
  24. this.getFoldWidget = function(session, foldStyle, row) {
  25. var line = session.getLine(row);
  26. if (this.singleLineBlockCommentRe.test(line)) {
  27. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  28. return "";
  29. }
  30. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  31. if (!fw && this.startRegionRe.test(line))
  32. return "start"; // lineCommentRegionStart
  33. return fw;
  34. };
  35. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  36. var line = session.getLine(row);
  37. if (this.startRegionRe.test(line))
  38. return this.getCommentRegionBlock(session, line, row);
  39. var match = line.match(this.foldingStartMarker);
  40. if (match) {
  41. var i = match.index;
  42. if (match[1])
  43. return this.openingBracketBlock(session, match[1], row, i);
  44. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  45. if (range && !range.isMultiLine()) {
  46. if (forceMultiline) {
  47. range = this.getSectionRange(session, row);
  48. } else if (foldStyle != "all")
  49. range = null;
  50. }
  51. return range;
  52. }
  53. if (foldStyle === "markbegin")
  54. return;
  55. var match = line.match(this.foldingStopMarker);
  56. if (match) {
  57. var i = match.index + match[0].length;
  58. if (match[1])
  59. return this.closingBracketBlock(session, match[1], row, i);
  60. return session.getCommentFoldRange(row, i, -1);
  61. }
  62. };
  63. this.getSectionRange = function(session, row) {
  64. var line = session.getLine(row);
  65. var startIndent = line.search(/\S/);
  66. var startRow = row;
  67. var startColumn = line.length;
  68. row = row + 1;
  69. var endRow = row;
  70. var maxRow = session.getLength();
  71. while (++row < maxRow) {
  72. line = session.getLine(row);
  73. var indent = line.search(/\S/);
  74. if (indent === -1)
  75. continue;
  76. if (startIndent > indent)
  77. break;
  78. var subRange = this.getFoldWidgetRange(session, "all", row);
  79. if (subRange) {
  80. if (subRange.start.row <= startRow) {
  81. break;
  82. } else if (subRange.isMultiLine()) {
  83. row = subRange.end.row;
  84. } else if (startIndent == indent) {
  85. break;
  86. }
  87. }
  88. endRow = row;
  89. }
  90. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  91. };
  92. this.getCommentRegionBlock = function(session, line, row) {
  93. var startColumn = line.search(/\s*$/);
  94. var maxRow = session.getLength();
  95. var startRow = row;
  96. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  97. var depth = 1;
  98. while (++row < maxRow) {
  99. line = session.getLine(row);
  100. var m = re.exec(line);
  101. if (!m) continue;
  102. if (m[1]) depth--;
  103. else depth++;
  104. if (!depth) break;
  105. }
  106. var endRow = row;
  107. if (endRow > startRow) {
  108. return new Range(startRow, startColumn, endRow, line.length);
  109. }
  110. };
  111. }).call(FoldMode.prototype);
  112. });
  113. define("ace/mode/tcl_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  114. "use strict";
  115. var oop = ace_require("../lib/oop");
  116. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  117. var TclHighlightRules = function() {
  118. this.$rules = {
  119. "start" : [
  120. {
  121. token : "comment",
  122. regex : "#.*\\\\$",
  123. next : "commentfollow"
  124. }, {
  125. token : "comment",
  126. regex : "#.*$"
  127. }, {
  128. token : "support.function",
  129. regex : '[\\\\]$',
  130. next : "splitlineStart"
  131. }, {
  132. token : "text",
  133. regex : /\\(?:["{}\[\]$\\])/
  134. }, {
  135. token : "text", // last value before command
  136. regex : '^|[^{][;][^}]|[/\r/]',
  137. next : "commandItem"
  138. }, {
  139. token : "string", // single line
  140. regex : '[ ]*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  141. }, {
  142. token : "string", // multi line """ string start
  143. regex : '[ ]*["]',
  144. next : "qqstring"
  145. }, {
  146. token : "variable.instance",
  147. regex : "[$]",
  148. next : "variable"
  149. }, {
  150. token : "support.function",
  151. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|{\\*}|;|::"
  152. }, {
  153. token : "identifier",
  154. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  155. }, {
  156. token : "paren.lparen",
  157. regex : "[[{]",
  158. next : "commandItem"
  159. }, {
  160. token : "paren.lparen",
  161. regex : "[(]"
  162. }, {
  163. token : "paren.rparen",
  164. regex : "[\\])}]"
  165. }, {
  166. token : "text",
  167. regex : "\\s+"
  168. }
  169. ],
  170. "commandItem" : [
  171. {
  172. token : "comment",
  173. regex : "#.*\\\\$",
  174. next : "commentfollow"
  175. }, {
  176. token : "comment",
  177. regex : "#.*$",
  178. next : "start"
  179. }, {
  180. token : "string", // single line
  181. regex : '[ ]*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  182. }, {
  183. token : "variable.instance",
  184. regex : "[$]",
  185. next : "variable"
  186. }, {
  187. token : "support.function",
  188. regex : "(?:[:][:])[a-zA-Z0-9_/]+(?:[:][:])",
  189. next : "commandItem"
  190. }, {
  191. token : "support.function",
  192. regex : "[a-zA-Z0-9_/]+(?:[:][:])",
  193. next : "commandItem"
  194. }, {
  195. token : "support.function",
  196. regex : "(?:[:][:])",
  197. next : "commandItem"
  198. }, {
  199. token : "paren.rparen",
  200. regex : "[\\])}]"
  201. }, {
  202. token : "paren.lparen",
  203. regex : "[[({]"
  204. }, {
  205. token : "support.function",
  206. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|{\\*}|;|::"
  207. }, {
  208. token : "keyword",
  209. regex : "[a-zA-Z0-9_/]+",
  210. next : "start"
  211. } ],
  212. "commentfollow" : [
  213. {
  214. token : "comment",
  215. regex : ".*\\\\$",
  216. next : "commentfollow"
  217. }, {
  218. token : "comment",
  219. regex : '.+',
  220. next : "start"
  221. } ],
  222. "splitlineStart" : [
  223. {
  224. token : "text",
  225. regex : "^.",
  226. next : "start"
  227. }],
  228. "variable" : [
  229. {
  230. token : "variable.instance", // variable tcl
  231. regex : "[a-zA-Z_\\d]+(?:[(][a-zA-Z_\\d]+[)])?",
  232. next : "start"
  233. }, {
  234. token : "variable.instance", // variable tcl with braces
  235. regex : "{?[a-zA-Z_\\d]+}?",
  236. next : "start"
  237. }],
  238. "qqstring" : [ {
  239. token : "string", // multi line """ string end
  240. regex : '(?:[^\\\\]|\\\\.)*?["]',
  241. next : "start"
  242. }, {
  243. token : "string",
  244. regex : '.+'
  245. } ]
  246. };
  247. };
  248. oop.inherits(TclHighlightRules, TextHighlightRules);
  249. exports.TclHighlightRules = TclHighlightRules;
  250. });
  251. define("ace/mode/matching_brace_outdent",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  252. "use strict";
  253. var Range = ace_require("../range").Range;
  254. var MatchingBraceOutdent = function() {};
  255. (function() {
  256. this.checkOutdent = function(line, input) {
  257. if (! /^\s+$/.test(line))
  258. return false;
  259. return /^\s*\}/.test(input);
  260. };
  261. this.autoOutdent = function(doc, row) {
  262. var line = doc.getLine(row);
  263. var match = line.match(/^(\s*\})/);
  264. if (!match) return 0;
  265. var column = match[1].length;
  266. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  267. if (!openBracePos || openBracePos.row == row) return 0;
  268. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  269. doc.replace(new Range(row, 0, row, column-1), indent);
  270. };
  271. this.$getIndent = function(line) {
  272. return line.match(/^\s*/)[0];
  273. };
  274. }).call(MatchingBraceOutdent.prototype);
  275. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  276. });
  277. define("ace/mode/tcl",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/folding/cstyle","ace/mode/tcl_highlight_rules","ace/mode/matching_brace_outdent","ace/range"], function(ace_require, exports, module) {
  278. "use strict";
  279. var oop = ace_require("../lib/oop");
  280. var TextMode = ace_require("./text").Mode;
  281. var CStyleFoldMode = ace_require("./folding/cstyle").FoldMode;
  282. var TclHighlightRules = ace_require("./tcl_highlight_rules").TclHighlightRules;
  283. var MatchingBraceOutdent = ace_require("./matching_brace_outdent").MatchingBraceOutdent;
  284. var Range = ace_require("../range").Range;
  285. var Mode = function() {
  286. this.HighlightRules = TclHighlightRules;
  287. this.$outdent = new MatchingBraceOutdent();
  288. this.foldingRules = new CStyleFoldMode();
  289. this.$behaviour = this.$defaultBehaviour;
  290. };
  291. oop.inherits(Mode, TextMode);
  292. (function() {
  293. this.lineCommentStart = "#";
  294. this.getNextLineIndent = function(state, line, tab) {
  295. var indent = this.$getIndent(line);
  296. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  297. var tokens = tokenizedLine.tokens;
  298. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  299. return indent;
  300. }
  301. if (state == "start") {
  302. var match = line.match(/^.*[\{\(\[]\s*$/);
  303. if (match) {
  304. indent += tab;
  305. }
  306. }
  307. return indent;
  308. };
  309. this.checkOutdent = function(state, line, input) {
  310. return this.$outdent.checkOutdent(line, input);
  311. };
  312. this.autoOutdent = function(state, doc, row) {
  313. this.$outdent.autoOutdent(doc, row);
  314. };
  315. this.$id = "ace/mode/tcl";
  316. this.snippetFileId = "ace/snippets/tcl";
  317. }).call(Mode.prototype);
  318. exports.Mode = Mode;
  319. }); (function() {
  320. window.ace_require(["ace/mode/tcl"], function(m) {
  321. if (typeof module == "object" && typeof exports == "object" && module) {
  322. module.exports = m;
  323. }
  324. });
  325. })();