summaryrefslogtreecommitdiff
path: root/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js')
-rw-r--r--Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js101
1 files changed, 70 insertions, 31 deletions
diff --git a/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js b/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js
index 9e7b3ff22..f33f5a924 100644
--- a/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js
+++ b/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js
@@ -51,7 +51,7 @@ WebInspector.SourceCSSTokenizer = function()
{
WebInspector.SourceTokenizer.call(this);
- this._propertyKeywords = WebInspector.CSSCompletions.cssPropertiesMetainfo.keySet();
+ this._propertyKeywords = WebInspector.CSSCompletions.cssPropertiesMetainfoKeySet();
this._colorKeywords = WebInspector.CSSKeywordCompletions.colors();
this._valueKeywords = [
@@ -104,7 +104,12 @@ WebInspector.SourceCSSTokenizer = function()
"-webkit-right", "-webkit-small-control", "-webkit-text", "-webkit-xxx-large", "-webkit-zoom-in", "-webkit-zoom-out",
].keySet();
- this._mediaTypes = ["all", "aural", "braille", "embossed", "handheld", "import", "print", "projection", "screen", "tty", "tv"].keySet();
+ this._scssValueKeywords = [
+ "abs", "adjust-color", "adjust-hue", "alpha", "append", "ceil", "change-color", "comparable", "complement", "darken", "desaturate",
+ "fade-in", "fade-out", "floor", "grayscale", "hue", "ie-hex-str", "invert", "join", "length", "lighten",
+ "lightness", "max", "min", "mix", "nth", "opacify", "opacity", "percentage", "quote", "round", "saturate",
+ "saturation", "scale-color", "transparentize", "type-of", "unit", "unitless", "unquote", "zip"
+ ].keySet();
this._lexConditions = {
INITIAL: 0,
@@ -129,6 +134,10 @@ WebInspector.SourceCSSTokenizer = function()
this.condition = this.createInitialCondition();
}
+WebInspector.SourceCSSTokenizer.SCSSAtRelatedKeywords = ["from", "if", "in", "through"].keySet();
+
+WebInspector.SourceCSSTokenizer.MediaTypes = ["all", "aural", "braille", "embossed", "handheld", "import", "print", "projection", "screen", "tty", "tv"].keySet();
+
WebInspector.SourceCSSTokenizer.prototype = {
createInitialCondition: function()
{
@@ -152,6 +161,11 @@ WebInspector.SourceCSSTokenizer.prototype = {
return this._condition.parseCondition === this._parseConditions.PROPERTY_VALUE || this._condition.parseCondition === this._parseConditions.AT_RULE;
},
+ _setParseCondition: function(condition)
+ {
+ this._condition.parseCondition = condition;
+ },
+
nextToken: function(cursor)
{
var cursorOnEnter = cursor;
@@ -186,8 +200,9 @@ WebInspector.SourceCSSTokenizer.prototype = {
NumericLiteral = "-"? ([0-9]+ | [0-9]* "." [0-9]+) ("em" | "rem" | "__qem" | "ex" | "px" | "cm" |
"mm" | "in" | "pt" | "pc" | "deg" | "rad" | "grad" | "turn" | "ms" | "s" | "Hz" | "kHz" | "%")?;
- Color = "#" [0-9A-Fa-f]+;
- Identifier = [@!_\-$0-9a-zA-Z\[\]='"/]+;
+ ColorOrSelector = "#" [0-9A-Za-z]+;
+ Identifier = [@!_\-0-9a-zA-Z\[\]='"/&]+;
+ Variable = "$" Identifier;
DoubleStringContent = ([^\r\n\"\\] | "\\" ['"\\bfnrtv])*;
SingleStringContent = ([^\r\n\'\\] | "\\" ['"\\bfnrtv])*;
@@ -213,35 +228,37 @@ WebInspector.SourceCSSTokenizer.prototype = {
<INITIAL> OpenCurlyBracket
{
this.tokenType = "block-start";
+ this._condition.openBraces = (this._condition.openBraces || 0) + 1;
if (this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE)
- this._condition.parseCondition = this._parseConditions.INITIAL;
+ this._setParseCondition(this._parseConditions.INITIAL);
else
- this._condition.parseCondition = this._parseConditions.PROPERTY;
+ this._setParseCondition(this._parseConditions.PROPERTY);
return cursor;
}
<INITIAL> CloseCurlyBracket
{
this.tokenType = "block-end";
- this._condition.parseCondition = this._parseConditions.INITIAL;
+ if (this._condition.openBraces > 0)
+ --this._condition.openBraces;
+ this._setParseCondition(this._condition.openBraces ? this._parseConditions.PROPERTY : this._parseConditions.INITIAL);
+ delete this._condition.atKeyword;
return cursor;
}
<INITIAL> Colon
{
this.tokenType = null;
- if (this._condition.parseCondition === this._parseConditions.PROPERTY)
- this._condition.parseCondition = this._parseConditions.PROPERTY_VALUE;
+ if (this._condition.parseCondition === this._parseConditions.PROPERTY || this._condition.parseCondition === this._parseConditions.INITIAL)
+ this._setParseCondition(this._parseConditions.PROPERTY_VALUE);
return cursor;
}
<INITIAL> Semicolon
{
this.tokenType = null;
- if (this._condition.parseCondition === this._parseConditions.AT_RULE)
- this._condition.parseCondition = this._parseConditions.INITIAL;
- else
- this._condition.parseCondition = this._parseConditions.PROPERTY;
+ this._setParseCondition(this._condition.openBraces ? this._parseConditions.PROPERTY : this._parseConditions.INITIAL);
+ delete this._condition.atKeyword;
return cursor;
}
@@ -254,41 +271,63 @@ WebInspector.SourceCSSTokenizer.prototype = {
return cursor;
}
- <INITIAL> Color
+ <INITIAL> ColorOrSelector
{
if (this._isPropertyValue())
this.tokenType = "css-color";
+ else if (this._condition.parseCondition === this._parseConditions.INITIAL)
+ this.tokenType = "css-selector";
else
this.tokenType = null;
return cursor;
}
+ <INITIAL> Variable
+ {
+ if (this._condition.parseCondition === this._condition.parseCondition.INITIAL || this._condition.parseCondition === this._condition.parseCondition.AT_RULE)
+ this._setParseCondition(this._parseConditions.PROPERTY);
+ this.tokenType = "scss-variable";
+ return cursor;
+ }
+
<INITIAL> Identifier
{
var token = this._line.substring(cursorOnEnter, cursor);
- if (this._condition.parseCondition === this._parseConditions.INITIAL) {
- if (token === "@media") {
+ this.tokenType = null;
+ if (this._condition.parseCondition === this._parseConditions.INITIAL || this._condition.parseCondition === this._parseConditions.PROPERTY) {
+ if (token.charAt(0) === "@") {
this.tokenType = "css-at-rule";
- this._condition.parseCondition = this._parseConditions.AT_MEDIA_RULE;
- } else if (token.startsWith("@")) {
+ this._setParseCondition(token === "@media" ? this._parseConditions.AT_MEDIA_RULE : this._parseConditions.AT_RULE);
+ this._condition.atKeyword = token;
+ } else if (this._condition.parseCondition === this._parseConditions.INITIAL)
+ this.tokenType = "css-selector";
+ else if (this._propertyKeywords.hasOwnProperty(token))
+ this.tokenType = "css-property";
+ } else if (this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE || this._condition.parseCondition === this._parseConditions.AT_RULE) {
+ if (WebInspector.SourceCSSTokenizer.SCSSAtRelatedKeywords.hasOwnProperty(token))
this.tokenType = "css-at-rule";
- this._condition.parseCondition = this._parseConditions.AT_RULE;
- } else
+ else if (WebInspector.SourceCSSTokenizer.MediaTypes.hasOwnProperty(token))
+ this.tokenType = "css-keyword";
+ }
+ if (this.tokenType)
+ return cursor;
+
+ if (this._isPropertyValue()) {
+ var firstChar = token.charAt(0);
+ if (firstChar === "$")
+ this.tokenType = "scss-variable";
+ else if (firstChar === "!")
+ this.tokenType = "css-bang-keyword";
+ else if (this._condition.atKeyword === "@extend")
this.tokenType = "css-selector";
- } else if ((this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE || this._condition.parseCondition === this._parseConditions.AT_RULE) && token in this._mediaTypes)
- this.tokenType = "css-keyword";
- else if (this._condition.parseCondition === this._parseConditions.PROPERTY && token in this._propertyKeywords)
- this.tokenType = "css-property";
- else if (this._isPropertyValue()) {
- if (token in this._valueKeywords)
+ else if (this._valueKeywords.hasOwnProperty(token) || this._scssValueKeywords.hasOwnProperty(token))
this.tokenType = "css-keyword";
- else if (token in this._colorKeywords) {
+ else if (this._colorKeywords.hasOwnProperty(token)) {
// FIXME: this does not convert tokens toLowerCase() for the sake of speed.
this.tokenType = "css-color";
- } else if (token === "!important")
- this.tokenType = "css-important";
- } else
- this.tokenType = null;
+ }
+ } else if (this._condition.parseCondition !== this._parseConditions.PROPERTY_VALUE)
+ this.tokenType = "css-selector";
return cursor;
}
<*> [^] { this.tokenType = null; return cursor; }