From 32221bc146be61fba1296c58ed072cdf84b4de6f Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Mon, 18 Feb 2019 00:40:20 +0000 Subject: Parse: fix handling of EOF --- src/parse/parse.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/parse/parse.c b/src/parse/parse.c index afc6d72..def9895 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -927,21 +927,19 @@ css_error parseRuleset(css_parser *parser) if (error != CSS_OK) return error; - if (token->type == CSS_TOKEN_EOF) { + if (token->type != CSS_TOKEN_CHAR || + lwc_string_length(token->idata) != 1 || + lwc_string_data(token->idata)[0] != '{') { + /* FOLLOW(selector) contains only '{', but we may + * also have seen EOF, which is a parse error. */ error = pushBack(parser, token); if (error != CSS_OK) return error; + parser->parseError = true; return done(parser); } - if (token->type != CSS_TOKEN_CHAR || - lwc_string_length(token->idata) != 1 || - lwc_string_data(token->idata)[0] != '{') { - /* This should never happen, as FOLLOW(selector) - * contains only '{' */ - assert(0 && "Expected {"); - } state->substate = WS; /* Fall through */ @@ -1961,6 +1959,9 @@ css_error parseAny1(css_parser *parser) if (error != CSS_OK) return error; + if (token->type == CSS_TOKEN_EOF) + return done(parser); + /* Grammar ambiguity: any0 can be followed by * '{', ';', ')', ']'. any1 can only be followed by '{'. */ if (token->type == CSS_TOKEN_CHAR && @@ -2080,6 +2081,17 @@ css_error parseAny(css_parser *parser) if (error != CSS_OK) return error; + if (token->type == CSS_TOKEN_EOF) { + error = pushBack(parser, token); + if (error != CSS_OK) + return error; + + /* parse error */ + parser->parseError = true; + + return done(parser); + } + /* Match correct close bracket (grammar ambiguity) */ if (token->type == CSS_TOKEN_CHAR && lwc_string_length(token->idata) == 1 && -- cgit v1.2.3