mode-tcl.js 10 KB

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