From 2d9623cbe8ebf988c7bd5060315c6d8b465b5c30 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Tue, 14 Aug 2012 16:22:38 +0200 Subject: [PATCH] the 'local' keyword now also introduces the declaration of a local variable --- parser.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/parser.c b/parser.c index 65ec05d..85640e9 100644 --- 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; -- 2.39.2