mode-sass.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. ace.define("ace/mode/scss_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|unquote").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. ("aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|" +
  94. "blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|" +
  95. "chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|" +
  96. "darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|" +
  97. "darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|" +
  98. "darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|" +
  99. "darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|" +
  100. "dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|" +
  101. "ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|" +
  102. "hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|" +
  103. "lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|" +
  104. "lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|" +
  105. "lightsalmon|lightseagreen|lightskyblue|lightslategray|" +
  106. "lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|" +
  107. "magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|" +
  108. "mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|" +
  109. "mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|" +
  110. "moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|" +
  111. "orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|" +
  112. "papayawhip|peachpuff|peru|pink|plum|powderblue|purple|rebeccapurple|" +
  113. "red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|" +
  114. "seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|" +
  115. "springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|" +
  116. "wheat|white|whitesmoke|yellow|yellowgreen").split("|")
  117. );
  118. var keywords = lang.arrayToMap(
  119. ("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|def|end|declare").split("|")
  120. );
  121. var tags = lang.arrayToMap(
  122. ("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|" +
  123. "big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|" +
  124. "command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|" +
  125. "figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|" +
  126. "header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|" +
  127. "link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|" +
  128. "option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|" +
  129. "small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|" +
  130. "textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp").split("|")
  131. );
  132. var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
  133. this.$rules = {
  134. "start" : [
  135. {
  136. token : "comment",
  137. regex : "\\/\\/.*$"
  138. },
  139. {
  140. token : "comment", // multi line comment
  141. regex : "\\/\\*",
  142. next : "comment"
  143. }, {
  144. token : "string", // single line
  145. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  146. }, {
  147. token : "string", // multi line string start
  148. regex : '["].*\\\\$',
  149. next : "qqstring"
  150. }, {
  151. token : "string", // single line
  152. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  153. }, {
  154. token : "string", // multi line string start
  155. regex : "['].*\\\\$",
  156. next : "qstring"
  157. }, {
  158. token : "constant.numeric",
  159. regex : numRe + "(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"
  160. }, {
  161. token : "constant.numeric", // hex6 color
  162. regex : "#[a-f0-9]{6}"
  163. }, {
  164. token : "constant.numeric", // hex3 color
  165. regex : "#[a-f0-9]{3}"
  166. }, {
  167. token : "constant.numeric",
  168. regex : numRe
  169. }, {
  170. token : ["support.function", "string", "support.function"],
  171. regex : "(url\\()(.*)(\\))"
  172. }, {
  173. token : function(value) {
  174. if (properties.hasOwnProperty(value.toLowerCase()))
  175. return "support.type";
  176. if (keywords.hasOwnProperty(value))
  177. return "keyword";
  178. else if (constants.hasOwnProperty(value))
  179. return "constant.language";
  180. else if (functions.hasOwnProperty(value))
  181. return "support.function";
  182. else if (colors.hasOwnProperty(value.toLowerCase()))
  183. return "support.constant.color";
  184. else if (tags.hasOwnProperty(value.toLowerCase()))
  185. return "variable.language";
  186. else
  187. return "text";
  188. },
  189. regex : "\\-?[@a-z_][@a-z0-9_\\-]*"
  190. }, {
  191. token : "variable",
  192. regex : "[a-z_\\-$][a-z0-9_\\-$]*\\b"
  193. }, {
  194. token: "variable.language",
  195. regex: "#[a-z0-9-_]+"
  196. }, {
  197. token: "variable.language",
  198. regex: "\\.[a-z0-9-_]+"
  199. }, {
  200. token: "variable.language",
  201. regex: ":[a-z0-9-_]+"
  202. }, {
  203. token: "constant",
  204. regex: "[a-z0-9-_]+"
  205. }, {
  206. token : "keyword.operator",
  207. regex : "<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"
  208. }, {
  209. token : "paren.lparen",
  210. regex : "[[({]"
  211. }, {
  212. token : "paren.rparen",
  213. regex : "[\\])}]"
  214. }, {
  215. token : "text",
  216. regex : "\\s+"
  217. }, {
  218. caseInsensitive: true
  219. }
  220. ],
  221. "comment" : [
  222. {
  223. token : "comment", // closing comment
  224. regex : "\\*\\/",
  225. next : "start"
  226. }, {
  227. defaultToken : "comment"
  228. }
  229. ],
  230. "qqstring" : [
  231. {
  232. token : "string",
  233. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  234. next : "start"
  235. }, {
  236. token : "string",
  237. regex : '.+'
  238. }
  239. ],
  240. "qstring" : [
  241. {
  242. token : "string",
  243. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  244. next : "start"
  245. }, {
  246. token : "string",
  247. regex : '.+'
  248. }
  249. ]
  250. };
  251. };
  252. oop.inherits(ScssHighlightRules, TextHighlightRules);
  253. exports.ScssHighlightRules = ScssHighlightRules;
  254. });
  255. ace.define("ace/mode/sass_highlight_rules",[], function(require, exports, module) {
  256. "use strict";
  257. var oop = require("../lib/oop");
  258. var lang = require("../lib/lang");
  259. var ScssHighlightRules = require("./scss_highlight_rules").ScssHighlightRules;
  260. var SassHighlightRules = function() {
  261. ScssHighlightRules.call(this);
  262. var start = this.$rules.start;
  263. if (start[1].token == "comment") {
  264. start.splice(1, 1, {
  265. onMatch: function(value, currentState, stack) {
  266. stack.unshift(this.next, -1, value.length - 2, currentState);
  267. return "comment";
  268. },
  269. regex: /^\s*\/\*/,
  270. next: "comment"
  271. }, {
  272. token: "error.invalid",
  273. regex: "/\\*|[{;}]"
  274. }, {
  275. token: "support.type",
  276. regex: /^\s*:[\w\-]+\s/
  277. });
  278. this.$rules.comment = [
  279. {regex: /^\s*/, onMatch: function(value, currentState, stack) {
  280. if (stack[1] === -1)
  281. stack[1] = Math.max(stack[2], value.length - 1);
  282. if (value.length <= stack[1]) {
  283. stack.shift();stack.shift();stack.shift();
  284. this.next = stack.shift();
  285. return "text";
  286. } else {
  287. this.next = "";
  288. return "comment";
  289. }
  290. }, next: "start"},
  291. {defaultToken: "comment"}
  292. ];
  293. }
  294. };
  295. oop.inherits(SassHighlightRules, ScssHighlightRules);
  296. exports.SassHighlightRules = SassHighlightRules;
  297. });
  298. ace.define("ace/mode/folding/coffee",[], function(require, exports, module) {
  299. "use strict";
  300. var oop = require("../../lib/oop");
  301. var BaseFoldMode = require("./fold_mode").FoldMode;
  302. var Range = require("../../range").Range;
  303. var FoldMode = exports.FoldMode = function() {};
  304. oop.inherits(FoldMode, BaseFoldMode);
  305. (function() {
  306. this.getFoldWidgetRange = function(session, foldStyle, row) {
  307. var range = this.indentationBlock(session, row);
  308. if (range)
  309. return range;
  310. var re = /\S/;
  311. var line = session.getLine(row);
  312. var startLevel = line.search(re);
  313. if (startLevel == -1 || line[startLevel] != "#")
  314. return;
  315. var startColumn = line.length;
  316. var maxRow = session.getLength();
  317. var startRow = row;
  318. var endRow = row;
  319. while (++row < maxRow) {
  320. line = session.getLine(row);
  321. var level = line.search(re);
  322. if (level == -1)
  323. continue;
  324. if (line[level] != "#")
  325. break;
  326. endRow = row;
  327. }
  328. if (endRow > startRow) {
  329. var endColumn = session.getLine(endRow).length;
  330. return new Range(startRow, startColumn, endRow, endColumn);
  331. }
  332. };
  333. this.getFoldWidget = function(session, foldStyle, row) {
  334. var line = session.getLine(row);
  335. var indent = line.search(/\S/);
  336. var next = session.getLine(row + 1);
  337. var prev = session.getLine(row - 1);
  338. var prevIndent = prev.search(/\S/);
  339. var nextIndent = next.search(/\S/);
  340. if (indent == -1) {
  341. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  342. return "";
  343. }
  344. if (prevIndent == -1) {
  345. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  346. session.foldWidgets[row - 1] = "";
  347. session.foldWidgets[row + 1] = "";
  348. return "start";
  349. }
  350. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  351. if (session.getLine(row - 2).search(/\S/) == -1) {
  352. session.foldWidgets[row - 1] = "start";
  353. session.foldWidgets[row + 1] = "";
  354. return "";
  355. }
  356. }
  357. if (prevIndent!= -1 && prevIndent < indent)
  358. session.foldWidgets[row - 1] = "start";
  359. else
  360. session.foldWidgets[row - 1] = "";
  361. if (indent < nextIndent)
  362. return "start";
  363. else
  364. return "";
  365. };
  366. }).call(FoldMode.prototype);
  367. });
  368. ace.define("ace/mode/sass",[], function(require, exports, module) {
  369. "use strict";
  370. var oop = require("../lib/oop");
  371. var TextMode = require("./text").Mode;
  372. var SassHighlightRules = require("./sass_highlight_rules").SassHighlightRules;
  373. var FoldMode = require("./folding/coffee").FoldMode;
  374. var Mode = function() {
  375. this.HighlightRules = SassHighlightRules;
  376. this.foldingRules = new FoldMode();
  377. this.$behaviour = this.$defaultBehaviour;
  378. };
  379. oop.inherits(Mode, TextMode);
  380. (function() {
  381. this.lineCommentStart = "//";
  382. this.$id = "ace/mode/sass";
  383. }).call(Mode.prototype);
  384. exports.Mode = Mode;
  385. });
  386. (function() {
  387. ace.require(["ace/mode/sass"], function(m) {
  388. if (typeof module == "object" && typeof exports == "object" && module) {
  389. module.exports = m;
  390. }
  391. });
  392. })();