From: Dale Weiler Date: Wed, 30 Jan 2013 05:51:28 +0000 (+0000) Subject: Fix pragma parsing that I broke. X-Git-Tag: before-library~192 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9f5f2b6d745648d1f70d0889a3d3c2c7e15bf61e;p=xonotic%2Fgmqcc.git Fix pragma parsing that I broke. --- diff --git a/parser.c b/parser.c index 5b1e011..1bdddf3 100644 --- a/parser.c +++ b/parser.c @@ -3292,8 +3292,15 @@ static bool parse_eol(parser_t *parser) return parser->tok == TOKEN_EOL; } - -static bool parse_pragma_do(parser_t *parser) { +static bool parse_pragma_do(parser_t *parser) +{ + if (!parser_next(parser) || + parser->tok != TOKEN_IDENT || + strcmp(parser_tokval(parser), "pragma")) + { + parseerror(parser, "expected `pragma` keyword after `#`, got `%s`", parser_tokval(parser)); + return false; + } if (!parse_skipwhite(parser) || parser->tok != TOKEN_IDENT) { parseerror(parser, "expected pragma, got `%s`", parser_tokval(parser)); return false; @@ -3304,37 +3311,33 @@ static bool parse_pragma_do(parser_t *parser) { parseerror(parser, "`noref` pragma requires an argument: 0 or 1"); return false; } - parser->noref = !!parser_token(parser)->constval.i; - if (!parse_eol(parser)) { parseerror(parser, "parse error after `noref` pragma"); return false; } - } else { + } + else + { (void)!parsewarning(parser, WARN_UNKNOWN_PRAGMAS, "ignoring #pragma %s", parser_tokval(parser)); return false; } + return true; } - static bool parse_pragma(parser_t *parser) { bool rv; - parser->lex->flags.preprocessing = true; - parser->lex->flags.mergelines = true; - + parser->lex->flags.mergelines = true; rv = parse_pragma_do(parser); - if (parser->tok != TOKEN_EOL) { parseerror(parser, "junk after pragma"); rv = false; } parser->lex->flags.preprocessing = false; - parser->lex->flags.mergelines = false; - + parser->lex->flags.mergelines = false; if (!parser_next(parser)) { parseerror(parser, "parse error after pragma"); rv = false;