mode-sass.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. ace.define("ace/mode/scss_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var lang = require("../lib/lang");
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var ScssHighlightRules = function() {
  7. var properties = lang.arrayToMap( (function () {
  8. var browserPrefix = ("-webkit-|-moz-|-o-|-ms-|-svg-|-pie-|-khtml-").split("|");
  9. var prefixProperties = ("appearance|background-clip|background-inline-policy|background-origin|" +
  10. "background-size|binding|border-bottom-colors|border-left-colors|" +
  11. "border-right-colors|border-top-colors|border-end|border-end-color|" +
  12. "border-end-style|border-end-width|border-image|border-start|" +
  13. "border-start-color|border-start-style|border-start-width|box-align|" +
  14. "box-direction|box-flex|box-flexgroup|box-ordinal-group|box-orient|" +
  15. "box-pack|box-sizing|column-count|column-gap|column-width|column-rule|" +
  16. "column-rule-width|column-rule-style|column-rule-color|float-edge|" +
  17. "font-feature-settings|font-language-override|force-broken-image-icon|" +
  18. "image-region|margin-end|margin-start|opacity|outline|outline-color|" +
  19. "outline-offset|outline-radius|outline-radius-bottomleft|" +
  20. "outline-radius-bottomright|outline-radius-topleft|outline-radius-topright|" +
  21. "outline-style|outline-width|padding-end|padding-start|stack-sizing|" +
  22. "tab-size|text-blink|text-decoration-color|text-decoration-line|" +
  23. "text-decoration-style|transform|transform-origin|transition|" +
  24. "transition-delay|transition-duration|transition-property|" +
  25. "transition-timing-function|user-focus|user-input|user-modify|user-select|" +
  26. "window-shadow|border-radius").split("|");
  27. var properties = ("azimuth|background-attachment|background-color|background-image|" +
  28. "background-position|background-repeat|background|border-bottom-color|" +
  29. "border-bottom-style|border-bottom-width|border-bottom|border-collapse|" +
  30. "border-color|border-left-color|border-left-style|border-left-width|" +
  31. "border-left|border-right-color|border-right-style|border-right-width|" +
  32. "border-right|border-spacing|border-style|border-top-color|" +
  33. "border-top-style|border-top-width|border-top|border-width|border|bottom|" +
  34. "box-shadow|box-sizing|caption-side|clear|clip|color|content|counter-increment|" +
  35. "counter-reset|cue-after|cue-before|cue|cursor|direction|display|" +
  36. "elevation|empty-cells|float|font-family|font-size-adjust|font-size|" +
  37. "font-stretch|font-style|font-variant|font-weight|font|height|left|" +
  38. "letter-spacing|line-height|list-style-image|list-style-position|" +
  39. "list-style-type|list-style|margin-bottom|margin-left|margin-right|" +
  40. "margin-top|marker-offset|margin|marks|max-height|max-width|min-height|" +
  41. "min-width|opacity|orphans|outline-color|" +
  42. "outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|" +
  43. "padding-left|padding-right|padding-top|padding|page-break-after|" +
  44. "page-break-before|page-break-inside|page|pause-after|pause-before|" +
  45. "pause|pitch-range|pitch|play-during|position|quotes|richness|right|" +
  46. "size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|" +
  47. "stress|table-layout|text-align|text-decoration|text-indent|" +
  48. "text-shadow|text-transform|top|unicode-bidi|vertical-align|" +
  49. "visibility|voice-family|volume|white-space|widows|width|word-spacing|" +
  50. "z-index").split("|");
  51. var ret = [];
  52. for (var i=0, ln=browserPrefix.length; i<ln; i++) {
  53. Array.prototype.push.apply(
  54. ret,
  55. (( browserPrefix[i] + prefixProperties.join("|" + browserPrefix[i]) ).split("|"))
  56. );
  57. }
  58. Array.prototype.push.apply(ret, prefixProperties);
  59. Array.prototype.push.apply(ret, properties);
  60. return ret;
  61. })() );
  62. var functions = lang.arrayToMap(
  63. ("hsl|hsla|rgb|rgba|url|attr|counter|counters|abs|adjust_color|adjust_hue|" +
  64. "alpha|join|blue|ceil|change_color|comparable|complement|darken|desaturate|" +
  65. "floor|grayscale|green|hue|if|invert|join|length|lighten|lightness|mix|" +
  66. "nth|opacify|opacity|percentage|quote|red|round|saturate|saturation|" +
  67. "scale_color|transparentize|type_of|unit|unitless|unqoute").split("|")
  68. );
  69. var constants = lang.arrayToMap(
  70. ("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|" +
  71. "block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|" +
  72. "char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|" +
  73. "decimal-leading-zero|decimal|default|disabled|disc|" +
  74. "distribute-all-lines|distribute-letter|distribute-space|" +
  75. "distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|" +
  76. "hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|" +
  77. "ideograph-alpha|ideograph-numeric|ideograph-parenthesis|" +
  78. "ideograph-space|inactive|inherit|inline-block|inline|inset|inside|" +
  79. "inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|" +
  80. "keep-all|left|lighter|line-edge|line-through|line|list-item|loose|" +
  81. "lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|" +
  82. "medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|" +
  83. "nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|" +
  84. "overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|" +
  85. "ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|" +
  86. "solid|square|static|strict|super|sw-resize|table-footer-group|" +
  87. "table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|" +
  88. "transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|" +
  89. "vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|" +
  90. "zero").split("|")
  91. );
  92. var colors = lang.arrayToMap(
  93. ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" +
  94. "purple|red|silver|teal|white|yellow").split("|")
  95. );
  96. var keywords = lang.arrayToMap(
  97. ("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|def|end|declare").split("|")
  98. )
  99. var tags = lang.arrayToMap(
  100. ("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|" +
  101. "big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|" +
  102. "command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|" +
  103. "figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|" +
  104. "header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|" +
  105. "link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|" +
  106. "option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|" +
  107. "small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|" +
  108. "textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp").split("|")
  109. );
  110. var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
  111. this.$rules = {
  112. "start" : [
  113. {
  114. token : "comment",
  115. regex : "\\/\\/.*$"
  116. },
  117. {
  118. token : "comment", // multi line comment
  119. regex : "\\/\\*",
  120. next : "comment"
  121. }, {
  122. token : "string", // single line
  123. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  124. }, {
  125. token : "string", // multi line string start
  126. regex : '["].*\\\\$',
  127. next : "qqstring"
  128. }, {
  129. token : "string", // single line
  130. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  131. }, {
  132. token : "string", // multi line string start
  133. regex : "['].*\\\\$",
  134. next : "qstring"
  135. }, {
  136. token : "constant.numeric",
  137. regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
  138. }, {
  139. token : "constant.numeric", // hex6 color
  140. regex : "#[a-f0-9]{6}"
  141. }, {
  142. token : "constant.numeric", // hex3 color
  143. regex : "#[a-f0-9]{3}"
  144. }, {
  145. token : "constant.numeric",
  146. regex : numRe
  147. }, {
  148. token : ["support.function", "string", "support.function"],
  149. regex : "(url\\()(.*)(\\))"
  150. }, {
  151. token : function(value) {
  152. if (properties.hasOwnProperty(value.toLowerCase()))
  153. return "support.type";
  154. if (keywords.hasOwnProperty(value))
  155. return "keyword";
  156. else if (constants.hasOwnProperty(value))
  157. return "constant.language";
  158. else if (functions.hasOwnProperty(value))
  159. return "support.function";
  160. else if (colors.hasOwnProperty(value.toLowerCase()))
  161. return "support.constant.color";
  162. else if (tags.hasOwnProperty(value.toLowerCase()))
  163. return "variable.language";
  164. else
  165. return "text";
  166. },
  167. regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
  168. }, {
  169. token : "variable",
  170. regex : "[a-z_\\-$][a-z0-9_\\-$]*\\b"
  171. }, {
  172. token: "variable.language",
  173. regex: "#[a-z0-9-_]+"
  174. }, {
  175. token: "variable.language",
  176. regex: "\\.[a-z0-9-_]+"
  177. }, {
  178. token: "variable.language",
  179. regex: ":[a-z0-9-_]+"
  180. }, {
  181. token: "constant",
  182. regex: "[a-z0-9-_]+"
  183. }, {
  184. token : "keyword.operator",
  185. regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
  186. }, {
  187. token : "paren.lparen",
  188. regex : "[[({]"
  189. }, {
  190. token : "paren.rparen",
  191. regex : "[\\])}]"
  192. }, {
  193. token : "text",
  194. regex : "\\s+"
  195. }, {
  196. caseInsensitive: true
  197. }
  198. ],
  199. "comment" : [
  200. {
  201. token : "comment", // closing comment
  202. regex : ".*?\\*\\/",
  203. next : "start"
  204. }, {
  205. token : "comment", // comment spanning whole line
  206. regex : ".+"
  207. }
  208. ],
  209. "qqstring" : [
  210. {
  211. token : "string",
  212. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  213. next : "start"
  214. }, {
  215. token : "string",
  216. regex : '.+'
  217. }
  218. ],
  219. "qstring" : [
  220. {
  221. token : "string",
  222. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  223. next : "start"
  224. }, {
  225. token : "string",
  226. regex : '.+'
  227. }
  228. ]
  229. };
  230. };
  231. oop.inherits(ScssHighlightRules, TextHighlightRules);
  232. exports.ScssHighlightRules = ScssHighlightRules;
  233. });
  234. ace.define("ace/mode/sass_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/scss_highlight_rules"], function(require, exports, module) {
  235. "use strict";
  236. var oop = require("../lib/oop");
  237. var lang = require("../lib/lang");
  238. var ScssHighlightRules = require("./scss_highlight_rules").ScssHighlightRules;
  239. var SassHighlightRules = function() {
  240. ScssHighlightRules.call(this);
  241. var start = this.$rules.start;
  242. if (start[1].token == "comment") {
  243. start.splice(1, 1, {
  244. onMatch: function(value, currentState, stack) {
  245. stack.unshift(this.next, -1, value.length - 2, currentState);
  246. return "comment";
  247. },
  248. regex: /^\s*\/\*/,
  249. next: "comment"
  250. }, {
  251. token: "error.invalid",
  252. regex: "/\\*|[{;}]"
  253. }, {
  254. token: "support.type",
  255. regex: /^\s*:[\w\-]+\s/
  256. });
  257. this.$rules.comment = [
  258. {regex: /^\s*/, onMatch: function(value, currentState, stack) {
  259. if (stack[1] === -1)
  260. stack[1] = Math.max(stack[2], value.length - 1);
  261. if (value.length <= stack[1]) {stack.shift();stack.shift();stack.shift();
  262. this.next = stack.shift();
  263. return "text";
  264. } else {
  265. this.next = "";
  266. return "comment";
  267. }
  268. }, next: "start"},
  269. {defaultToken: "comment"}
  270. ]
  271. }
  272. };
  273. oop.inherits(SassHighlightRules, ScssHighlightRules);
  274. exports.SassHighlightRules = SassHighlightRules;
  275. });
  276. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  277. "use strict";
  278. var oop = require("../../lib/oop");
  279. var BaseFoldMode = require("./fold_mode").FoldMode;
  280. var Range = require("../../range").Range;
  281. var FoldMode = exports.FoldMode = function() {};
  282. oop.inherits(FoldMode, BaseFoldMode);
  283. (function() {
  284. this.getFoldWidgetRange = function(session, foldStyle, row) {
  285. var range = this.indentationBlock(session, row);
  286. if (range)
  287. return range;
  288. var re = /\S/;
  289. var line = session.getLine(row);
  290. var startLevel = line.search(re);
  291. if (startLevel == -1 || line[startLevel] != "#")
  292. return;
  293. var startColumn = line.length;
  294. var maxRow = session.getLength();
  295. var startRow = row;
  296. var endRow = row;
  297. while (++row < maxRow) {
  298. line = session.getLine(row);
  299. var level = line.search(re);
  300. if (level == -1)
  301. continue;
  302. if (line[level] != "#")
  303. break;
  304. endRow = row;
  305. }
  306. if (endRow > startRow) {
  307. var endColumn = session.getLine(endRow).length;
  308. return new Range(startRow, startColumn, endRow, endColumn);
  309. }
  310. };
  311. this.getFoldWidget = function(session, foldStyle, row) {
  312. var line = session.getLine(row);
  313. var indent = line.search(/\S/);
  314. var next = session.getLine(row + 1);
  315. var prev = session.getLine(row - 1);
  316. var prevIndent = prev.search(/\S/);
  317. var nextIndent = next.search(/\S/);
  318. if (indent == -1) {
  319. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  320. return "";
  321. }
  322. if (prevIndent == -1) {
  323. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  324. session.foldWidgets[row - 1] = "";
  325. session.foldWidgets[row + 1] = "";
  326. return "start";
  327. }
  328. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  329. if (session.getLine(row - 2).search(/\S/) == -1) {
  330. session.foldWidgets[row - 1] = "start";
  331. session.foldWidgets[row + 1] = "";
  332. return "";
  333. }
  334. }
  335. if (prevIndent!= -1 && prevIndent < indent)
  336. session.foldWidgets[row - 1] = "start";
  337. else
  338. session.foldWidgets[row - 1] = "";
  339. if (indent < nextIndent)
  340. return "start";
  341. else
  342. return "";
  343. };
  344. }).call(FoldMode.prototype);
  345. });
  346. ace.define("ace/mode/sass",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/sass_highlight_rules","ace/mode/folding/coffee"], function(require, exports, module) {
  347. "use strict";
  348. var oop = require("../lib/oop");
  349. var TextMode = require("./text").Mode;
  350. var SassHighlightRules = require("./sass_highlight_rules").SassHighlightRules;
  351. var FoldMode = require("./folding/coffee").FoldMode;
  352. var Mode = function() {
  353. this.HighlightRules = SassHighlightRules;
  354. this.foldingRules = new FoldMode();
  355. this.$behaviour = this.$defaultBehaviour;
  356. };
  357. oop.inherits(Mode, TextMode);
  358. (function() {
  359. this.lineCommentStart = "//";
  360. this.$id = "ace/mode/sass";
  361. }).call(Mode.prototype);
  362. exports.Mode = Mode;
  363. });