mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 12:00:38 +00:00
if not() support
This commit is contained in:
parent
8f1f6160e3
commit
f3ebbf598f
1 changed files with 18 additions and 3 deletions
19
parser.c
19
parser.c
|
@ -1420,11 +1420,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;
|
||||
}
|
||||
|
@ -1471,6 +1483,9 @@ static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out)
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue