Errors work better with sublime
This commit is contained in:
@@ -10,23 +10,28 @@ print_token_line(Token *token){
|
||||
|
||||
// Print from line begin to token
|
||||
int i1 = token->str - token->line_begin;
|
||||
printf("%.*s", i1, token->line_begin);
|
||||
log_info_no_nl("%.*s", i1, token->line_begin);
|
||||
|
||||
// Print token part
|
||||
printf( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
if(color_codes_enabled){
|
||||
log_info_no_nl( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
} else {
|
||||
log_info_no_nl("%.*s", (int)token->len, token->str);
|
||||
}
|
||||
|
||||
|
||||
// Print to end of line from token
|
||||
int iend = 0;
|
||||
U8 *pointer = token->str + token->len;
|
||||
while(pointer[iend]!='\n' && pointer[iend]!=0) iend++;
|
||||
printf("%.*s", iend, pointer);
|
||||
printf("\n");
|
||||
log_info_no_nl("%.*s", iend, pointer);
|
||||
log_info_no_nl("\n");
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
print_token_context(Token *token){
|
||||
if(!token) return;
|
||||
printf("\n");
|
||||
log_info_no_nl("\n");
|
||||
print_token_line(token);
|
||||
}
|
||||
|
||||
@@ -35,24 +40,25 @@ compiler_error(Token *token1, Token *token2, const char *str, ...){
|
||||
Scratch scratch;
|
||||
STRING_FMT(scratch, str, string);
|
||||
|
||||
printf("\n%s", string.str);
|
||||
log_info_no_nl("\n%s", string.str);
|
||||
if(token1){
|
||||
if(token1->kind == TK_Error){
|
||||
printf("\nToken Error: %.*s", (int)token1->error_val.len, token1->error_val.str);
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token1->error_val.len, token1->error_val.str);
|
||||
}
|
||||
print_token_context(token1);
|
||||
}
|
||||
|
||||
if(token2){
|
||||
if(token2->kind == TK_Error){
|
||||
printf("\nToken Error: %.*s", (int)token2->error_val.len, token2->error_val.str);
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token2->error_val.len, token2->error_val.str);
|
||||
}
|
||||
print_token_context(token2);
|
||||
}
|
||||
|
||||
if(token1) printf("\n%s:%d token_di:%u", token1->file.str, (S32)token1->line + 1, token1->di);
|
||||
if(token2) printf("\n%s:%d token_di:%u", token2->file.str, (S32)token2->line + 1, token2->di);
|
||||
if(token1) log_info_no_nl("\n%s:%d", token1->file.str, (S32)token1->line + 1);
|
||||
if(token2) log_info_no_nl("\n%s:%d", token2->file.str, (S32)token2->line + 1);
|
||||
|
||||
fflush(stdout);
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
@@ -61,17 +67,19 @@ compiler_error(Token *token, const char *str, ...){
|
||||
Scratch scratch;
|
||||
STRING_FMT(scratch, str, string);
|
||||
|
||||
printf("\n%s", string.str);
|
||||
if(token) log_info_no_nl("\n%s:%d %Q", token->file.str, (S32)token->line + 1, string);
|
||||
else log_info_no_nl("\n%s", string.str);
|
||||
if(token){
|
||||
if(token->kind == TK_Error){
|
||||
printf("\nToken Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||
}
|
||||
|
||||
print_token_context(token);
|
||||
}
|
||||
|
||||
if(token) printf("\n%s:%d token_di:%u", token->file.str, (S32)token->line + 1, token->di);
|
||||
|
||||
|
||||
fflush(stdout);
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user