parse: implement parsing of {...} statement blocks

This commit is contained in:
2026-05-12 22:57:16 +01:00
parent 0cd7ca2dde
commit 26e2a63200
+30
View File
@@ -0,0 +1,30 @@
#include "../syntax.h"
bool parse_block(struct parse_ctx *ctx, struct ast_node **out)
{
if (!parse_symbol(ctx, SYM_LEFT_BRACE)) {
return false;
}
struct block_ast_node *block
= (struct block_ast_node *)ast_node_create(AST_BLOCK);
while (1) {
parse_linefeed(ctx);
if (parse_symbol(ctx, SYM_RIGHT_BRACE)) {
break;
}
struct ast_node *stmt = NULL;
if (!parse_statement(ctx, &stmt)) {
ast_node_destroy((struct ast_node *)block);
return false;
}
fx_queue_push_back(&block->n_statements, &stmt->n_entry);
}
*out = (struct ast_node *)block;
return true;
}