aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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),