Add static and runtime assert
This commit is contained in:
24
parsing.cpp
24
parsing.cpp
@@ -224,6 +224,30 @@ parse_stmt_scope(Ast_Scope *scope_defined_outside = 0){
|
||||
scope->stmts.add(ast_pass(token));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_assert)){
|
||||
token_expect(TK_OpenParen);
|
||||
Ast_Expr *expr = parse_expr();
|
||||
Intern_String message = {};
|
||||
if(token_match(TK_Comma)){
|
||||
Token *t = token_expect(TK_StringLit);
|
||||
message = t->intern_val;
|
||||
}
|
||||
token_expect(TK_CloseParen);
|
||||
scope->stmts.add(ast_runtime_assert(token, expr, message));
|
||||
}
|
||||
|
||||
else if(token_match_pound(keyword_assert)){
|
||||
token_expect(TK_OpenParen);
|
||||
Ast_Expr *expr = parse_expr();
|
||||
Intern_String message = {};
|
||||
if(token_match(TK_Comma)){
|
||||
Token *t = token_expect(TK_StringLit);
|
||||
message = t->intern_val;
|
||||
}
|
||||
token_expect(TK_CloseParen);
|
||||
scope->stmts.add(ast_constant_assert(token, expr, message));
|
||||
}
|
||||
|
||||
else if(token_match_keyword(keyword_for)){
|
||||
Ast_Scope *for_scope = begin_stmt_scope(scratch, token_get());
|
||||
Ast_Expr *init = 0;
|
||||
|
||||
Reference in New Issue
Block a user