]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
if not() support
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 13 Nov 2012 17:54:25 +0000 (18:54 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 13 Nov 2012 17:55:55 +0000 (18:55 +0100)
parser.c

index 194f224080787a26369e7757f2082147ab391451..0f354a7b1ce6c1605e971464bc3074dd43c664c1 100644 (file)
--- 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;
 }