aboutsummaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-30 23:48:02 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-30 23:48:02 -0400
commit0f11502a7db584ad65f9508cc6bc023d4a73c9fc (patch)
tree7e352b45fe96ec972a961490d2d30a26e86b158f /src/parse.c
parent982d67437fa0d6e504a929daf0ce95c5cd03ef54 (diff)
Prepend `do_begin` statements to `do` statements, don't put them in a
separate block
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/parse.c b/src/parse.c
index 5190d92c..6a1b151c 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -1126,14 +1126,18 @@ PARSER(parse_do) {
pos = tmp;
ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'do'");
if (begin && end) {
- return NewAST(ctx->file, start, pos, Block,
- .statements=new(ast_list_t, .ast=begin,
- .next=new(ast_list_t, .ast=WrapAST(end, Defer, .body=end),
- .next=new(ast_list_t, .ast=body))));
+ ast_list_t *statements = Match(begin, Block)->statements;
+ REVERSE_LIST(statements);
+ statements = new(ast_list_t, .ast=WrapAST(end, Defer, .body=end), .next=statements);
+ statements = new(ast_list_t, .ast=body, .next=statements);
+ REVERSE_LIST(statements);
+ return NewAST(ctx->file, start, pos, Block, .statements=statements);
} else if (begin) {
- return NewAST(ctx->file, start, pos, Block,
- .statements=new(ast_list_t, .ast=begin,
- .next=new(ast_list_t, .ast=body)));
+ ast_list_t *statements = Match(begin, Block)->statements;
+ REVERSE_LIST(statements);
+ statements = new(ast_list_t, .ast=body, .next=statements);
+ REVERSE_LIST(statements);
+ return NewAST(ctx->file, start, pos, Block, .statements=statements);
} else if (end) {
return NewAST(ctx->file, start, pos, Block,
.statements=new(ast_list_t, .ast=WrapAST(end, Defer, .body=end),