From 8cd31829add35fbb43c989cf77fe49bcae00f34b Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Thu, 30 Jan 2025 18:14:43 -0300 Subject: [PATCH] move to C-style braces --- compiler/parse.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/parse.c b/compiler/parse.c index 39a5ae6..1bd8a36 100644 --- a/compiler/parse.c +++ b/compiler/parse.c @@ -200,7 +200,7 @@ proc_decl(ParserState *ps) lex_backup(ps->lexer, token); } /* body */ - proc->proc.body = stmt_list_until(ps, false, (enum LexTokenId[]){T_END}, 1); + proc->proc.body = stmt_list_until(ps, false, (enum LexTokenId[]){T_RBRACE}, 1); return proc; } @@ -364,7 +364,7 @@ decorated_decl(ParserState *ps) static Ast * if_stmt_expr(ParserState *ps) { - const enum LexTokenId if_block_ends[] = {T_ELSE, T_ELIF, T_END}; + const enum LexTokenId if_block_ends[] = {T_ELSE, T_ELIF, T_RBRACE}; Ast *tree = make_tree(AST_IF, ps->lexer->cur_loc); /* parse `if` */ tree->ifse.cond = expr(ps, EXPR_INIT_PREC); @@ -382,7 +382,7 @@ if_stmt_expr(ParserState *ps) /* once we see an `else` block, we assume the end of the `if` block, * enforcing that `else` must be the last. */ trace("we got else\n"); - tree->ifse.false_body = stmt_list_until(ps, true, (enum LexTokenId[]){T_ELIF, T_END}, 2); + tree->ifse.false_body = stmt_list_until(ps, true, (enum LexTokenId[]){T_ELIF, T_RBRACE}, 2); next = lex_scan(ps->lexer); if (next.id == T_ELIF) { parse_error(ps, "'elif' branch after 'else' branch not allowed"); @@ -415,7 +415,7 @@ while_stmt(ParserState *ps) { Ast *tree = make_tree(AST_LOOP, ps->lexer->cur_loc); tree->loop.precond = expr(ps, EXPR_INIT_PREC); - tree->loop.body = stmt_list_until(ps, false, (enum LexTokenId[]){T_END}, 1); + tree->loop.body = stmt_list_until(ps, false, (enum LexTokenId[]){T_RBRACE}, 1); return tree; } @@ -555,6 +555,7 @@ token_id_in_list(enum LexTokenId c, const enum LexTokenId *toks, isize len) static Ast * stmt_list_until(ParserState *ps, bool putback, const enum LexTokenId *end_markers, isize len) { + next_match(ps->lexer, T_LBRACE); LexToken token = lex_scan(ps->lexer); Vec(Ast *) stmts = nil; Ast *body = make_tree(AST_STMTS, ps->lexer->cur_loc);