Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Unified Diff: Source/core/css/CSSGrammar.y.in

Issue 14926003: Taking parentheses into account while CSS error recovering. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSGrammar.y.in
diff --git a/Source/core/css/CSSGrammar.y.in b/Source/core/css/CSSGrammar.y.in
index 20860de7ce6e4c380e738dea75e7e8f86bd61db5..4e74510bd30af4d1c30d4976a529e79b9f7cc009 100644
--- a/Source/core/css/CSSGrammar.y.in
+++ b/Source/core/css/CSSGrammar.y.in
@@ -87,7 +87,7 @@ static inline bool isCSSTokenAString(int yytype)
%}
-%expect 35
+%expect 34
%nonassoc LOWEST_PREC
@@ -300,6 +300,7 @@ static inline bool isCSSTokenAString(int yytype)
%type <character> operator
%type <valueList> expr
+%type <valueList> valid_expr
%type <value> term
%type <value> unary_term
%type <value> function
@@ -331,25 +332,25 @@ stylesheet:
;
internal_rule:
- INTERNAL_RULE_SYM '{' maybe_space valid_rule maybe_space '}' {
+ INTERNAL_RULE_SYM '{' maybe_space valid_rule maybe_space closing_brace {
parser->m_rule = $4;
}
;
webkit_keyframe_rule:
- WEBKIT_KEYFRAME_RULE_SYM '{' maybe_space keyframe_rule maybe_space '}' {
+ WEBKIT_KEYFRAME_RULE_SYM '{' maybe_space keyframe_rule maybe_space closing_brace{
parser->m_keyframe = $4;
}
;
internal_decls:
- INTERNAL_DECLS_SYM '{' maybe_space_before_declaration declaration_list '}' {
+ INTERNAL_DECLS_SYM '{' maybe_space_before_declaration declaration_list closing_brace {
/* can be empty */
}
;
internal_value:
- INTERNAL_VALUE_SYM '{' maybe_space expr '}' {
+ INTERNAL_VALUE_SYM '{' maybe_space expr closing_brace {
if ($4) {
parser->m_valueList = parser->sinkFloatingValueList($4);
int oldParsedProperties = parser->m_parsedProperties.size();
@@ -361,13 +362,13 @@ internal_value:
;
webkit_mediaquery:
- WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query '}' {
+ WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query closing_brace {
parser->m_mediaQuery = parser->sinkFloatingMediaQuery($4);
}
;
internal_selector:
- INTERNAL_SELECTOR_SYM '{' maybe_space selector_list '}' {
+ INTERNAL_SELECTOR_SYM '{' maybe_space selector_list closing_brace {
if ($4) {
if (parser->m_selectorListForParseSelector)
parser->m_selectorListForParseSelector->adoptSelectorVector(*$4);
@@ -376,7 +377,7 @@ internal_selector:
;
webkit_supports_condition:
- WEBKIT_SUPPORTS_CONDITION_SYM '{' maybe_space supports_condition '}' {
+ WEBKIT_SUPPORTS_CONDITION_SYM '{' maybe_space supports_condition closing_brace {
parser->m_supportsCondition = $4;
}
;
@@ -403,6 +404,11 @@ closing_brace:
| %prec LOWEST_PREC TOKEN_EOF
;
+closing_parenthesis:
+ ')'
+ | %prec LOWEST_PREC TOKEN_EOF
+ ;
+
charset:
CHARSET_SYM maybe_space STRING maybe_space ';' {
if (parser->m_styleSheet)
@@ -582,7 +588,7 @@ maybe_media_value:
;
media_query_exp:
- maybe_media_restrictor maybe_space '(' maybe_space media_feature maybe_space maybe_media_value ')' maybe_space {
+ maybe_media_restrictor maybe_space '(' maybe_space media_feature maybe_space maybe_media_value closing_parenthesis maybe_space {
// If restrictor is specified, media query expression is invalid.
// Create empty media query expression and continue parsing media query.
if ($1 != MediaQuery::None)
@@ -763,17 +769,17 @@ supports_disjunction:
;
supports_condition_in_parens:
- '(' maybe_space supports_condition ')' maybe_space {
+ '(' maybe_space supports_condition closing_parenthesis maybe_space {
$$ = $3;
}
| supports_declaration_condition
- | '(' error ')' {
+ | '(' error closing_parenthesis {
$$ = false;
}
;
supports_declaration_condition:
- '(' maybe_space property ':' maybe_space expr prio ')' maybe_space {
+ '(' maybe_space property ':' maybe_space expr prio closing_parenthesis maybe_space {
$$ = false;
CSSParser* p = static_cast<CSSParser*>(parser);
if ($3 && $6) {
@@ -816,7 +822,7 @@ keyframes_rule:
;
keyframe_rule:
- key_list maybe_space '{' maybe_space declaration_list '}' {
+ key_list maybe_space '{' maybe_space declaration_list closing_brace {
$$ = parser->createKeyframe($1);
}
;
@@ -1403,7 +1409,7 @@ pseudo:
$$ = 0;
}
// used by ::cue(:past/:future)
- | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space ')' {
+ | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space closing_parenthesis {
if ($5) {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
@@ -1415,7 +1421,7 @@ pseudo:
} else
$$ = 0;
}
- | ':' ':' DISTRIBUTEDFUNCTION maybe_space selector maybe_space ')' {
+ | ':' ':' DISTRIBUTEDFUNCTION maybe_space selector maybe_space closing_parenthesis {
if (!$5)
$$ = 0;
else {
@@ -1431,7 +1437,7 @@ pseudo:
// Use simple_selector_list for now to match -moz-any.
// See http://lists.w3.org/Archives/Public/www-style/2010Sep/0566.html for some
// related discussion with respect to :not.
- | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space ')' {
+ | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space closing_parenthesis {
if ($4) {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
@@ -1445,7 +1451,7 @@ pseudo:
$$ = 0;
}
// used by :nth-*(ax+b)
- | ':' FUNCTION maybe_space NTH maybe_space ')' {
+ | ':' FUNCTION maybe_space NTH maybe_space closing_parenthesis {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
$$->setArgument($4);
@@ -1455,7 +1461,7 @@ pseudo:
$$ = 0;
}
// used by :nth-*
- | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space ')' {
+ | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space closing_parenthesis {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
$$->setArgument(String::number($4 * $5));
@@ -1465,7 +1471,7 @@ pseudo:
$$ = 0;
}
// used by :nth-*(odd/even) and :lang
- | ':' FUNCTION maybe_space IDENT maybe_space ')' {
+ | ':' FUNCTION maybe_space IDENT maybe_space closing_parenthesis {
$$ = parser->createFloatingSelector();
$$->setMatch(CSSSelector::PseudoClass);
$$->setArgument($4);
@@ -1483,7 +1489,7 @@ pseudo:
}
}
// used by :not
- | ':' NOTFUNCTION maybe_space simple_selector maybe_space ')' {
+ | ':' NOTFUNCTION maybe_space simple_selector maybe_space closing_parenthesis {
if (!$4 || !$4->isSimple())
$$ = 0;
else {
@@ -1543,11 +1549,9 @@ decl_list:
;
decl_list_recovery:
- error error_location {
+ error error_location error_recovery {
parser->syntaxError($2, CSSParser::PropertyDeclarationError);
}
- | decl_list_recovery invalid_block
- | decl_list_recovery error
;
declaration:
@@ -1598,11 +1602,9 @@ declaration:
;
declaration_recovery:
- error error_location {
+ error error_location error_recovery {
parser->syntaxError($2);
}
- | declaration_recovery invalid_block
- | declaration_recovery error
;
property:
@@ -1617,11 +1619,20 @@ prio:
;
expr:
+ valid_expr {
+ $$ = $1;
+ }
+ | valid_expr expr_recovery {
+ $$ = 0;
+ }
+ ;
+
+valid_expr:
term {
$$ = parser->createFloatingValueList();
$$->addValue(parser->sinkFloatingValue($1));
}
- | expr operator term {
+ | valid_expr operator term {
$$ = $1;
if ($$) {
if ($2) {
@@ -1634,15 +1645,10 @@ expr:
$$->addValue(parser->sinkFloatingValue($3));
}
}
- | expr invalid_block_list {
- $$ = 0;
- }
- | expr invalid_block_list error {
- $$ = 0;
- }
- | expr error {
- $$ = 0;
- }
+ ;
+
+expr_recovery:
+ error error_location error_recovery
;
operator:
@@ -1673,7 +1679,7 @@ term:
| UNICODERANGE maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_UNICODE_RANGE; }
| HEX maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; }
| '#' maybe_space { $$.id = 0; $$.string = CSSParserString(); $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; } /* Handle error case: "color: #;" */
- | VARFUNCTION maybe_space IDENT ')' maybe_space {
+ | VARFUNCTION maybe_space IDENT closing_parenthesis maybe_space {
$$.id = 0;
$$.string = $3;
$$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
@@ -1733,15 +1739,7 @@ unary_term:
;
function:
- FUNCTION maybe_space expr ')' maybe_space {
- CSSParserFunction* f = parser->createFloatingFunction();
- f->name = $1;
- f->args = parser->sinkFloatingValueList($3);
- $$.id = 0;
- $$.unit = CSSParserValue::Function;
- $$.function = f;
- } |
- FUNCTION maybe_space expr TOKEN_EOF {
+ FUNCTION maybe_space expr closing_parenthesis maybe_space {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = parser->sinkFloatingValueList($3);
@@ -1749,7 +1747,7 @@ function:
$$.unit = CSSParserValue::Function;
$$.function = f;
} |
- FUNCTION maybe_space ')' maybe_space {
+ FUNCTION maybe_space closing_parenthesis maybe_space {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
CSSParserValueList* valueList = parser->createFloatingValueList();
@@ -1758,7 +1756,7 @@ function:
$$.unit = CSSParserValue::Function;
$$.function = f;
} |
- FUNCTION maybe_space error {
+ FUNCTION maybe_space expr_recovery closing_parenthesis maybe_space {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = nullptr;
@@ -1767,10 +1765,10 @@ function:
$$.function = f;
}
;
-
+
calc_func_term:
unary_term { $$ = $1; }
- | VARFUNCTION maybe_space IDENT ')' {
+ | VARFUNCTION maybe_space IDENT closing_parenthesis {
$$.id = 0;
$$.string = $3;
$$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
@@ -1815,8 +1813,8 @@ calc_func_paren_expr:
}
calc_closing_paren:
- WHITESPACE ')'
- | ')'
+ WHITESPACE closing_parenthesis
+ | closing_parenthesis
calc_func_expr:
calc_func_term {
@@ -1912,7 +1910,7 @@ min_or_max:
;
min_or_max_function:
- min_or_max maybe_space calc_func_expr_list ')' maybe_space {
+ min_or_max maybe_space calc_func_expr_list closing_parenthesis maybe_space {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = parser->sinkFloatingValueList($3);
@@ -1982,5 +1980,19 @@ error_location: {
}
;
+error_recovery:
+ /* empty */
+ | error_recovery error
+ | error_recovery '{' error_recovery closing_brace
+ | error_recovery '(' error_recovery closing_parenthesis
+ | error_recovery FUNCTION error_recovery closing_parenthesis
+ | error_recovery CALCFUNCTION error_recovery closing_parenthesis
+ | error_recovery VARFUNCTION error_recovery closing_parenthesis
+ | error_recovery MINFUNCTION error_recovery closing_parenthesis
+ | error_recovery MAXFUNCTION error_recovery closing_parenthesis
+ | error_recovery ANYFUNCTION error_recovery closing_parenthesis
+ | error_recovery NOTFUNCTION error_recovery closing_parenthesis
+ ;
+
%%
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698