Add switch case statement
This commit is contained in:
31
parsing.cpp
31
parsing.cpp
@@ -234,6 +234,37 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(ast_pass(token));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_switch)){
|
||||
Ast_Switch *result = MAKE_AST(Ast_Switch, AST_SWITCH, token, AST_STMT);
|
||||
result->value = parse_expr();
|
||||
result->cases = {scratch};
|
||||
|
||||
token_expect(OPEN_SCOPE);
|
||||
do{
|
||||
if(token_match_keyword(keyword_default)){
|
||||
result->default_scope = parse_stmt_scope();
|
||||
continue;
|
||||
}
|
||||
|
||||
Ast_Switch_Case *switch_case = MAKE_AST(Ast_Switch_Case, AST_SWITCH_CASE, token_get(), AST_STMT);
|
||||
if(token_match_pound(pctx->intern("fallthrough"_s)))
|
||||
switch_case->fallthrough = true;
|
||||
|
||||
switch_case->labels = {scratch};
|
||||
do{
|
||||
switch_case->labels.add(parse_expr());
|
||||
}while(token_match(TK_Comma));
|
||||
switch_case->labels = switch_case->labels.tight_copy(pctx->perm);
|
||||
|
||||
switch_case->scope = parse_stmt_scope();
|
||||
result->cases.add(switch_case);
|
||||
}while(token_match(SAME_SCOPE));
|
||||
token_expect(CLOSE_SCOPE);
|
||||
result->cases = result->cases.tight_copy(pctx->perm);
|
||||
|
||||
scope->stmts.add(result);
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_assert)){
|
||||
token_expect(TK_OpenParen);
|
||||
Ast_Expr *expr = parse_expr();
|
||||
|
||||
Reference in New Issue
Block a user