Nicer error messages
This commit is contained in:
@@ -15,5 +15,5 @@ val := CONSTANT_VAL
|
||||
DEPENDENCE :: CONSTANT_VAL
|
||||
CONSTANT_VAL :: 10
|
||||
|
||||
//thing: a_type = 10
|
||||
thing: a_type = 10
|
||||
|
||||
|
||||
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();
|
||||
|
||||
@@ -528,7 +528,8 @@ function void
|
||||
insert_into_scope(Ast_Scope *scope, Ast_Decl *decl){
|
||||
Ast_Decl *find = search_for_decl(scope, decl->name);
|
||||
if(find){
|
||||
compiler_error(decl->pos, "[%s] is already defined in this scope", decl->name.str);
|
||||
print_token_context(find->pos);
|
||||
compiler_error(decl->pos, "[%s] is already defined", decl->name.str);
|
||||
}
|
||||
|
||||
scope->decls.add(decl);
|
||||
|
||||
Reference in New Issue
Block a user