parse: implement parsing of {...} statement blocks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user