#include "../syntax.h" bool parse_block(struct bshell_parse_ctx *ctx, struct bshell_ast_node **out) { if (!parse_symbol(ctx, BSHELL_SYM_LEFT_BRACE)) { return false; } parse_linefeed(ctx); struct bshell_block_ast_node *block = (struct bshell_block_ast_node *)bshell_ast_node_create( BSHELL_AST_BLOCK); bool ok = true; while (1) { if (parse_symbol(ctx, BSHELL_SYM_RIGHT_BRACE)) { break; } parse_linefeed(ctx); struct bshell_ast_node *stmt = NULL; if (!parse_statement(ctx, &stmt)) { ok = false; break; } fx_queue_push_back(&block->n_statements, &stmt->n_entry); if (parse_symbol(ctx, BSHELL_SYM_RIGHT_BRACE)) { break; } if (!parse_linefeed(ctx) && !parse_symbol(ctx, BSHELL_SYM_SEMICOLON)) { report_error( ctx, "expected `;`, `}`, or linefeed after " "statement"); ok = false; break; } } if (!ok) { bshell_ast_node_destroy((struct bshell_ast_node *)block); block = NULL; } *out = (struct bshell_ast_node *)block; return true; }