Work on lambda body

This commit is contained in:
Krzosa Karol
2022-05-24 23:35:49 +02:00
parent 52910d5606
commit 9dc2e1588d
5 changed files with 97 additions and 18 deletions

View File

@@ -58,7 +58,7 @@ parsing_error(Token *token, const char *str, ...){
// @Note(Krzosa): Print nice error message
printf("\nError: %s", string.str);
if(token){
printf(" %s:%d\n", token->file.str, (S32)token->line);
printf(" %s:%d\n", token->file.str, (S32)token->line + 1);
// @Note(Krzosa): Print error line
{
@@ -165,15 +165,35 @@ parse_optional_type(){
return result;
}
function Ast_Block *
parse_block(){
Ast_Block *block = 0;
if(token_match(TK_NewUpScope)){
Token *token_block = token_get();
// function Ast_Block *
// parse_block(){
// Ast_Block *result = 0;
// if(token_match(TK_NewScope)){
Scratch scratch;
Array<Ast *> stmts = {scratch};
do{
Token *token = token_get();
if(token_match_keyword(keyword_return)){
AST_NEW(Return, AST_RETURN, token);
result->expr = parse_expr();
stmts.add(result);
}
else{
// @todo
// Probably want to rewrite parse decls to allow for
// calling from other places, dont want to error messages
// to suffer though!!!
parsing_error(token, "Unexpected token while parsing statement");
}
} while(token_match(TK_NewLine));
token_expect(TK_NewDownScope);
// }
// return result;
// }
block = ast_block(token_block, stmts);
}
return block;
}
function Ast_Lambda *
@@ -198,7 +218,7 @@ parse_lambda(Token *token, B32 is_typespec = false){ // @Todo(Krzosa): is_typesp
token_expect(TK_CloseParen);
Ast_Typespec *ret = parse_optional_type();
Ast_Block *block = 0;
Ast_Block *block = parse_block();
Ast_Lambda *result = ast_lambda(token, params, ret, block);
return result;
}
@@ -392,7 +412,10 @@ parse_decl(){
Token *token = token_get();
parsing_error(token, "Unexpected token: [%s] when parsing a declaration", token_kind_string(token->kind).str);
}
}
else if(!token_is(TK_End)){
Token *token = token_get();
parsing_error(token, "Unexpected token: [%s] when parsing a declaration", token_kind_string(token->kind).str);
}
return result;
}