commit 736422829f43ddbbe70861b02848bbf1e0f9d601
parent c267f1639f7639afee0f5799b00ddf5dfee1cbe2
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 20 Dec 2020 16:48:05 -0500
parse: fix compound expr w/only control statement
export fn main() int = {
return 0;
};
This would previously cause a syntax error.
Diffstat:
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/parse.c b/src/parse.c
@@ -441,38 +441,38 @@ parse_expression_list(struct parser *par, struct ast_expression *exp)
while (more) {
struct ast_expression *curexp =
calloc(1, sizeof(struct ast_expression));
- parse_scope_expression(par, curexp);
cur->expr = curexp;
struct token tok = {0};
- want(par, T_SEMICOLON, &tok);
-
switch (lex(par->lex, &tok)) {
- case T_RBRACE:
- more = false;
- break;
case T_BREAK:
case T_CONTINUE:
case T_RETURN:
unlex(par->lex, &tok);
- *next = calloc(1, sizeof(struct ast_expression_list));
- cur = *next;
-
- curexp = calloc(1, sizeof(struct ast_expression));
parse_control_statement(par, curexp);
- cur->expr = curexp;
-
- want(par, T_SEMICOLON, &tok);
- want(par, T_RBRACE, &tok);
more = false;
break;
default:
- *next = calloc(1, sizeof(struct ast_expression_list));
- cur = *next;
- next = &cur->next;
unlex(par->lex, &tok);
+ parse_scope_expression(par, curexp);
break;
}
+
+ want(par, T_SEMICOLON, &tok);
+
+ if (more) {
+ lex(par->lex, &tok);
+ if (tok.token == T_RBRACE) {
+ more = false;
+ } else {
+ unlex(par->lex, &tok);
+ *next = calloc(1, sizeof(struct ast_expression_list));
+ cur = *next;
+ next = &cur->next;
+ }
+ } else {
+ want(par, T_RBRACE, &tok);
+ }
}
trleave(TR_PARSE, NULL);