Nicer error messages

This commit is contained in:
Krzosa Karol
2022-06-10 16:26:26 +02:00
parent 11e7bd52fd
commit 6ad5f4e706
3 changed files with 20 additions and 14 deletions

View File

@@ -1,5 +1,21 @@
function Ast_Decl *parse_decl(B32 is_global);
function void
print_token_context(Token *token){
printf(" :: %s:%d\n", token->file.str, (S32)token->line + 1);
// @Note(Krzosa): Print error line
{
int i = 0;
while(token->line_begin[i]!='\n' && token->line_begin[i]!=0) i++;
printf("%.*s\n", i, token->line_begin);
// @Note(Krzosa): Print error marker
int token_i = token->str - token->line_begin;
for(int i = 0; i < token_i-2; i++) printf(" ");
printf("^^^^^^\n");
}
}
function void
compiler_error(Token *token, const char *str, ...){
Scratch scratch;
@@ -11,19 +27,8 @@ compiler_error(Token *token, const char *str, ...){
if(token->kind == TK_Error){
printf("Token Error: %.*s", (int)token->error_val.len, token->error_val.str);
}
printf(" :: %s:%d\n", token->file.str, (S32)token->line + 1);
// @Note(Krzosa): Print error line
{
int i = 0;
while(token->line_begin[i]!='\n' && token->line_begin[i]!=0) i++;
printf("%.*s\n", i, token->line_begin);
// @Note(Krzosa): Print error marker
int token_i = token->str - token->line_begin;
for(int i = 0; i < token_i-2; i++) printf(" ");
printf("^^^^^^\n");
}
print_token_context(token);
}
__debugbreak();