Unreviewed, rolling out r152598.
[WebKit-https.git] / Source / WebInspectorUI / Tools / PrettyPrinting / css.js
1 CodeMirror.defineMode("css", function(config) {
2   return CodeMirror.getMode(config, "text/css");
3 });
4
5 CodeMirror.defineMode("css-base", function(config, parserConfig) {
6   "use strict";
7
8   var indentUnit = config.indentUnit,
9       hooks = parserConfig.hooks || {},
10       atMediaTypes = parserConfig.atMediaTypes || {},
11       atMediaFeatures = parserConfig.atMediaFeatures || {},
12       propertyKeywords = parserConfig.propertyKeywords || {},
13       colorKeywords = parserConfig.colorKeywords || {},
14       valueKeywords = parserConfig.valueKeywords || {},
15       allowNested = !!parserConfig.allowNested,
16       type = null;
17
18   function ret(style, tp) { type = tp; return style; }
19
20   function tokenBase(stream, state) {
21     var ch = stream.next();
22     if (hooks[ch]) {
23       // result[0] is style and result[1] is type
24       var result = hooks[ch](stream, state);
25       if (result !== false) return result;
26     }
27     if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("def", stream.current());}
28     else if (ch == "=") ret(null, "compare");
29     else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
30     else if (ch == "\"" || ch == "'") {
31       state.tokenize = tokenString(ch);
32       return state.tokenize(stream, state);
33     }
34     else if (ch == "#") {
35       stream.eatWhile(/[\w\\\-]/);
36       return ret("atom", "hash");
37     }
38     else if (ch == "!") {
39       stream.match(/^\s*\w*/);
40       return ret("keyword", "important");
41     }
42     else if (/\d/.test(ch)) {
43       stream.eatWhile(/[\w.%]/);
44       return ret("number", "unit");
45     }
46     else if (ch === "-") {
47       if (/\d/.test(stream.peek())) {
48         stream.eatWhile(/[\w.%]/);
49         return ret("number", "unit");
50       } else if (stream.match(/^[^-]+-/)) {
51         return ret("meta", "meta");
52       }
53     }
54     else if (/[,+>*\/]/.test(ch)) {
55       return ret(null, "select-op");
56     }
57     else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
58       return ret("qualifier", "qualifier");
59     }
60     else if (ch == ":") {
61       return ret("operator", ch);
62     }
63     else if (/[;{}\[\]\(\)]/.test(ch)) {
64       return ret(null, ch);
65     }
66     else if (ch == "u" && stream.match("rl(")) {
67       stream.backUp(1);
68       state.tokenize = tokenParenthesized;
69       return ret("property", "variable");
70     }
71     else {
72       stream.eatWhile(/[\w\\\-]/);
73       return ret("property", "variable");
74     }
75   }
76
77   function tokenString(quote, nonInclusive) {
78     return function(stream, state) {
79       var escaped = false, ch;
80       while ((ch = stream.next()) != null) {
81         if (ch == quote && !escaped)
82           break;
83         escaped = !escaped && ch == "\\";
84       }
85       if (!escaped) {
86         if (nonInclusive) stream.backUp(1);
87         state.tokenize = tokenBase;
88       }
89       return ret("string", "string");
90     };
91   }
92
93   function tokenParenthesized(stream, state) {
94     stream.next(); // Must be '('
95     if (!stream.match(/\s*[\"\']/, false))
96       state.tokenize = tokenString(")", true);
97     else
98       state.tokenize = tokenBase;
99     return ret(null, "(");
100   }
101
102   return {
103     startState: function(base) {
104       return {tokenize: tokenBase,
105               baseIndent: base || 0,
106               stack: []};
107     },
108
109     token: function(stream, state) {
110
111       // Use these terms when applicable (see http://www.xanthir.com/blog/b4E50)
112       //
113       // rule** or **ruleset:
114       // A selector + braces combo, or an at-rule.
115       //
116       // declaration block:
117       // A sequence of declarations.
118       //
119       // declaration:
120       // A property + colon + value combo.
121       //
122       // property value:
123       // The entire value of a property.
124       //
125       // component value:
126       // A single piece of a property value. Like the 5px in
127       // text-shadow: 0 0 5px blue;. Can also refer to things that are
128       // multiple terms, like the 1-4 terms that make up the background-size
129       // portion of the background shorthand.
130       //
131       // term:
132       // The basic unit of author-facing CSS, like a single number (5),
133       // dimension (5px), string ("foo"), or function. Officially defined
134       //  by the CSS 2.1 grammar (look for the 'term' production)
135       //
136       //
137       // simple selector:
138       // A single atomic selector, like a type selector, an attr selector, a
139       // class selector, etc.
140       //
141       // compound selector:
142       // One or more simple selectors without a combinator. div.example is
143       // compound, div > .example is not.
144       //
145       // complex selector:
146       // One or more compound selectors chained with combinators.
147       //
148       // combinator:
149       // The parts of selectors that express relationships. There are four
150       // currently - the space (descendant combinator), the greater-than
151       // bracket (child combinator), the plus sign (next sibling combinator),
152       // and the tilda (following sibling combinator).
153       //
154       // sequence of selectors:
155       // One or more of the named type of selector chained with commas.
156
157       state.tokenize = state.tokenize || tokenBase;
158       if (state.tokenize == tokenBase && stream.eatSpace()) return null;
159       var style = state.tokenize(stream, state);
160       if (style && typeof style != "string") style = ret(style[0], style[1]);
161
162       // Changing style returned based on context
163       var context = state.stack[state.stack.length-1];
164       if (style == "variable") {
165         if (type == "variable-definition") state.stack.push("propertyValue");
166         return "variable-2";
167       } else if (style == "property") {
168         if (context == "propertyValue"){
169           if (valueKeywords[stream.current()]) {
170             style = "string-2";
171           } else if (colorKeywords[stream.current()]) {
172             style = "keyword";
173           } else {
174             style = "variable-2";
175           }
176         } else if (context == "rule") {
177           if (!propertyKeywords[stream.current()]) {
178             style += " error";
179           }
180         } else if (context == "block") {
181           // if a value is present in both property, value, or color, the order
182           // of preference is property -> color -> value
183           if (propertyKeywords[stream.current()]) {
184             style = "property";
185           } else if (colorKeywords[stream.current()]) {
186             style = "keyword";
187           } else if (valueKeywords[stream.current()]) {
188             style = "string-2";
189           } else {
190             style = "tag";
191           }
192         } else if (!context || context == "@media{") {
193           style = "tag";
194         } else if (context == "@media") {
195           if (atMediaTypes[stream.current()]) {
196             style = "attribute"; // Known attribute
197           } else if (/^(only|not)$/i.test(stream.current())) {
198             style = "keyword";
199           } else if (stream.current().toLowerCase() == "and") {
200             style = "error"; // "and" is only allowed in @mediaType
201           } else if (atMediaFeatures[stream.current()]) {
202             style = "error"; // Known property, should be in @mediaType(
203           } else {
204             // Unknown, expecting keyword or attribute, assuming attribute
205             style = "attribute error";
206           }
207         } else if (context == "@mediaType") {
208           if (atMediaTypes[stream.current()]) {
209             style = "attribute";
210           } else if (stream.current().toLowerCase() == "and") {
211             style = "operator";
212           } else if (/^(only|not)$/i.test(stream.current())) {
213             style = "error"; // Only allowed in @media
214           } else if (atMediaFeatures[stream.current()]) {
215             style = "error"; // Known property, should be in parentheses
216           } else {
217             // Unknown attribute or property, but expecting property (preceded
218             // by "and"). Should be in parentheses
219             style = "error";
220           }
221         } else if (context == "@mediaType(") {
222           if (propertyKeywords[stream.current()]) {
223             // do nothing, remains "property"
224           } else if (atMediaTypes[stream.current()]) {
225             style = "error"; // Known property, should be in parentheses
226           } else if (stream.current().toLowerCase() == "and") {
227             style = "operator";
228           } else if (/^(only|not)$/i.test(stream.current())) {
229             style = "error"; // Only allowed in @media
230           } else {
231             style += " error";
232           }
233         } else {
234           style = "error";
235         }
236       } else if (style == "atom") {
237         if(!context || context == "@media{" || context == "block") {
238           style = "builtin";
239         } else if (context == "propertyValue") {
240           if (!/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
241             style += " error";
242           }
243         } else {
244           style = "error";
245         }
246       } else if (context == "@media" && type == "{") {
247         style = "error";
248       }
249
250       // Push/pop context stack
251       if (type == "{") {
252         if (context == "@media" || context == "@mediaType") {
253           state.stack.pop();
254           state.stack[state.stack.length-1] = "@media{";
255         }
256         else {
257           var newContext = allowNested ? "block" : "rule";
258           state.stack.push(newContext);
259         }
260       }
261       else if (type == "}") {
262         var lastState = state.stack[state.stack.length - 1];
263         if (lastState == "interpolation") style = "operator";
264         state.stack.pop();
265         if (context == "propertyValue") state.stack.pop();
266       }
267       else if (type == "interpolation") state.stack.push("interpolation");
268       else if (type == "@media") state.stack.push("@media");
269       else if (context == "@media" && /\b(keyword|attribute)\b/.test(style))
270         state.stack.push("@mediaType");
271       else if (context == "@mediaType" && stream.current() == ",") state.stack.pop();
272       else if (context == "@mediaType" && type == "(") state.stack.push("@mediaType(");
273       else if (context == "@mediaType(" && type == ")") state.stack.pop();
274       else if ((context == "rule" || context == "block") && type == ":") state.stack.push("propertyValue");
275       else if (context == "propertyValue" && type == ";") state.stack.pop();
276       return style;
277     },
278
279     indent: function(state, textAfter) {
280       var n = state.stack.length;
281       if (/^\}/.test(textAfter))
282         n -= state.stack[state.stack.length-1] == "propertyValue" ? 2 : 1;
283       return state.baseIndent + n * indentUnit;
284     },
285
286     electricChars: "}"
287   };
288 });
289
290 (function() {
291   function keySet(array) {
292     var keys = {};
293     for (var i = 0; i < array.length; ++i) {
294       keys[array[i]] = true;
295     }
296     return keys;
297   }
298
299   var atMediaTypes = keySet([
300     "all", "aural", "braille", "handheld", "print", "projection", "screen",
301     "tty", "tv", "embossed"
302   ]);
303
304   var atMediaFeatures = keySet([
305     "width", "min-width", "max-width", "height", "min-height", "max-height",
306     "device-width", "min-device-width", "max-device-width", "device-height",
307     "min-device-height", "max-device-height", "aspect-ratio",
308     "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
309     "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
310     "max-color", "color-index", "min-color-index", "max-color-index",
311     "monochrome", "min-monochrome", "max-monochrome", "resolution",
312     "min-resolution", "max-resolution", "scan", "grid"
313   ]);
314
315   var propertyKeywords = keySet([
316     "align-content", "align-items", "align-self", "alignment-adjust",
317     "alignment-baseline", "anchor-point", "animation", "animation-delay",
318     "animation-direction", "animation-duration", "animation-iteration-count",
319     "animation-name", "animation-play-state", "animation-timing-function",
320     "appearance", "azimuth", "backface-visibility", "background",
321     "background-attachment", "background-clip", "background-color",
322     "background-image", "background-origin", "background-position",
323     "background-repeat", "background-size", "baseline-shift", "binding",
324     "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
325     "bookmark-target", "border", "border-bottom", "border-bottom-color",
326     "border-bottom-left-radius", "border-bottom-right-radius",
327     "border-bottom-style", "border-bottom-width", "border-collapse",
328     "border-color", "border-image", "border-image-outset",
329     "border-image-repeat", "border-image-slice", "border-image-source",
330     "border-image-width", "border-left", "border-left-color",
331     "border-left-style", "border-left-width", "border-radius", "border-right",
332     "border-right-color", "border-right-style", "border-right-width",
333     "border-spacing", "border-style", "border-top", "border-top-color",
334     "border-top-left-radius", "border-top-right-radius", "border-top-style",
335     "border-top-width", "border-width", "bottom", "box-decoration-break",
336     "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
337     "caption-side", "clear", "clip", "color", "color-profile", "column-count",
338     "column-fill", "column-gap", "column-rule", "column-rule-color",
339     "column-rule-style", "column-rule-width", "column-span", "column-width",
340     "columns", "content", "counter-increment", "counter-reset", "crop", "cue",
341     "cue-after", "cue-before", "cursor", "direction", "display",
342     "dominant-baseline", "drop-initial-after-adjust",
343     "drop-initial-after-align", "drop-initial-before-adjust",
344     "drop-initial-before-align", "drop-initial-size", "drop-initial-value",
345     "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
346     "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
347     "float", "float-offset", "font", "font-feature-settings", "font-family",
348     "font-kerning", "font-language-override", "font-size", "font-size-adjust",
349     "font-stretch", "font-style", "font-synthesis", "font-variant",
350     "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
351     "font-variant-ligatures", "font-variant-numeric", "font-variant-position",
352     "font-weight", "grid-cell", "grid-column", "grid-column-align",
353     "grid-column-sizing", "grid-column-span", "grid-columns", "grid-flow",
354     "grid-row", "grid-row-align", "grid-row-sizing", "grid-row-span",
355     "grid-rows", "grid-template", "hanging-punctuation", "height", "hyphens",
356     "icon", "image-orientation", "image-rendering", "image-resolution",
357     "inline-box-align", "justify-content", "left", "letter-spacing",
358     "line-break", "line-height", "line-stacking", "line-stacking-ruby",
359     "line-stacking-shift", "line-stacking-strategy", "list-style",
360     "list-style-image", "list-style-position", "list-style-type", "margin",
361     "margin-bottom", "margin-left", "margin-right", "margin-top",
362     "marker-offset", "marks", "marquee-direction", "marquee-loop",
363     "marquee-play-count", "marquee-speed", "marquee-style", "max-height",
364     "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
365     "nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline",
366     "outline-color", "outline-offset", "outline-style", "outline-width",
367     "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
368     "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
369     "page", "page-break-after", "page-break-before", "page-break-inside",
370     "page-policy", "pause", "pause-after", "pause-before", "perspective",
371     "perspective-origin", "pitch", "pitch-range", "play-during", "position",
372     "presentation-level", "punctuation-trim", "quotes", "rendering-intent",
373     "resize", "rest", "rest-after", "rest-before", "richness", "right",
374     "rotation", "rotation-point", "ruby-align", "ruby-overhang",
375     "ruby-position", "ruby-span", "size", "speak", "speak-as", "speak-header",
376     "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
377     "tab-size", "table-layout", "target", "target-name", "target-new",
378     "target-position", "text-align", "text-align-last", "text-decoration",
379     "text-decoration-color", "text-decoration-line", "text-decoration-skip",
380     "text-decoration-style", "text-emphasis", "text-emphasis-color",
381     "text-emphasis-position", "text-emphasis-style", "text-height",
382     "text-indent", "text-justify", "text-outline", "text-shadow",
383     "text-space-collapse", "text-transform", "text-underline-position",
384     "text-wrap", "top", "transform", "transform-origin", "transform-style",
385     "transition", "transition-delay", "transition-duration",
386     "transition-property", "transition-timing-function", "unicode-bidi",
387     "vertical-align", "visibility", "voice-balance", "voice-duration",
388     "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
389     "voice-volume", "volume", "white-space", "widows", "width", "word-break",
390     "word-spacing", "word-wrap", "z-index"
391   ]);
392
393   var colorKeywords = keySet([
394     "black", "silver", "gray", "white", "maroon", "red", "purple", "fuchsia",
395     "green", "lime", "olive", "yellow", "navy", "blue", "teal", "aqua"
396   ]);
397
398   var valueKeywords = keySet([
399     "above", "absolute", "activeborder", "activecaption", "afar",
400     "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
401     "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
402     "arabic-indic", "armenian", "asterisks", "auto", "avoid", "background",
403     "backwards", "baseline", "below", "bidi-override", "binary", "bengali",
404     "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
405     "both", "bottom", "break-all", "break-word", "button", "button-bevel",
406     "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
407     "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
408     "cell", "center", "checkbox", "circle", "cjk-earthly-branch",
409     "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
410     "col-resize", "collapse", "compact", "condensed", "contain", "content",
411     "content-box", "context-menu", "continuous", "copy", "cover", "crop",
412     "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
413     "decimal-leading-zero", "default", "default-button", "destination-atop",
414     "destination-in", "destination-out", "destination-over", "devanagari",
415     "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
416     "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
417     "element", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
418     "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
419     "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
420     "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
421     "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
422     "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
423     "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
424     "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
425     "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes",
426     "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
427     "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
428     "help", "hidden", "hide", "higher", "highlight", "highlighttext",
429     "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
430     "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
431     "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
432     "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert",
433     "italic", "justify", "kannada", "katakana", "katakana-iroha", "khmer",
434     "landscape", "lao", "large", "larger", "left", "level", "lighter",
435     "line-through", "linear", "lines", "list-item", "listbox", "listitem",
436     "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
437     "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
438     "lower-roman", "lowercase", "ltr", "malayalam", "match",
439     "media-controls-background", "media-current-time-display",
440     "media-fullscreen-button", "media-mute-button", "media-play-button",
441     "media-return-to-realtime-button", "media-rewind-button",
442     "media-seek-back-button", "media-seek-forward-button", "media-slider",
443     "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
444     "media-volume-slider-container", "media-volume-sliderthumb", "medium",
445     "menu", "menulist", "menulist-button", "menulist-text",
446     "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
447     "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
448     "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
449     "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
450     "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
451     "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
452     "outside", "overlay", "overline", "padding", "padding-box", "painted",
453     "paused", "persian", "plus-darker", "plus-lighter", "pointer", "portrait",
454     "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
455     "radio", "read-only", "read-write", "read-write-plaintext-only", "relative",
456     "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
457     "ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
458     "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
459     "searchfield-cancel-button", "searchfield-decoration",
460     "searchfield-results-button", "searchfield-results-decoration",
461     "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
462     "single", "skip-white-space", "slide", "slider-horizontal",
463     "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
464     "small", "small-caps", "small-caption", "smaller", "solid", "somali",
465     "source-atop", "source-in", "source-out", "source-over", "space", "square",
466     "square-button", "start", "static", "status-bar", "stretch", "stroke",
467     "sub", "subpixel-antialiased", "super", "sw-resize", "table",
468     "table-caption", "table-cell", "table-column", "table-column-group",
469     "table-footer-group", "table-header-group", "table-row", "table-row-group",
470     "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
471     "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
472     "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
473     "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
474     "transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
475     "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
476     "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
477     "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
478     "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider",
479     "window", "windowframe", "windowtext", "x-large", "x-small", "xor",
480     "xx-large", "xx-small"
481   ]);
482
483   function tokenCComment(stream, state) {
484     var maybeEnd = false, ch;
485     while ((ch = stream.next()) != null) {
486       if (maybeEnd && ch == "/") {
487         state.tokenize = null;
488         break;
489       }
490       maybeEnd = (ch == "*");
491     }
492     return ["comment", "comment"];
493   }
494
495   CodeMirror.defineMIME("text/css", {
496     atMediaTypes: atMediaTypes,
497     atMediaFeatures: atMediaFeatures,
498     propertyKeywords: propertyKeywords,
499     colorKeywords: colorKeywords,
500     valueKeywords: valueKeywords,
501     hooks: {
502       "<": function(stream, state) {
503         function tokenSGMLComment(stream, state) {
504           var dashes = 0, ch;
505           while ((ch = stream.next()) != null) {
506             if (dashes >= 2 && ch == ">") {
507               state.tokenize = null;
508               break;
509             }
510             dashes = (ch == "-") ? dashes + 1 : 0;
511           }
512           return ["comment", "comment"];
513         }
514         if (stream.eat("!")) {
515           state.tokenize = tokenSGMLComment;
516           return tokenSGMLComment(stream, state);
517         }
518       },
519       "/": function(stream, state) {
520         if (stream.eat("*")) {
521           state.tokenize = tokenCComment;
522           return tokenCComment(stream, state);
523         }
524         return false;
525       }
526     },
527     name: "css-base"
528   });
529
530   CodeMirror.defineMIME("text/x-scss", {
531     atMediaTypes: atMediaTypes,
532     atMediaFeatures: atMediaFeatures,
533     propertyKeywords: propertyKeywords,
534     colorKeywords: colorKeywords,
535     valueKeywords: valueKeywords,
536     allowNested: true,
537     hooks: {
538       "$": function(stream) {
539         stream.match(/^[\w-]+/);
540         if (stream.peek() == ":") {
541           return ["variable", "variable-definition"];
542         }
543         return ["variable", "variable"];
544       },
545       "/": function(stream, state) {
546         if (stream.eat("/")) {
547           stream.skipToEnd();
548           return ["comment", "comment"];
549         } else if (stream.eat("*")) {
550           state.tokenize = tokenCComment;
551           return tokenCComment(stream, state);
552         } else {
553           return ["operator", "operator"];
554         }
555       },
556       "#": function(stream) {
557         if (stream.eat("{")) {
558           return ["operator", "interpolation"];
559         } else {
560           stream.eatWhile(/[\w\\\-]/);
561           return ["atom", "hash"];
562         }
563       }
564     },
565     name: "css-base"
566   });
567 })();