2026-05-25 10:33:29 +01:00
|
|
|
#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);
|
|
|
|
|
|
2026-06-20 15:11:02 +01:00
|
|
|
parse_linefeed(ctx);
|
|
|
|
|
|
2026-05-25 10:33:29 +01:00
|
|
|
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;
|
|
|
|
|
}
|