From f3ebbf598fa61fc4ad13416ef00a7d09d947c7a4 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Tue, 13 Nov 2012 18:54:25 +0100 Subject: [PATCH] if not() support --- parser.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/parser.c b/parser.c index 194f224..0f354a7 100644 --- a/parser.c +++ b/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,7 +1483,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; } -- 2.39.2