From: Wolfgang (Blub) Bumiller Date: Tue, 13 Nov 2012 17:54:25 +0000 (+0100) Subject: if not() support X-Git-Tag: 0.1~24 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e7d558dbd867816d64267ac090a4d6daef46bc46;p=xonotic%2Fgmqcc.git if not() support --- diff --git a/parser.c b/parser.c index f548e22..0f0d52e 100644 --- a/parser.c +++ b/parser.c @@ -1418,11 +1418,23 @@ static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out) { ast_ifthen *ifthen; ast_expression *cond, *ontrue, *onfalse = NULL; + bool ifnot = false; lex_ctx ctx = parser_ctx(parser); - /* skip the 'if' and check for opening paren */ - if (!parser_next(parser) || parser->tok != '(') { + /* skip the 'if', parse an optional 'not' and check for an opening paren */ + if (!parser_next(parser)) { + parseerror(parser, "expected condition or 'not'"); + return false; + } + if (parser->tok == TOKEN_KEYWORD && !strcmp(parser_tokval(parser), "not")) { + ifnot = true; + if (!parser_next(parser)) { + parseerror(parser, "expected condition in parenthesis"); + return false; + } + } + if (parser->tok != '(') { parseerror(parser, "expected 'if' condition in parenthesis"); return false; } @@ -1469,7 +1481,10 @@ static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out) } } - ifthen = ast_ifthen_new(ctx, cond, ontrue, onfalse); + if (ifnot) + ifthen = ast_ifthen_new(ctx, cond, onfalse, ontrue); + else + ifthen = ast_ifthen_new(ctx, cond, ontrue, onfalse); *out = (ast_expression*)ifthen; return true; }