Nicer error messages
This commit is contained in:
29
parsing.cpp
29
parsing.cpp
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user