diff --git a/bshell/parse/syntax/block.c b/bshell/parse/syntax/block.c new file mode 100644 index 0000000..ca0d809 --- /dev/null +++ b/bshell/parse/syntax/block.c @@ -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; +}