2 * Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2012 Intel Corporation. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 %parse-param { CSSParser* parser }
27 %lex-param { CSSParser* parser }
34 CSSParserString string;
37 Vector<RefPtr<StyleRuleBase> >* ruleList;
38 CSSParserSelector* selector;
39 Vector<OwnPtr<CSSParserSelector> >* selectorList;
40 CSSSelector::MarginBoxType marginBox;
41 CSSSelector::Relation relation;
42 MediaQuerySet* mediaList;
43 MediaQuery* mediaQuery;
44 MediaQuery::Restrictor mediaQueryRestrictor;
45 MediaQueryExp* mediaQueryExp;
47 CSSParserValueList* valueList;
48 Vector<OwnPtr<MediaQueryExp> >* mediaQueryExpList;
49 StyleKeyframe* keyframe;
50 Vector<RefPtr<StyleKeyframe> >* keyframeRuleList;
57 static inline int cssyyerror(void*, const char*)
74 %token WHITESPACE SGML_CD
83 %token <string> STRING
87 %nonassoc <string> HEX
88 %nonassoc <string> IDSEL
92 %nonassoc <string> '*'
99 #if ENABLE_CSS3_CONDITIONAL_RULES
103 #if ENABLE_SHADOW_DOM
109 %token WEBKIT_RULE_SYM
110 %token WEBKIT_DECLS_SYM
111 %token WEBKIT_KEYFRAME_RULE_SYM
112 %token WEBKIT_KEYFRAMES_SYM
113 %token WEBKIT_VALUE_SYM
114 %token WEBKIT_MEDIAQUERY_SYM
115 %token WEBKIT_SELECTOR_SYM
116 %token WEBKIT_REGION_RULE_SYM
117 %token WEBKIT_VIEWPORT_RULE_SYM
118 #if ENABLE_CSS3_CONDITIONAL_RULES
119 %token WEBKIT_SUPPORTS_CONDITION_SYM
121 #if ENABLE_CSS_SHADERS
122 %token WEBKIT_FILTER_RULE_SYM
124 %token <marginBox> TOPLEFTCORNER_SYM
125 %token <marginBox> TOPLEFT_SYM
126 %token <marginBox> TOPCENTER_SYM
127 %token <marginBox> TOPRIGHT_SYM
128 %token <marginBox> TOPRIGHTCORNER_SYM
129 %token <marginBox> BOTTOMLEFTCORNER_SYM
130 %token <marginBox> BOTTOMLEFT_SYM
131 %token <marginBox> BOTTOMCENTER_SYM
132 %token <marginBox> BOTTOMRIGHT_SYM
133 %token <marginBox> BOTTOMRIGHTCORNER_SYM
134 %token <marginBox> LEFTTOP_SYM
135 %token <marginBox> LEFTMIDDLE_SYM
136 %token <marginBox> LEFTBOTTOM_SYM
137 %token <marginBox> RIGHTTOP_SYM
138 %token <marginBox> RIGHTMIDDLE_SYM
139 %token <marginBox> RIGHTBOTTOM_SYM
147 #if ENABLE_CSS3_CONDITIONAL_RULES
165 %token <number> GRADS
166 %token <number> TURNS
167 %token <number> MSECS
169 %token <number> HERTZ
170 %token <number> KHERTZ
171 %token <string> DIMEN
172 %token <string> INVALIDDIMEN
173 %token <number> PERCENTAGE
174 %token <number> FLOATTOKEN
175 %token <number> INTEGER
185 %token <string> FUNCTION
186 %token <string> ANYFUNCTION
187 #if ENABLE_VIDEO_TRACK
188 %token <string> CUEFUNCTION
190 %token <string> NOTFUNCTION
191 %token <string> DISTRIBUTEDFUNCTION
192 %token <string> CALCFUNCTION
193 %token <string> MINFUNCTION
194 %token <string> MAXFUNCTION
195 %token <string> VAR_DEFINITION
197 %token <string> UNICODERANGE
199 %type <relation> combinator
202 %type <rule> ignored_charset
206 %type <rule> namespace
208 %type <rule> margin_box
209 %type <rule> font_face
210 #if ENABLE_SHADOW_DOM
213 %type <rule> keyframes
214 %type <rule> invalid_rule
215 %type <rule> save_block
216 %type <rule> invalid_at
218 %type <rule> valid_rule
219 %type <ruleList> block_rule_list
220 %type <ruleList> region_block_rule_list
221 %type <rule> block_rule
222 %type <rule> block_valid_rule
224 #if ENABLE_CSS3_CONDITIONAL_RULES
225 %type <rule> supports
227 #if ENABLE_CSS_DEVICE_ADAPTATION
228 %type <rule> viewport
230 #if ENABLE_CSS_SHADERS
234 %type <string> maybe_ns_prefix
236 %type <string> namespace_selector
238 %type <string> string_or_uri
239 %type <string> ident_or_string
240 %type <string> medium
241 %type <marginBox> margin_sym
243 %type <string> media_feature
244 %type <mediaList> media_list
245 %type <mediaList> maybe_media_list
246 %type <mediaQuery> media_query
247 %type <mediaQueryRestrictor> maybe_media_restrictor
248 %type <valueList> maybe_media_value
249 %type <mediaQueryExp> media_query_exp
250 %type <mediaQueryExpList> media_query_exp_list
251 %type <mediaQueryExpList> maybe_and_media_query_exp_list
253 #if ENABLE_CSS3_CONDITIONAL_RULES
254 %type <boolean> supports_condition
255 %type <boolean> supports_condition_in_parens
256 %type <boolean> supports_negation
257 %type <boolean> supports_conjunction
258 %type <boolean> supports_disjunction
259 %type <boolean> supports_declaration_condition
260 %type <boolean> supports_error
263 %type <string> keyframe_name
264 %type <keyframe> keyframe_rule
265 %type <keyframeRuleList> keyframes_rule
266 %type <valueList> key_list
271 %type <selector> specifier
272 %type <selector> specifier_list
273 %type <selector> simple_selector
274 %type <selector> selector
275 %type <selectorList> selector_list
276 %type <selectorList> simple_selector_list
277 %type <selectorList> region_selector
278 %type <selector> selector_with_trailing_whitespace
279 %type <selector> class
280 %type <selector> attrib
281 %type <selector> pseudo
282 %type <selector> pseudo_page
283 %type <selector> page_selector
285 %type <boolean> declaration_list
286 %type <boolean> decl_list
287 %type <boolean> declaration
288 %type <boolean> declarations_and_margins
292 %type <integer> match
293 %type <integer> unary_operator
294 %type <integer> maybe_unary_operator
295 %type <character> operator
297 %type <valueList> expr
299 %type <value> unary_term
300 %type <value> function
301 %type <value> calc_func_term
302 %type <character> calc_func_operator
303 %type <valueList> calc_func_expr
304 %type <valueList> calc_func_expr_list
305 %type <valueList> calc_func_paren_expr
306 %type <value> calc_function
307 %type <string> min_or_max
308 %type <value> min_or_max_function
310 %type <string> element_name
311 %type <string> attr_name
316 maybe_space maybe_charset maybe_sgml rule_list
317 | webkit_rule maybe_space
318 | webkit_decls maybe_space
319 | webkit_value maybe_space
320 | webkit_mediaquery maybe_space
321 | webkit_selector maybe_space
322 | webkit_keyframe_rule maybe_space
323 #if ENABLE_CSS3_CONDITIONAL_RULES
324 | webkit_supports_condition maybe_space
329 WEBKIT_RULE_SYM '{' maybe_space valid_rule maybe_space '}' {
334 webkit_keyframe_rule:
335 WEBKIT_KEYFRAME_RULE_SYM '{' maybe_space keyframe_rule maybe_space '}' {
336 parser->m_keyframe = $4;
341 WEBKIT_DECLS_SYM '{' maybe_space_before_declaration declaration_list '}' {
347 WEBKIT_VALUE_SYM '{' maybe_space expr '}' {
349 parser->m_valueList = parser->sinkFloatingValueList($4);
350 int oldParsedProperties = parser->m_parsedProperties.size();
351 if (!parser->parseValue(parser->m_id, parser->m_important))
352 parser->rollbackLastProperties(parser->m_parsedProperties.size() - oldParsedProperties);
353 parser->m_valueList = nullptr;
359 WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query '}' {
360 parser->m_mediaQuery = parser->sinkFloatingMediaQuery($4);
365 WEBKIT_SELECTOR_SYM '{' maybe_space selector_list '}' {
367 if (parser->m_selectorListForParseSelector)
368 parser->m_selectorListForParseSelector->adoptSelectorVector(*$4);
373 #if ENABLE_CSS3_CONDITIONAL_RULES
374 webkit_supports_condition:
375 WEBKIT_SUPPORTS_CONDITION_SYM '{' maybe_space supports_condition '}' {
376 parser->m_supportsCondition = $4;
382 /* empty */ %prec UNIMPORTANT_TOK
383 | maybe_space WHITESPACE
389 | maybe_sgml WHITESPACE
400 | %prec LOWEST_PREC TOKEN_EOF
404 CHARSET_SYM maybe_space STRING maybe_space ';' {
405 if (parser->m_styleSheet)
406 parser->m_styleSheet->parserSetEncodingFromCharsetRule($3);
407 if (parser->isExtractingSourceData() && parser->m_currentRuleDataStack->isEmpty() && parser->m_ruleSourceDataResult)
408 parser->addNewRuleToSourceTree(CSSRuleSourceData::createUnknown());
411 | CHARSET_SYM error invalid_block {
413 | CHARSET_SYM error ';' {
418 CHARSET_SYM maybe_space STRING maybe_space ';' {
419 // Ignore any @charset rule not at the beginning of the style sheet.
422 | CHARSET_SYM maybe_space ';' {
429 | rule_list rule maybe_sgml {
430 if ($2 && parser->m_styleSheet)
431 parser->m_styleSheet->parserAppendRule($2);
444 #if ENABLE_CSS3_CONDITIONAL_RULES
447 #if ENABLE_SHADOW_DOM
450 #if ENABLE_CSS_DEVICE_ADAPTATION
453 #if ENABLE_CSS_SHADERS
460 parser->m_hadSyntacticallyValidCSSRule = true;
468 /* empty */ { $$ = 0; }
469 | block_rule_list block_rule maybe_sgml {
473 $$ = parser->createRuleList();
479 region_block_rule_list:
480 /* empty */ { $$ = 0; }
481 | region_block_rule_list block_valid_rule maybe_sgml {
485 $$ = parser->createRuleList();
497 #if ENABLE_CSS3_CONDITIONAL_RULES
500 #if ENABLE_CSS_DEVICE_ADAPTATION
503 #if ENABLE_CSS_SHADERS
517 at_import_header_end_maybe_space:
519 parser->markRuleHeaderEnd();
520 parser->markRuleBodyStart();
526 parser->markRuleHeaderStart(CSSRuleSourceData::IMPORT_RULE);
531 before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list ';' {
532 $$ = parser->createImportRule($4, $6);
534 | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list TOKEN_EOF {
535 $$ = parser->createImportRule($4, $6);
537 | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list invalid_block {
539 parser->popRuleData();
541 | before_import_rule IMPORT_SYM error ';' {
543 parser->popRuleData();
545 | before_import_rule IMPORT_SYM error invalid_block {
547 parser->popRuleData();
552 NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space ';' {
553 parser->addNamespace($3, $4);
556 | NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space invalid_block {
559 | NAMESPACE_SYM error invalid_block {
562 | NAMESPACE_SYM error ';' {
568 /* empty */ { $$.clear(); }
569 | IDENT maybe_space { $$ = $1; }
587 | ':' maybe_space expr maybe_space {
593 maybe_media_restrictor maybe_space '(' maybe_space media_feature maybe_space maybe_media_value ')' maybe_space {
594 // If restrictor is specified, media query expression is invalid.
595 // Create empty media query expression and continue parsing media query.
596 if ($1 != MediaQuery::None)
597 $$ = parser->createFloatingMediaQueryExp("", 0);
600 $$ = parser->createFloatingMediaQueryExp($5, $7);
605 media_query_exp_list:
607 $$ = parser->createFloatingMediaQueryExpList();
608 $$->append(parser->sinkFloatingMediaQueryExp($1));
610 | media_query_exp_list maybe_space MEDIA_AND maybe_space media_query_exp {
612 $$->append(parser->sinkFloatingMediaQueryExp($5));
616 maybe_and_media_query_exp_list:
618 $$ = parser->createFloatingMediaQueryExpList();
620 | MEDIA_AND maybe_space media_query_exp_list {
625 maybe_media_restrictor:
627 $$ = MediaQuery::None;
630 $$ = MediaQuery::Only;
633 $$ = MediaQuery::Not;
638 media_query_exp_list {
639 $$ = parser->createFloatingMediaQuery(parser->sinkFloatingMediaQueryExpList($1));
642 maybe_media_restrictor maybe_space medium maybe_and_media_query_exp_list {
644 $$ = parser->createFloatingMediaQuery($1, $3, parser->sinkFloatingMediaQueryExpList($4));
650 $$ = parser->createMediaQuerySet();
657 $$ = parser->createMediaQuerySet();
658 $$->addMediaQuery(parser->sinkFloatingMediaQuery($1));
659 parser->updateLastMediaLine($$);
661 | media_list ',' maybe_space media_query {
664 $$->addMediaQuery(parser->sinkFloatingMediaQuery($4));
665 parser->updateLastMediaLine($$);
675 parser->markRuleBodyStart();
681 parser->markRuleHeaderStart(CSSRuleSourceData::MEDIA_RULE);
685 at_rule_header_end_maybe_space:
687 parser->markRuleHeaderEnd();
692 before_media_rule MEDIA_SYM maybe_space media_list at_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block {
693 $$ = parser->createMediaRule($4, $9);
695 | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space block_rule_list save_block {
696 $$ = parser->createMediaRule(0, $7);
698 | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space ';' {
700 parser->popRuleData();
710 #if ENABLE_CSS3_CONDITIONAL_RULES
712 before_supports_rule SUPPORTS_SYM maybe_space supports_condition at_supports_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block {
713 $$ = parser->createSupportsRule($4, $9);
715 | before_supports_rule SUPPORTS_SYM supports_error {
716 parser->popRuleData();
717 parser->popSupportsRuleData();
723 | error invalid_block
725 before_supports_rule:
727 parser->markRuleHeaderStart(CSSRuleSourceData::SUPPORTS_RULE);
728 parser->markSupportsRuleHeaderStart();
732 at_supports_rule_header_end:
734 parser->markRuleHeaderEnd();
735 parser->markSupportsRuleHeaderEnd();
740 supports_condition_in_parens
742 | supports_conjunction
743 | supports_disjunction
747 SUPPORTS_NOT maybe_space supports_condition_in_parens {
752 supports_conjunction:
753 supports_condition_in_parens SUPPORTS_AND maybe_space supports_condition_in_parens {
756 | supports_conjunction SUPPORTS_AND maybe_space supports_condition_in_parens {
761 supports_disjunction:
762 supports_condition_in_parens SUPPORTS_OR maybe_space supports_condition_in_parens {
765 | supports_disjunction SUPPORTS_OR maybe_space supports_condition_in_parens {
770 supports_condition_in_parens:
771 '(' maybe_space supports_condition ')' maybe_space {
774 | supports_declaration_condition
778 supports_declaration_condition:
779 '(' maybe_space property ':' maybe_space expr prio ')' maybe_space {
781 CSSParser* p = static_cast<CSSParser*>(parser);
783 p->m_valueList = p->sinkFloatingValueList($6);
784 int oldParsedProperties = p->m_parsedProperties.size();
785 $$ = p->parseValue(static_cast<CSSPropertyID>($3), $7);
786 // We just need to know if the declaration is supported as it is written. Rollback any additions.
788 p->rollbackLastProperties(p->m_parsedProperties.size() - oldParsedProperties);
789 p->m_valueList = nullptr;
791 p->markPropertyEnd($7, false);
796 before_keyframes_rule:
798 parser->markRuleHeaderStart(CSSRuleSourceData::KEYFRAMES_RULE);
803 before_keyframes_rule WEBKIT_KEYFRAMES_SYM maybe_space keyframe_name at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space keyframes_rule closing_brace {
804 $$ = parser->createKeyframesRule($4, parser->sinkFloatingKeyframeVector($9));
814 /* empty */ { $$ = parser->createFloatingKeyframeVector(); }
815 | keyframes_rule keyframe_rule maybe_space {
823 key_list maybe_space '{' maybe_space declaration_list '}' {
824 $$ = parser->createKeyframe($1);
830 $$ = parser->createFloatingValueList();
831 $$->addValue(parser->sinkFloatingValue($1));
833 | key_list maybe_space ',' maybe_space key {
836 $$->addValue(parser->sinkFloatingValue($5));
841 maybe_unary_operator PERCENTAGE { $$.id = 0; $$.isInt = false; $$.fValue = $1 * $2; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
843 $$.id = 0; $$.isInt = false; $$.unit = CSSPrimitiveValue::CSS_NUMBER;
844 CSSParserString& str = $1;
845 if (str.equalIgnoringCase("from"))
847 else if (str.equalIgnoringCase("to"))
856 parser->markRuleHeaderStart(CSSRuleSourceData::PAGE_RULE);
861 before_page_rule PAGE_SYM maybe_space page_selector at_rule_header_end_maybe_space
862 '{' at_rule_body_start maybe_space_before_declaration declarations_and_margins closing_brace {
864 $$ = parser->createPageRule(parser->sinkFloatingSelector($4));
866 // Clear properties in the invalid @page rule.
867 parser->clearProperties();
868 // Also clear margin at-rules here once we fully implement margin at-rules parsing.
870 parser->popRuleData();
873 | before_page_rule PAGE_SYM error invalid_block {
874 parser->popRuleData();
877 | before_page_rule PAGE_SYM error ';' {
878 parser->popRuleData();
885 $$ = parser->createFloatingSelectorWithTagName(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
888 | IDENT pseudo_page {
891 $$->prependTagSelector(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
901 $$ = parser->createFloatingSelector();
906 declarations_and_margins:
908 | declarations_and_margins margin_box maybe_space declaration_list
913 parser->startDeclarationsForMarginBox();
914 } maybe_space '{' maybe_space declaration_list closing_brace {
915 $$ = parser->createMarginAtRule($1);
921 $$ = CSSSelector::TopLeftCornerMarginBox;
924 $$ = CSSSelector::TopLeftMarginBox;
927 $$ = CSSSelector::TopCenterMarginBox;
930 $$ = CSSSelector::TopRightMarginBox;
932 | TOPRIGHTCORNER_SYM {
933 $$ = CSSSelector::TopRightCornerMarginBox;
935 | BOTTOMLEFTCORNER_SYM {
936 $$ = CSSSelector::BottomLeftCornerMarginBox;
939 $$ = CSSSelector::BottomLeftMarginBox;
942 $$ = CSSSelector::BottomCenterMarginBox;
945 $$ = CSSSelector::BottomRightMarginBox;
947 | BOTTOMRIGHTCORNER_SYM {
948 $$ = CSSSelector::BottomRightCornerMarginBox;
951 $$ = CSSSelector::LeftTopMarginBox;
954 $$ = CSSSelector::LeftMiddleMarginBox;
957 $$ = CSSSelector::LeftBottomMarginBox;
960 $$ = CSSSelector::RightTopMarginBox;
963 $$ = CSSSelector::RightMiddleMarginBox;
966 $$ = CSSSelector::RightBottomMarginBox;
970 before_font_face_rule:
972 parser->markRuleHeaderStart(CSSRuleSourceData::FONT_FACE_RULE);
977 before_font_face_rule FONT_FACE_SYM at_rule_header_end_maybe_space
978 '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
979 $$ = parser->createFontFaceRule();
981 | before_font_face_rule FONT_FACE_SYM error invalid_block {
983 parser->popRuleData();
985 | before_font_face_rule FONT_FACE_SYM error ';' {
987 parser->popRuleData();
991 #if ENABLE_SHADOW_DOM
994 parser->markRuleHeaderStart(CSSRuleSourceData::HOST_RULE);
999 before_host_rule HOST_SYM at_rule_header_end_maybe_space
1000 '{' at_rule_body_start maybe_space block_rule_list save_block {
1001 $$ = parser->createHostRule($7);
1003 | before_host_rule HOST_SYM at_rule_header_end_maybe_space ';' {
1005 parser->popRuleData();
1010 #if ENABLE_CSS_DEVICE_ADAPTATION
1011 before_viewport_rule:
1013 parser->markViewportRuleBodyStart();
1014 parser->markRuleHeaderStart(CSSRuleSourceData::VIEWPORT_RULE);
1019 before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM at_rule_header_end_maybe_space
1020 '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
1021 $$ = parser->createViewportRule();
1022 parser->markViewportRuleBodyEnd();
1024 | before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM error invalid_block {
1026 parser->popRuleData();
1027 parser->markViewportRuleBodyEnd();
1029 | before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM error ';' {
1031 parser->popRuleData();
1032 parser->markViewportRuleBodyEnd();
1040 parser->setReusableRegionSelectorVector($1);
1041 $$ = parser->reusableRegionSelectorVector();
1050 parser->markRuleHeaderStart(CSSRuleSourceData::REGION_RULE);
1055 before_region_rule WEBKIT_REGION_RULE_SYM WHITESPACE region_selector at_rule_header_end '{' at_rule_body_start maybe_space region_block_rule_list save_block {
1057 $$ = parser->createRegionRule($4, $9);
1060 parser->popRuleData();
1065 #if ENABLE_CSS_SHADERS
1068 parser->markRuleHeaderStart(CSSRuleSourceData::FILTER_RULE);
1073 before_filter_rule WEBKIT_FILTER_RULE_SYM WHITESPACE IDENT at_rule_header_end_maybe_space
1074 '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
1075 $$ = parser->createFilterRule($4);
1081 '+' maybe_space { $$ = CSSSelector::DirectAdjacent; }
1082 | '~' maybe_space { $$ = CSSSelector::IndirectAdjacent; }
1083 | '>' maybe_space { $$ = CSSSelector::Child; }
1086 maybe_unary_operator:
1087 unary_operator { $$ = $1; }
1096 maybe_space_before_declaration:
1098 parser->markPropertyStart();
1102 before_selector_list:
1104 parser->markRuleHeaderStart(CSSRuleSourceData::STYLE_RULE);
1105 parser->markSelectorStart();
1111 parser->markRuleHeaderEnd();
1117 parser->markSelectorEnd();
1122 before_selector_list selector_list at_selector_end at_rule_header_end '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
1123 $$ = parser->createStyleRule($2);
1127 before_selector_group_item:
1129 parser->markSelectorStart();
1133 selector %prec UNIMPORTANT_TOK {
1135 $$ = parser->reusableSelectorVector();
1137 $$->append(parser->sinkFloatingSelector($1));
1138 parser->updateLastSelectorLineAndPosition();
1141 | selector_list at_selector_end ',' maybe_space before_selector_group_item selector %prec UNIMPORTANT_TOK {
1144 $$->append(parser->sinkFloatingSelector($6));
1145 parser->updateLastSelectorLineAndPosition();
1149 | selector_list error {
1154 selector_with_trailing_whitespace:
1155 selector WHITESPACE {
1164 | selector_with_trailing_whitespace
1168 | selector_with_trailing_whitespace simple_selector
1174 CSSParserSelector* end = $$;
1175 while (end->tagHistory())
1176 end = end->tagHistory();
1177 end->setRelation(CSSSelector::Descendant);
1178 end->setTagHistory(parser->sinkFloatingSelector($1));
1181 | selector combinator simple_selector {
1186 CSSParserSelector* end = $$;
1187 while (end->tagHistory())
1188 end = end->tagHistory();
1189 end->setRelation($2);
1190 end->setTagHistory(parser->sinkFloatingSelector($1));
1199 /* empty */ '|' { $$.clear(); }
1200 | '*' '|' { static LChar star = '*'; $$.init(&star, 1); }
1201 | IDENT '|' { $$ = $1; }
1206 $$ = parser->createFloatingSelectorWithTagName(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
1208 | element_name specifier_list {
1211 $$ = parser->rewriteSpecifiersWithElementName(nullAtom, $1, $$);
1216 $$ = parser->rewriteSpecifiersWithNamespaceIfNeeded($$);
1218 | namespace_selector element_name {
1219 $$ = parser->createFloatingSelectorWithTagName(parser->determineNameInNamespace($1, $2));
1221 | namespace_selector element_name specifier_list {
1224 $$ = parser->rewriteSpecifiersWithElementName($1, $2, $$);
1226 | namespace_selector specifier_list {
1229 $$ = parser->rewriteSpecifiersWithElementName($1, starAtom, $$);
1233 simple_selector_list:
1234 simple_selector %prec UNIMPORTANT_TOK {
1236 $$ = parser->createFloatingSelectorVector();
1237 $$->append(parser->sinkFloatingSelector($1));
1241 | simple_selector_list maybe_space ',' maybe_space simple_selector %prec UNIMPORTANT_TOK {
1244 $$->append(parser->sinkFloatingSelector($5));
1248 | simple_selector_list error {
1255 CSSParserString& str = $1;
1256 if (parser->m_context.isHTMLDocument)
1261 static LChar star = '*';
1270 | specifier_list specifier {
1274 $$ = parser->rewriteSpecifiers($1, $2);
1276 | specifier_list error {
1283 $$ = parser->createFloatingSelector();
1284 $$->setMatch(CSSSelector::Id);
1285 if (parser->m_context.mode == CSSQuirksMode)
1290 if ($1[0] >= '0' && $1[0] <= '9') {
1293 $$ = parser->createFloatingSelector();
1294 $$->setMatch(CSSSelector::Id);
1295 if (parser->m_context.mode == CSSQuirksMode)
1307 $$ = parser->createFloatingSelector();
1308 $$->setMatch(CSSSelector::Class);
1309 if (parser->m_context.mode == CSSQuirksMode)
1317 CSSParserString& str = $1;
1318 if (parser->m_context.isHTMLDocument)
1325 '[' maybe_space attr_name ']' {
1326 $$ = parser->createFloatingSelector();
1327 $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
1328 $$->setMatch(CSSSelector::Set);
1330 | '[' maybe_space attr_name match maybe_space ident_or_string maybe_space ']' {
1331 $$ = parser->createFloatingSelector();
1332 $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
1333 $$->setMatch((CSSSelector::Match)$4);
1336 | '[' maybe_space namespace_selector attr_name ']' {
1337 $$ = parser->createFloatingSelector();
1338 $$->setAttribute(parser->determineNameInNamespace($3, $4));
1339 $$->setMatch(CSSSelector::Set);
1341 | '[' maybe_space namespace_selector attr_name match maybe_space ident_or_string maybe_space ']' {
1342 $$ = parser->createFloatingSelector();
1343 $$->setAttribute(parser->determineNameInNamespace($3, $4));
1344 $$->setMatch((CSSSelector::Match)$5);
1351 $$ = CSSSelector::Exact;
1354 $$ = CSSSelector::List;
1357 $$ = CSSSelector::Hyphen;
1360 $$ = CSSSelector::Begin;
1363 $$ = CSSSelector::End;
1366 $$ = CSSSelector::Contain;
1377 $$ = parser->createFloatingSelector();
1378 $$->setMatch(CSSSelector::PagePseudoClass);
1381 CSSSelector::PseudoType type = $$->pseudoType();
1382 if (type == CSSSelector::PseudoUnknown)
1388 $$ = parser->createFloatingSelector();
1389 $$->setMatch(CSSSelector::PseudoClass);
1392 CSSSelector::PseudoType type = $$->pseudoType();
1393 if (type == CSSSelector::PseudoUnknown)
1397 $$ = parser->createFloatingSelector();
1398 $$->setMatch(CSSSelector::PseudoElement);
1401 // FIXME: This call is needed to force selector to compute the pseudoType early enough.
1402 CSSSelector::PseudoType type = $$->pseudoType();
1403 if (type == CSSSelector::PseudoUnknown)
1406 #if ENABLE_VIDEO_TRACK
1407 // used by ::cue(:past/:future)
1408 | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space ')' {
1410 $$ = parser->createFloatingSelector();
1411 $$->setMatch(CSSSelector::PseudoClass);
1412 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($5));
1414 CSSSelector::PseudoType type = $$->pseudoType();
1415 if (type != CSSSelector::PseudoCue)
1421 #if ENABLE_SHADOW_DOM
1422 | ':' ':' DISTRIBUTEDFUNCTION maybe_space selector maybe_space ')' {
1426 $$ = parser->createFloatingSelector();
1427 $$->setMatch(CSSSelector::PseudoElement);
1428 $$->setFunctionArgumentSelector($5);
1434 // use by :-webkit-any.
1435 // FIXME: should we support generic selectors here or just simple_selectors?
1436 // Use simple_selector_list for now to match -moz-any.
1437 // See http://lists.w3.org/Archives/Public/www-style/2010Sep/0566.html for some
1438 // related discussion with respect to :not.
1439 | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space ')' {
1441 $$ = parser->createFloatingSelector();
1442 $$->setMatch(CSSSelector::PseudoClass);
1443 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
1446 CSSSelector::PseudoType type = $$->pseudoType();
1447 if (type != CSSSelector::PseudoAny)
1452 // used by :nth-*(ax+b)
1453 | ':' FUNCTION maybe_space NTH maybe_space ')' {
1454 $$ = parser->createFloatingSelector();
1455 $$->setMatch(CSSSelector::PseudoClass);
1456 $$->setArgument($4);
1458 CSSSelector::PseudoType type = $$->pseudoType();
1459 if (type == CSSSelector::PseudoUnknown)
1463 | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space ')' {
1464 $$ = parser->createFloatingSelector();
1465 $$->setMatch(CSSSelector::PseudoClass);
1466 $$->setArgument(String::number($4 * $5));
1468 CSSSelector::PseudoType type = $$->pseudoType();
1469 if (type == CSSSelector::PseudoUnknown)
1472 // used by :nth-*(odd/even) and :lang
1473 | ':' FUNCTION maybe_space IDENT maybe_space ')' {
1474 $$ = parser->createFloatingSelector();
1475 $$->setMatch(CSSSelector::PseudoClass);
1476 $$->setArgument($4);
1479 CSSSelector::PseudoType type = $$->pseudoType();
1480 if (type == CSSSelector::PseudoUnknown)
1482 else if (type == CSSSelector::PseudoNthChild ||
1483 type == CSSSelector::PseudoNthOfType ||
1484 type == CSSSelector::PseudoNthLastChild ||
1485 type == CSSSelector::PseudoNthLastOfType) {
1486 if (!isValidNthToken($4))
1491 | ':' NOTFUNCTION maybe_space simple_selector maybe_space ')' {
1492 if (!$4 || !$4->isSimple())
1495 $$ = parser->createFloatingSelector();
1496 $$->setMatch(CSSSelector::PseudoClass);
1498 Vector<OwnPtr<CSSParserSelector> > selectorVector;
1499 selectorVector.append(parser->sinkFloatingSelector($4));
1500 $$->adoptSelectorVector(selectorVector);
1512 | decl_list declaration {
1520 | error invalid_block_list error {
1529 | decl_list invalid_block_list {
1535 declaration ';' maybe_space {
1536 parser->markPropertyStart();
1539 | declaration invalid_block_list maybe_space {
1542 | declaration invalid_block_list ';' maybe_space {
1545 | error ';' maybe_space {
1546 parser->markPropertyStart();
1549 | error invalid_block_list error ';' maybe_space {
1552 | decl_list declaration ';' maybe_space {
1553 parser->markPropertyStart();
1558 | decl_list error ';' maybe_space {
1559 parser->markPropertyStart();
1562 | decl_list error invalid_block_list error ';' maybe_space {
1563 parser->markPropertyStart();
1569 VAR_DEFINITION ':' maybe_space expr prio {
1570 #if ENABLE_CSS_VARIABLES
1571 parser->storeVariableDeclaration($1, parser->sinkFloatingValueList($4), $5);
1573 parser->markPropertyEnd($5, true);
1579 property ':' maybe_space expr prio {
1581 bool isPropertyParsed = false;
1583 parser->m_valueList = parser->sinkFloatingValueList($4);
1584 int oldParsedProperties = parser->m_parsedProperties.size();
1585 $$ = parser->parseValue(static_cast<CSSPropertyID>($1), $5);
1587 parser->rollbackLastProperties(parser->m_parsedProperties.size() - oldParsedProperties);
1589 isPropertyParsed = true;
1590 parser->m_valueList = nullptr;
1592 parser->markPropertyEnd($5, isPropertyParsed);
1599 property ':' maybe_space error expr prio {
1600 /* The default movable type template has letter-spacing: .none; Handle this by looking for
1601 error tokens at the start of an expr, recover the expr and then treat as an error, cleaning
1602 up and deleting the shifted expr. */
1603 parser->markPropertyEnd(false, false);
1607 property ':' maybe_space expr prio error {
1608 /* When we encounter something like p {color: red !important fail;} we should drop the declaration */
1609 parser->markPropertyEnd(false, false);
1613 IMPORTANT_SYM maybe_space {
1614 /* Handle this case: div { text-align: center; !important } Just reduce away the stray !important. */
1618 property ':' maybe_space {
1619 /* div { font-family: } Just reduce away this property with no value. */
1620 parser->markPropertyEnd(false, false);
1624 property ':' maybe_space error {
1625 /* if we come across rules with invalid values like this case: p { weight: *; }, just discard the rule */
1626 parser->markPropertyEnd(false, false);
1630 property invalid_block {
1631 /* if we come across: div { color{;color:maroon} }, ignore everything within curly brackets */
1638 $$ = cssPropertyID($1);
1643 IMPORTANT_SYM maybe_space { $$ = true; }
1644 | /* empty */ { $$ = false; }
1649 $$ = parser->createFloatingValueList();
1650 $$->addValue(parser->sinkFloatingValue($1));
1652 | expr operator term {
1658 v.unit = CSSParserValue::Operator;
1662 $$->addValue(parser->sinkFloatingValue($3));
1665 | expr invalid_block_list {
1668 | expr invalid_block_list error {
1689 unary_term { $$ = $1; }
1690 | unary_operator unary_term { $$ = $2; $$.fValue *= $1; }
1691 | STRING maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_STRING; }
1692 | IDENT maybe_space {
1693 $$.id = cssValueKeywordID($1);
1694 $$.unit = CSSPrimitiveValue::CSS_IDENT;
1697 /* We might need to actually parse the number from a dimension, but we can't just put something that uses $$.string into unary_term. */
1698 | DIMEN maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_DIMENSION; }
1699 | unary_operator DIMEN maybe_space { $$.id = 0; $$.string = $2; $$.unit = CSSPrimitiveValue::CSS_DIMENSION; }
1700 | URI maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_URI; }
1701 | UNICODERANGE maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_UNICODE_RANGE; }
1702 | HEX maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; }
1703 | '#' maybe_space { $$.id = 0; $$.string = CSSParserString(); $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; } /* Handle error case: "color: #;" */
1704 | VARFUNCTION maybe_space IDENT ')' maybe_space {
1705 #if ENABLE_CSS_VARIABLES
1708 $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
1711 /* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
1718 | min_or_max_function {
1721 | '%' maybe_space { /* Handle width: %; */
1722 $$.id = 0; $$.unit = 0;
1727 INTEGER maybe_space { $$.id = 0; $$.isInt = true; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
1728 | FLOATTOKEN maybe_space { $$.id = 0; $$.isInt = false; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
1729 | PERCENTAGE maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PERCENTAGE; }
1730 | PXS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PX; }
1731 | CMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CM; }
1732 | MMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_MM; }
1733 | INS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_IN; }
1734 | PTS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PT; }
1735 | PCS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PC; }
1736 | DEGS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DEG; }
1737 | RADS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_RAD; }
1738 | GRADS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_GRAD; }
1739 | TURNS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_TURN; }
1740 | MSECS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_MS; }
1741 | SECS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_S; }
1742 | HERTZ maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_HZ; }
1743 | KHERTZ maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_KHZ; }
1744 | EMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EMS; }
1745 | QEMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSParserValue::Q_EMS; }
1746 | EXS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EXS; }
1747 | REMS maybe_space {
1750 $$.unit = CSSPrimitiveValue::CSS_REMS;
1751 if (parser->m_styleSheet)
1752 parser->m_styleSheet->parserSetUsesRemUnits(true);
1754 | VW maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VW; }
1755 | VH maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VH; }
1756 | VMIN maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VMIN; }
1757 | VMAX maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VMAX; }
1758 | DPPX maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPPX; }
1759 | DPI maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPI; }
1760 | DPCM maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPCM; }
1764 FUNCTION maybe_space expr ')' maybe_space {
1765 CSSParserFunction* f = parser->createFloatingFunction();
1767 f->args = parser->sinkFloatingValueList($3);
1769 $$.unit = CSSParserValue::Function;
1772 FUNCTION maybe_space expr TOKEN_EOF {
1773 CSSParserFunction* f = parser->createFloatingFunction();
1775 f->args = parser->sinkFloatingValueList($3);
1777 $$.unit = CSSParserValue::Function;
1780 FUNCTION maybe_space ')' maybe_space {
1781 CSSParserFunction* f = parser->createFloatingFunction();
1783 CSSParserValueList* valueList = parser->createFloatingValueList();
1784 f->args = parser->sinkFloatingValueList(valueList);
1786 $$.unit = CSSParserValue::Function;
1789 FUNCTION maybe_space error {
1790 CSSParserFunction* f = parser->createFloatingFunction();
1794 $$.unit = CSSParserValue::Function;
1800 unary_term { $$ = $1; }
1801 | VARFUNCTION maybe_space IDENT ')' maybe_space {
1802 #if ENABLE_CSS_VARIABLES
1805 $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
1808 | unary_operator unary_term { $$ = $2; $$.fValue *= $1; }
1826 calc_func_paren_expr:
1827 '(' maybe_space calc_func_expr maybe_space ')' maybe_space {
1832 v.unit = CSSParserValue::Operator;
1834 $$->insertValueAt(0, v);
1842 calc_func_term maybe_space {
1843 $$ = parser->createFloatingValueList();
1844 $$->addValue(parser->sinkFloatingValue($1));
1846 | calc_func_expr calc_func_operator calc_func_term {
1851 v.unit = CSSParserValue::Operator;
1854 $$->addValue(parser->sinkFloatingValue($3));
1859 | calc_func_expr calc_func_operator calc_func_paren_expr {
1860 if ($1 && $2 && $3) {
1864 v.unit = CSSParserValue::Operator;
1871 | calc_func_paren_expr
1872 | calc_func_expr error {
1877 calc_func_expr_list:
1881 | calc_func_expr_list ',' maybe_space calc_func_expr {
1886 v.unit = CSSParserValue::Operator;
1896 CALCFUNCTION maybe_space calc_func_expr ')' maybe_space {
1897 CSSParserFunction* f = parser->createFloatingFunction();
1899 f->args = parser->sinkFloatingValueList($3);
1901 $$.unit = CSSParserValue::Function;
1904 | CALCFUNCTION maybe_space error {
1919 min_or_max_function:
1920 min_or_max maybe_space calc_func_expr_list ')' maybe_space {
1921 CSSParserFunction* f = parser->createFloatingFunction();
1923 f->args = parser->sinkFloatingValueList($3);
1925 $$.unit = CSSParserValue::Function;
1928 | min_or_max maybe_space error {
1933 /* error handling rules */
1939 | error closing_brace {
1945 ATKEYWORD error invalid_block {
1948 | ATKEYWORD error ';' {
1954 error invalid_block {
1959 Seems like the two rules below are trying too much and violating
1960 http://www.hixie.ch/tests/evil/mixed/csserrorhandling.html
1972 '{' error invalid_block_list error closing_brace {
1973 parser->invalidBlockHit();
1975 | '{' error closing_brace {
1976 parser->invalidBlockHit();
1982 | invalid_block_list error invalid_block