Add var args for using printf
This commit is contained in:
@@ -283,30 +283,38 @@ function Ast_Lambda *
|
||||
parse_lambda(Token *token){
|
||||
Scratch scratch;
|
||||
|
||||
B32 has_var_args = false;
|
||||
Array<Ast_Lambda_Arg *> params = {scratch};
|
||||
if(!token_is(TK_CloseParen)){
|
||||
for(;;){
|
||||
Token *name = token_expect(TK_Identifier);
|
||||
token_expect(TK_Colon);
|
||||
Ast_Expr *typespec = parse_expr();
|
||||
Token *name = token_get();
|
||||
if(token_match(TK_Identifier)){
|
||||
token_expect(TK_Colon);
|
||||
Ast_Expr *typespec = parse_expr();
|
||||
|
||||
Ast_Expr *default_value = 0;
|
||||
if(token_match(TK_Assign)) {
|
||||
default_value = parse_expr();
|
||||
Ast_Expr *default_value = 0;
|
||||
if(token_match(TK_Assign)) {
|
||||
default_value = parse_expr();
|
||||
}
|
||||
|
||||
Ast_Lambda_Arg *param = ast_expr_lambda_arg(name, name->intern_val, typespec, default_value);
|
||||
params.add(param);
|
||||
}
|
||||
|
||||
Ast_Lambda_Arg *param = ast_expr_lambda_arg(name, name->intern_val, typespec, default_value);
|
||||
params.add(param);
|
||||
if(!token_match(TK_Comma)){
|
||||
else if(token_match(TK_ThreeDots)){
|
||||
has_var_args = true;
|
||||
break;
|
||||
}
|
||||
else parsing_error(name, "Expected [Identifier] or [...] when parsing lambda arguments");
|
||||
|
||||
if(!token_match(TK_Comma))
|
||||
break;
|
||||
}
|
||||
}
|
||||
token_expect(TK_CloseParen);
|
||||
|
||||
Ast_Expr *ret = parse_optional_type();
|
||||
Ast_Block *block = token_is(OPEN_SCOPE) ? parse_block() : 0;
|
||||
Ast_Lambda *result = ast_lambda(token, params, ret, block);
|
||||
Ast_Lambda *result = ast_lambda(token, params, has_var_args, ret, block);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -421,8 +429,8 @@ parse_expr(S64 min_bp){
|
||||
}break;
|
||||
|
||||
case TK_OpenParen: {
|
||||
if(token_is(TK_CloseParen)) left = parse_lambda(token);
|
||||
else if(token_is(TK_Identifier) && token_is(TK_Colon, 1)) left = parse_lambda(token);
|
||||
if(token_is(TK_CloseParen) || (token_is(TK_Identifier) && token_is(TK_Colon, 1)) || token_is(TK_ThreeDots))
|
||||
left = parse_lambda(token);
|
||||
else{
|
||||
left = parse_expr(0);
|
||||
token_expect(TK_CloseParen);
|
||||
|
||||
Reference in New Issue
Block a user