]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
the 'local' keyword now also introduces the declaration of a local variable
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 14 Aug 2012 14:22:38 +0000 (16:22 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 14 Aug 2012 14:22:38 +0000 (16:22 +0200)
parser.c

index 65ec05d13da19bb5810f662195355871ef5f7454..85640e9b692b081e2b00e59879f07fe03748111c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1244,7 +1244,22 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
     }
     else if (parser->tok == TOKEN_KEYWORD)
     {
-        if (!strcmp(parser_tokval(parser), "return"))
+        if (!strcmp(parser_tokval(parser), "local"))
+        {
+            if (!block) {
+                parseerror(parser, "cannot declare a local variable here");
+                return false;
+            }
+            if (!parser_next(parser)) {
+                parseerror(parser, "expected variable declaration");
+                return false;
+            }
+            if (!parser_variable(parser, block))
+                return false;
+            *out = NULL;
+            return true;
+        }
+        else if (!strcmp(parser_tokval(parser), "return"))
         {
             ast_expression *exp = NULL;
             ast_return     *ret = NULL;