Change error printing to use colors, enable colors on windows cmd, print bytecode instruction line

This commit is contained in:
Krzosa Karol
2022-06-22 18:14:43 +02:00
parent cd48253e3e
commit a36747bc9c
4 changed files with 128 additions and 84 deletions

View File

@@ -1,20 +1,32 @@
function Ast_Decl *parse_decl(B32 is_global);
function void
print_token_line(Token *token){
if(!token) return;
#define PRINTF_RED "\033[31m"
#define PRINTF_RESET "\033[0m"
// Print from line begin to token
int i1 = token->str - token->line_begin;
printf("%.*s", i1, token->line_begin);
// Print token part
printf( PRINTF_RED "%.*s" PRINTF_RESET, (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");
}
function void
print_token_context(Token *token){
if(!token) return;
printf(" :: tdi:%u %s:%d\n", token->di, 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_line(token);
}
function void