@@ -731,6 +731,9 @@ errorcode_t parse_stmts(parse_ctx_t *ctx, ast_expr_list_t *stmt_list, defer_scop
731731 case TOKEN_LLVM_ASM :
732732 if (parse_llvm_asm (ctx , stmt_list )) return FAILURE ;
733733 break ;
734+ case TOKEN_BEGIN :
735+ if (parse_conditionless_block (ctx , stmt_list , defer_scope )) return FAILURE ;
736+ break ;
734737 default :
735738 parse_panic_token (ctx , sources [* i ], tokens [* i ].id , "Encountered unexpected token '%s' at beginning of statement" );
736739 return FAILURE ;
@@ -1013,6 +1016,36 @@ errorcode_t parse_switch(parse_ctx_t *ctx, ast_expr_list_t *stmt_list, defer_sco
10131016 return SUCCESS ;
10141017}
10151018
1019+ errorcode_t parse_conditionless_block (parse_ctx_t * ctx , ast_expr_list_t * stmt_list , defer_scope_t * defer_scope ){
1020+ source_t source = ctx -> tokenlist -> sources [(* ctx -> i )++ ];
1021+
1022+ ast_expr_list_t block_stmt_list ;
1023+ ast_expr_list_init (& block_stmt_list , 4 );
1024+
1025+ defer_scope_t block_defer_scope ;
1026+ defer_scope_init (& block_defer_scope , defer_scope , NULL , TRAIT_NONE );
1027+
1028+ if (parse_stmts (ctx , & block_stmt_list , & block_defer_scope , PARSE_STMTS_STANDARD )
1029+ || parse_eat (ctx , TOKEN_END , "Expected '}' to close condition-less block" )){
1030+ ast_expr_list_free (& block_stmt_list );
1031+ defer_scope_free (& block_defer_scope );
1032+ return FAILURE ;
1033+ }
1034+
1035+ defer_scope_free (& block_defer_scope );
1036+
1037+ ast_expr_conditionless_block_t * stmt = malloc (sizeof (ast_expr_conditionless_block_t ));
1038+
1039+ * stmt = (ast_expr_conditionless_block_t ){
1040+ .id = EXPR_CONDITIONLESS_BLOCK ,
1041+ .source = source ,
1042+ .statements = block_stmt_list ,
1043+ };
1044+
1045+ stmt_list -> statements [stmt_list -> length ++ ] = (ast_expr_t * ) stmt ;
1046+ return SUCCESS ;
1047+ }
1048+
10161049errorcode_t parse_onetime_conditional (parse_ctx_t * ctx , ast_expr_list_t * stmt_list , defer_scope_t * defer_scope ){
10171050 token_t * tokens = ctx -> tokenlist -> tokens ;
10181051 length_t * i = ctx -> i ;
0 commit comments