mode-snippets.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../../lib/oop");
  4. var BaseFoldMode = require("./fold_mode").FoldMode;
  5. var Range = require("../../range").Range;
  6. var FoldMode = exports.FoldMode = function() {};
  7. oop.inherits(FoldMode, BaseFoldMode);
  8. (function() {
  9. this.getFoldWidgetRange = function(session, foldStyle, row) {
  10. var range = this.indentationBlock(session, row);
  11. if (range)
  12. return range;
  13. var re = /\S/;
  14. var line = session.getLine(row);
  15. var startLevel = line.search(re);
  16. if (startLevel == -1 || line[startLevel] != "#")
  17. return;
  18. var startColumn = line.length;
  19. var maxRow = session.getLength();
  20. var startRow = row;
  21. var endRow = row;
  22. while (++row < maxRow) {
  23. line = session.getLine(row);
  24. var level = line.search(re);
  25. if (level == -1)
  26. continue;
  27. if (line[level] != "#")
  28. break;
  29. endRow = row;
  30. }
  31. if (endRow > startRow) {
  32. var endColumn = session.getLine(endRow).length;
  33. return new Range(startRow, startColumn, endRow, endColumn);
  34. }
  35. };
  36. this.getFoldWidget = function(session, foldStyle, row) {
  37. var line = session.getLine(row);
  38. var indent = line.search(/\S/);
  39. var next = session.getLine(row + 1);
  40. var prev = session.getLine(row - 1);
  41. var prevIndent = prev.search(/\S/);
  42. var nextIndent = next.search(/\S/);
  43. if (indent == -1) {
  44. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  45. return "";
  46. }
  47. if (prevIndent == -1) {
  48. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  49. session.foldWidgets[row - 1] = "";
  50. session.foldWidgets[row + 1] = "";
  51. return "start";
  52. }
  53. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  54. if (session.getLine(row - 2).search(/\S/) == -1) {
  55. session.foldWidgets[row - 1] = "start";
  56. session.foldWidgets[row + 1] = "";
  57. return "";
  58. }
  59. }
  60. if (prevIndent!= -1 && prevIndent < indent)
  61. session.foldWidgets[row - 1] = "start";
  62. else
  63. session.foldWidgets[row - 1] = "";
  64. if (indent < nextIndent)
  65. return "start";
  66. else
  67. return "";
  68. };
  69. }).call(FoldMode.prototype);
  70. });
  71. ace.define("ace/mode/snippets",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/text_highlight_rules","ace/mode/folding/coffee"], function(require, exports, module) {
  72. "use strict";
  73. var oop = require("../lib/oop");
  74. var TextMode = require("./text").Mode;
  75. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  76. var SnippetHighlightRules = function() {
  77. var builtins = "SELECTION|CURRENT_WORD|SELECTED_TEXT|CURRENT_LINE|LINE_INDEX|" +
  78. "LINE_NUMBER|SOFT_TABS|TAB_SIZE|FILENAME|FILEPATH|FULLNAME";
  79. this.$rules = {
  80. "start" : [
  81. {token:"constant.language.escape", regex: /\\[\$}`\\]/},
  82. {token:"keyword", regex: "\\$(?:TM_)?(?:" + builtins + ")\\b"},
  83. {token:"variable", regex: "\\$\\w+"},
  84. {onMatch: function(value, state, stack) {
  85. if (stack[1])
  86. stack[1]++;
  87. else
  88. stack.unshift(state, 1);
  89. return this.tokenName;
  90. }, tokenName: "markup.list", regex: "\\${", next: "varDecl"},
  91. {onMatch: function(value, state, stack) {
  92. if (!stack[1])
  93. return "text";
  94. stack[1]--;
  95. if (!stack[1])
  96. stack.splice(0,2);
  97. return this.tokenName;
  98. }, tokenName: "markup.list", regex: "}"},
  99. {token: "doc.comment", regex:/^\${2}-{5,}$/}
  100. ],
  101. "varDecl" : [
  102. {regex: /\d+\b/, token: "constant.numeric"},
  103. {token:"keyword", regex: "(?:TM_)?(?:" + builtins + ")\\b"},
  104. {token:"variable", regex: "\\w+"},
  105. {regex: /:/, token: "punctuation.operator", next: "start"},
  106. {regex: /\//, token: "string.regex", next: "regexp"},
  107. {regex: "", next: "start"}
  108. ],
  109. "regexp" : [
  110. {regex: /\\./, token: "escape"},
  111. {regex: /\[/, token: "regex.start", next: "charClass"},
  112. {regex: "/", token: "string.regex", next: "format"},
  113. {"token": "string.regex", regex:"."}
  114. ],
  115. charClass : [
  116. {regex: "\\.", token: "escape"},
  117. {regex: "\\]", token: "regex.end", next: "regexp"},
  118. {"token": "string.regex", regex:"."}
  119. ],
  120. "format" : [
  121. {regex: /\\[ulULE]/, token: "keyword"},
  122. {regex: /\$\d+/, token: "variable"},
  123. {regex: "/[gim]*:?", token: "string.regex", next: "start"},
  124. {"token": "string", regex:"."}
  125. ]
  126. };
  127. };
  128. oop.inherits(SnippetHighlightRules, TextHighlightRules);
  129. exports.SnippetHighlightRules = SnippetHighlightRules;
  130. var SnippetGroupHighlightRules = function() {
  131. this.$rules = {
  132. "start" : [
  133. {token: "text", regex: "^\\t", next: "sn-start"},
  134. {token:"invalid", regex: /^ \s*/},
  135. {token:"comment", regex: /^#.*/},
  136. {token:"constant.language.escape", regex: "^regex ", next: "regex"},
  137. {token:"constant.language.escape", regex: "^(trigger|endTrigger|name|snippet|guard|endGuard|tabTrigger|key)\\b"}
  138. ],
  139. "regex" : [
  140. {token:"text", regex: "\\."},
  141. {token:"keyword", regex: "/"},
  142. {token:"empty", regex: "$", next: "start"}
  143. ]
  144. };
  145. this.embedRules(SnippetHighlightRules, "sn-", [
  146. {token: "text", regex: "^\\t", next: "sn-start"},
  147. {onMatch: function(value, state, stack) {
  148. stack.splice(stack.length);
  149. return this.tokenName;
  150. }, tokenName: "text", regex: "^(?!\t)", next: "start"}
  151. ])
  152. };
  153. oop.inherits(SnippetGroupHighlightRules, TextHighlightRules);
  154. exports.SnippetGroupHighlightRules = SnippetGroupHighlightRules;
  155. var FoldMode = require("./folding/coffee").FoldMode;
  156. var Mode = function() {
  157. this.HighlightRules = SnippetGroupHighlightRules;
  158. this.foldingRules = new FoldMode();
  159. this.$behaviour = this.$defaultBehaviour;
  160. };
  161. oop.inherits(Mode, TextMode);
  162. (function() {
  163. this.$indentWithTabs = true;
  164. this.lineCommentStart = "#";
  165. this.$id = "ace/mode/snippets";
  166. }).call(Mode.prototype);
  167. exports.Mode = Mode;
  168. });