2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // Generate js file as follows:
33 // re2c -isc WebCore/inspector/front-end/SourceCSSTokenizer.re2js \
34 // | sed 's|^yy\([^:]*\)*\:|case \1:|' \
35 // | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
36 // | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
37 // | sed 's|[*]cursor|this._charAt(cursor)|' \
38 // | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
39 // | sed 's|goto case \([^;]*\)|{ gotoCase = \1; continue; }|' \
40 // | sed 's|unsigned\ int|var|' \
41 // | sed 's|var\ yych|case 1: var yych|'
43 WebInspector.SourceCSSTokenizer = function()
45 WebInspector.SourceTokenizer.call(this);
47 this._propertyKeywords = WebInspector.cssNameCompletions.keySet();
49 this._valueKeywords = [
50 "above", "absolute", "activeborder", "activecaption", "afar", "after-white-space", "ahead", "alias", "all", "all-scroll",
51 "alternate", "always","amharic", "amharic-abegede", "antialiased", "appworkspace", "aqua", "arabic-indic", "armenian", "asterisks",
52 "auto", "avoid", "background", "backwards", "baseline", "below", "bidi-override", "binary", "bengali", "black", "blink",
53 "block", "block-axis", "blue", "bold", "bolder", "border", "border-box", "both", "bottom", "break-all", "break-word", "button",
54 "button-bevel", "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian", "capitalize", "caps-lock-indicator",
55 "caption", "captiontext", "caret", "cell", "center", "checkbox", "circle", "cjk-earthly-branch", "cjk-heavenly-stem", "cjk-ideographic",
56 "clear", "clip", "close-quote", "col-resize", "collapse", "compact", "condensed", "contain", "content", "content-box", "context-menu",
57 "continuous", "copy", "cover", "crop", "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal", "decimal-leading-zero", "default",
58 "default-button", "destination-atop", "destination-in", "destination-out", "destination-over", "devanagari", "disc", "discard", "document",
59 "dot-dash", "dot-dot-dash", "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", "element",
60 "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", "ethiopic-abegede-am-et", "ethiopic-abegede-gez",
61 "ethiopic-abegede-ti-er", "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", "ethiopic-halehame-aa-et",
62 "ethiopic-halehame-am-et", "ethiopic-halehame-gez", "ethiopic-halehame-om-et", "ethiopic-halehame-sid-et",
63 "ethiopic-halehame-so-et", "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", "ew-resize", "expanded",
64 "extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes", "forwards", "from", "fuchsia", "geometricPrecision",
65 "georgian", "gray", "graytext", "green", "grey", "groove", "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", "help",
66 "hidden", "hide", "higher", "highlight", "highlighttext", "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
67 "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", "infobackground", "infotext", "inherit", "initial", "inline",
68 "inline-axis", "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert", "italic", "justify", "kannada", "katakana",
69 "katakana-iroha", "khmer", "landscape", "lao", "large", "larger", "left", "level", "lighter", "lime", "line-through", "linear", "lines",
70 "list-button", "list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", "lower-greek",
71 "lower-hexadecimal", "lower-latin", "lower-norwegian", "lower-roman", "lowercase", "ltr", "malayalam", "maroon", "match", "media-controls-background",
72 "media-current-time-display", "media-fullscreen-button", "media-mute-button", "media-play-button", "media-return-to-realtime-button",
73 "media-rewind-button", "media-seek-back-button", "media-seek-forward-button", "media-slider", "media-sliderthumb", "media-time-remaining-display",
74 "media-volume-slider", "media-volume-slider-container", "media-volume-sliderthumb", "medium", "menu", "menulist", "menulist-button",
75 "menulist-text", "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", "mix", "mongolian", "monospace", "move", "multiple",
76 "myanmar", "n-resize", "narrower", "navy", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", "no-open-quote", "no-repeat", "none",
77 "normal", "not-allowed", "nowrap", "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "olive", "open-quote", "optimizeLegibility",
78 "optimizeSpeed", "orange", "oriya", "oromo", "outset", "outside", "overlay", "overline", "padding", "padding-box", "painted", "paused",
79 "persian", "plus-darker", "plus-lighter", "pointer", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "purple",
80 "push-button", "radio", "read-only", "read-write", "read-write-plaintext-only", "red", "relative", "repeat", "repeat-x",
81 "repeat-y", "reset", "reverse", "rgb", "rgba", "ridge", "right", "round", "row-resize", "rtl", "run-in", "running", "s-resize", "sans-serif",
82 "scroll", "scrollbar", "se-resize", "searchfield", "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
83 "searchfield-results-decoration", "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", "silver", "single",
84 "skip-white-space", "slide", "slider-horizontal", "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
85 "small", "small-caps", "small-caption", "smaller", "solid", "somali", "source-atop", "source-in", "source-out", "source-over",
86 "space", "square", "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub", "subpixel-antialiased", "super",
87 "sw-resize", "table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group",
88 "table-row", "table-row-group", "teal", "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", "thick", "thin",
89 "threeddarkshadow", "threedface", "threedhighlight", "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", "tigrinya-er-abegede",
90 "tigrinya-et", "tigrinya-et-abegede", "to", "top", "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", "upper-alpha", "upper-armenian",
91 "upper-greek", "upper-hexadecimal", "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", "vertical", "vertical-text", "visible",
92 "visibleFill", "visiblePainted", "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider", "window", "windowframe", "windowtext",
93 "x-large", "x-small", "xor", "xx-large", "xx-small", "yellow", "-wap-marquee", "-webkit-activelink", "-webkit-auto", "-webkit-baseline-middle",
94 "-webkit-body", "-webkit-box", "-webkit-center", "-webkit-control", "-webkit-focus-ring-color", "-webkit-grab", "-webkit-grabbing",
95 "-webkit-gradient", "-webkit-inline-box", "-webkit-left", "-webkit-link", "-webkit-marquee", "-webkit-mini-control", "-webkit-nowrap", "-webkit-pictograph",
96 "-webkit-right", "-webkit-small-control", "-webkit-text", "-webkit-xxx-large", "-webkit-zoom-in", "-webkit-zoom-out",
99 this._mediaTypes = ["all", "aural", "braille", "embossed", "handheld", "import", "print", "projection", "screen", "tty", "tv"].keySet();
101 this._lexConditions = {
108 this._parseConditions = {
115 this.case_INITIAL = 1000;
116 this.case_COMMENT = 1002;
117 this.case_DSTRING = 1003;
118 this.case_SSTRING = 1004;
120 this.condition = this.createInitialCondition();
123 WebInspector.SourceCSSTokenizer.prototype = {
124 createInitialCondition: function()
126 return { lexCondition: this._lexConditions.INITIAL, parseCondition: this._parseConditions.INITIAL };
129 _stringToken: function(cursor, stringEnds)
131 if (this._isPropertyValue())
132 this.tokenType = "css-string";
134 this.tokenType = null;
138 _isPropertyValue: function()
140 return this._condition.parseCondition === this._parseConditions.PROPERTY_VALUE || this._condition.parseCondition === this._parseConditions.AT_RULE;
143 nextToken: function(cursor)
145 var cursorOnEnter = cursor;
149 // Following comment is replaced with generated state machine.
151 re2c:define:YYCTYPE = "var";
152 re2c:define:YYCURSOR = cursor;
153 re2c:define:YYGETCONDITION = "this.getLexCondition";
154 re2c:define:YYSETCONDITION = "this.setLexCondition";
155 re2c:condprefix = "case this.case_";
156 re2c:condenumprefix = "this._lexConditions.";
157 re2c:yyfill:enable = 0;
158 re2c:labelprefix = "case ";
160 re2c:indent:string = " ";
162 CommentContent = ([^*\r\n] | ("*"+[^/*]))*;
163 Comment = "/*" CommentContent "*"+ "/";
164 CommentStart = "/*" CommentContent [\r\n];
165 CommentEnd = CommentContent "*"+ "/";
167 OpenCurlyBracket = "{";
168 CloseCurlyBracket = "}";
173 NumericLiteral = "-"? ([0-9]+ | [0-9]* "." [0-9]+) ("em" | "rem" | "__qem" | "ex" | "px" | "cm" |
174 "mm" | "in" | "pt" | "pc" | "deg" | "rad" | "grad" | "turn" | "ms" | "s" | "Hz" | "kHz" | "%")?;
176 Identifier = [@!_\-$0-9a-zA-Z\[\]='"/]+;
178 DoubleStringContent = ([^\r\n\"\\] | "\\" ['"\\bfnrtv])*;
179 SingleStringContent = ([^\r\n\'\\] | "\\" ['"\\bfnrtv])*;
180 StringLiteral = "\"" DoubleStringContent "\"" | "'" SingleStringContent "'";
181 DoubleStringStart = "\"" DoubleStringContent "\\" [\r\n];
182 DoubleStringEnd = DoubleStringContent "\"";
183 SingleStringStart = "'" SingleStringContent "\\" [\r\n];
184 SingleStringEnd = SingleStringContent "'";
186 <INITIAL> Comment { this.tokenType = "css-comment"; return cursor; }
187 <INITIAL> CommentStart => COMMENT { this.tokenType = "css-comment"; return cursor; }
188 <COMMENT> CommentContent => COMMENT { this.tokenType = "css-comment"; return cursor; }
189 <COMMENT> CommentEnd => INITIAL { this.tokenType = "css-comment"; return cursor; }
191 <INITIAL> StringLiteral { return this._stringToken(cursor, true); }
192 <INITIAL> DoubleStringStart => DSTRING { return this._stringToken(cursor); }
193 <DSTRING> DoubleStringContent => DSTRING { return this._stringToken(cursor); }
194 <DSTRING> DoubleStringEnd => INITIAL { return this._stringToken(cursor, true); }
195 <INITIAL> SingleStringStart => SSTRING { return this._stringToken(cursor); }
196 <SSTRING> SingleStringContent => SSTRING { return this._stringToken(cursor); }
197 <SSTRING> SingleStringEnd => INITIAL { return this._stringToken(cursor, true); }
199 <INITIAL> OpenCurlyBracket
201 this.tokenType = null;
202 if (this._condition.parseCondition === this._parseConditions.AT_RULE)
203 this._condition.parseCondition = this._parseConditions.INITIAL;
205 this._condition.parseCondition = this._parseConditions.PROPERTY;
209 <INITIAL> CloseCurlyBracket
211 this.tokenType = null;
212 this._condition.parseCondition = this._parseConditions.INITIAL;
218 this.tokenType = null;
219 if (this._condition.parseCondition === this._parseConditions.PROPERTY)
220 this._condition.parseCondition = this._parseConditions.PROPERTY_VALUE;
226 this.tokenType = null;
227 if (this._condition.parseCondition === this._parseConditions.AT_RULE)
228 this._condition.parseCondition = this._parseConditions.INITIAL;
230 this._condition.parseCondition = this._parseConditions.PROPERTY;
234 <INITIAL> NumericLiteral
236 if (this._isPropertyValue())
237 this.tokenType = "css-number";
239 this.tokenType = null;
245 var token = this._line.substring(cursorOnEnter, cursor);
246 if (this._condition.parseCondition === this._parseConditions.INITIAL) {
247 if (token === "@import" || token === "@media") {
248 this.tokenType = "css-at-rule";
249 this._condition.parseCondition = this._parseConditions.AT_RULE;
250 } else if (token.indexOf("@") === 0)
251 this.tokenType = "css-at-rule";
253 this.tokenType = "css-selector";
255 else if (this._condition.parseCondition === this._parseConditions.AT_RULE && token in this._mediaTypes)
256 this.tokenType = "css-keyword";
257 else if (this._condition.parseCondition === this._parseConditions.PROPERTY && token in this._propertyKeywords)
258 this.tokenType = "css-property";
259 else if (this._isPropertyValue() && token in this._valueKeywords)
260 this.tokenType = "css-keyword";
261 else if (token === "!important")
262 this.tokenType = "css-important";
264 this.tokenType = null;
267 <*> [^] { this.tokenType = null; return cursor; }
273 WebInspector.SourceCSSTokenizer.prototype.__proto__ = WebInspector.SourceTokenizer.prototype;