From e793f92e675d8af49f24c62c1589bc0c26dce35b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 9 Aug 2021 13:01:47 +0100 Subject: [PATCH] Improve parsing handling for the `{ return }` cases --- src/parser.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/parser.cpp b/src/parser.cpp index 931563986..ee8aa46fa 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1548,6 +1548,15 @@ void expect_semicolon(AstFile *f, Ast *s) { expect_semicolon_newline_error(f, f->prev_token, s); return; } + switch (f->curr_token.kind) { + case Token_CloseBrace: + case Token_CloseParen: + if (f->curr_token.pos.line == f->prev_token.pos.line) { + return; + } + break; + } + prev_token = f->prev_token; if (prev_token.kind == Token_Semicolon) { expect_semicolon_newline_error(f, f->prev_token, s); @@ -1558,6 +1567,8 @@ void expect_semicolon(AstFile *f, Ast *s) { return; } + + if (s != nullptr) { bool insert_semi = (f->tokenizer.flags & TokenizerFlag_InsertSemicolon) != 0; if (insert_semi) { @@ -3926,7 +3937,7 @@ Ast *parse_return_stmt(AstFile *f) { auto results = array_make(heap_allocator()); - while (f->curr_token.kind != Token_Semicolon) { + while (f->curr_token.kind != Token_Semicolon && f->curr_token.kind != Token_CloseBrace) { Ast *arg = parse_expr(f, false); array_add(&results, arg); if (f->curr_token.kind != Token_Comma ||