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

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

Issue 14897004: Skipping {}, () and [] blocks while error recovering in CSS. (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
Index: Source/core/css/CSSGrammar.y.in
diff --git a/Source/core/css/CSSGrammar.y.in b/Source/core/css/CSSGrammar.y.in
index f9cd738e00f12c95fb974a0efce3b85bccd5d959..b55f6c061917bc1db825075a8ca76b73ecaa0b3a 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 33
+%expect 32
%nonassoc LOWEST_PREC
@@ -300,12 +300,14 @@ 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
%type <value> calc_func_term
%type <character> calc_func_operator
%type <valueList> calc_func_expr
+%type <valueList> valid_calc_func_expr
%type <valueList> calc_func_expr_list
%type <valueList> calc_func_paren_expr
%type <value> calc_function
@@ -1618,11 +1620,16 @@ prio:
;
expr:
+ valid_expr
+ | 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) {
@@ -1635,9 +1642,6 @@ expr:
$$->addValue(parser->sinkFloatingValue($3));
}
}
- | expr expr_recovery {
- $$ = 0;
- }
;
expr_recovery:
@@ -1678,13 +1682,13 @@ term:
$$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
}
/* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
- | function {
+ | function maybe_space {
$$ = $1;
}
- | calc_function {
+ | calc_function maybe_space {
$$ = $1;
}
- | min_or_max_function {
+ | min_or_max_function maybe_space {
$$ = $1;
}
| '%' maybe_space { /* Handle width: %; */
@@ -1732,7 +1736,7 @@ unary_term:
;
function:
- FUNCTION maybe_space expr closing_parenthesis maybe_space {
+ FUNCTION maybe_space expr closing_parenthesis {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = parser->sinkFloatingValueList($3);
@@ -1740,7 +1744,7 @@ function:
$$.unit = CSSParserValue::Function;
$$.function = f;
} |
- FUNCTION maybe_space closing_parenthesis maybe_space {
+ FUNCTION maybe_space closing_parenthesis {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
CSSParserValueList* valueList = parser->createFloatingValueList();
@@ -1749,7 +1753,7 @@ function:
$$.unit = CSSParserValue::Function;
$$.function = f;
} |
- FUNCTION maybe_space error {
+ FUNCTION maybe_space expr_recovery closing_parenthesis {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = nullptr;
@@ -1806,6 +1810,11 @@ calc_func_paren_expr:
;
calc_func_expr:
+ valid_calc_func_expr
+ | valid_calc_func_expr expr_recovery { $$ = 0; }
+ ;
+
+valid_calc_func_expr:
calc_func_term {
$$ = parser->createFloatingValueList();
$$->addValue(parser->sinkFloatingValue($1));
@@ -1836,9 +1845,6 @@ calc_func_expr:
$$ = 0;
}
| calc_func_paren_expr
- | calc_func_expr error {
- $$ = 0;
- }
;
calc_func_expr_list:
@@ -1860,7 +1866,7 @@ calc_func_expr_list:
;
calc_function:
- CALCFUNCTION maybe_space calc_func_expr calc_maybe_space ')' maybe_space {
+ CALCFUNCTION maybe_space calc_func_expr calc_maybe_space ')' {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = parser->sinkFloatingValueList($3);
@@ -1868,7 +1874,7 @@ calc_function:
$$.unit = CSSParserValue::Function;
$$.function = f;
}
- | CALCFUNCTION maybe_space error {
+ | CALCFUNCTION maybe_space expr_recovery closing_parenthesis {
YYERROR;
}
;
@@ -1884,7 +1890,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 ')' {
CSSParserFunction* f = parser->createFloatingFunction();
f->name = $1;
f->args = parser->sinkFloatingValueList($3);
@@ -1892,7 +1898,7 @@ min_or_max_function:
$$.unit = CSSParserValue::Function;
$$.function = f;
}
- | min_or_max maybe_space error {
+ | min_or_max maybe_space expr_recovery closing_parenthesis {
YYERROR;
}
;
@@ -1956,8 +1962,18 @@ error_location: {
error_recovery:
/* empty */
- | error_recovery invalid_block
| error_recovery error
+ | error_recovery '{' error_recovery closing_brace { parser->invalidBlockHit(); }
+ | error_recovery '[' error_recovery ']'
+ | error_recovery '[' error_recovery TOKEN_EOF
+ | 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
;
%%

Powered by Google App Engine
This is Rietveld 408576698