mode-tcl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../../lib/oop");
  4. var Range = require("../../range").Range;
  5. var BaseFoldMode = 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. ace.define("ace/mode/tcl_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  114. "use strict";
  115. var oop = require("../lib/oop");
  116. var TextHighlightRules = 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 : "support.function",
  203. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|{\\*}|;|::"
  204. }, {
  205. token : "keyword",
  206. regex : "[a-zA-Z0-9_/]+",
  207. next : "start"
  208. } ],
  209. "commentfollow" : [
  210. {
  211. token : "comment",
  212. regex : ".*\\\\$",
  213. next : "commentfollow"
  214. }, {
  215. token : "comment",
  216. regex : '.+',
  217. next : "start"
  218. } ],
  219. "splitlineStart" : [
  220. {
  221. token : "text",
  222. regex : "^.",
  223. next : "start"
  224. }],
  225. "variable" : [
  226. {
  227. token : "variable.instance", // variable tcl
  228. regex : "[a-zA-Z_\\d]+(?:[(][a-zA-Z_\\d]+[)])?",
  229. next : "start"
  230. }, {
  231. token : "variable.instance", // variable tcl with braces
  232. regex : "{?[a-zA-Z_\\d]+}?",
  233. next : "start"
  234. }],
  235. "qqstring" : [ {
  236. token : "string", // multi line """ string end
  237. regex : '(?:[^\\\\]|\\\\.)*?["]',
  238. next : "start"
  239. }, {
  240. token : "string",
  241. regex : '.+'
  242. } ]
  243. };
  244. };
  245. oop.inherits(TclHighlightRules, TextHighlightRules);
  246. exports.TclHighlightRules = TclHighlightRules;
  247. });
  248. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  249. "use strict";
  250. var Range = require("../range").Range;
  251. var MatchingBraceOutdent = function() {};
  252. (function() {
  253. this.checkOutdent = function(line, input) {
  254. if (! /^\s+$/.test(line))
  255. return false;
  256. return /^\s*\}/.test(input);
  257. };
  258. this.autoOutdent = function(doc, row) {
  259. var line = doc.getLine(row);
  260. var match = line.match(/^(\s*\})/);
  261. if (!match) return 0;
  262. var column = match[1].length;
  263. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  264. if (!openBracePos || openBracePos.row == row) return 0;
  265. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  266. doc.replace(new Range(row, 0, row, column-1), indent);
  267. };
  268. this.$getIndent = function(line) {
  269. return line.match(/^\s*/)[0];
  270. };
  271. }).call(MatchingBraceOutdent.prototype);
  272. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  273. });
  274. ace.define("ace/mode/tcl",["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(require, exports, module) {
  275. "use strict";
  276. var oop = require("../lib/oop");
  277. var TextMode = require("./text").Mode;
  278. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  279. var TclHighlightRules = require("./tcl_highlight_rules").TclHighlightRules;
  280. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  281. var Range = require("../range").Range;
  282. var Mode = function() {
  283. this.HighlightRules = TclHighlightRules;
  284. this.$outdent = new MatchingBraceOutdent();
  285. this.foldingRules = new CStyleFoldMode();
  286. this.$behaviour = this.$defaultBehaviour;
  287. };
  288. oop.inherits(Mode, TextMode);
  289. (function() {
  290. this.lineCommentStart = "#";
  291. this.getNextLineIndent = function(state, line, tab) {
  292. var indent = this.$getIndent(line);
  293. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  294. var tokens = tokenizedLine.tokens;
  295. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  296. return indent;
  297. }
  298. if (state == "start") {
  299. var match = line.match(/^.*[\{\(\[]\s*$/);
  300. if (match) {
  301. indent += tab;
  302. }
  303. }
  304. return indent;
  305. };
  306. this.checkOutdent = function(state, line, input) {
  307. return this.$outdent.checkOutdent(line, input);
  308. };
  309. this.autoOutdent = function(state, doc, row) {
  310. this.$outdent.autoOutdent(doc, row);
  311. };
  312. this.$id = "ace/mode/tcl";
  313. }).call(Mode.prototype);
  314. exports.Mode = Mode;
  315. });