move to C-style braces

This commit is contained in:
tocariimaa 2025-01-30 18:14:43 -03:00
parent e6b0294807
commit 8cd31829ad

View file

@ -200,7 +200,7 @@ proc_decl(ParserState *ps)
lex_backup(ps->lexer, token); lex_backup(ps->lexer, token);
} }
/* body */ /* 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; return proc;
} }
@ -364,7 +364,7 @@ decorated_decl(ParserState *ps)
static Ast * static Ast *
if_stmt_expr(ParserState *ps) 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); Ast *tree = make_tree(AST_IF, ps->lexer->cur_loc);
/* parse `if` */ /* parse `if` */
tree->ifse.cond = expr(ps, EXPR_INIT_PREC); 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, /* once we see an `else` block, we assume the end of the `if` block,
* enforcing that `else` must be the last. */ * enforcing that `else` must be the last. */
trace("we got else\n"); 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); next = lex_scan(ps->lexer);
if (next.id == T_ELIF) { if (next.id == T_ELIF) {
parse_error(ps, "'elif' branch after 'else' branch not allowed"); 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); Ast *tree = make_tree(AST_LOOP, ps->lexer->cur_loc);
tree->loop.precond = expr(ps, EXPR_INIT_PREC); 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; return tree;
} }
@ -555,6 +555,7 @@ token_id_in_list(enum LexTokenId c, const enum LexTokenId *toks, isize len)
static Ast * static Ast *
stmt_list_until(ParserState *ps, bool putback, const enum LexTokenId *end_markers, isize len) 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); LexToken token = lex_scan(ps->lexer);
Vec(Ast *) stmts = nil; Vec(Ast *) stmts = nil;
Ast *body = make_tree(AST_STMTS, ps->lexer->cur_loc); Ast *body = make_tree(AST_STMTS, ps->lexer->cur_loc);