#include "report.h" #include void print_report_loc( const char* filename, const char* text, size_t text_len, Loc loc) { size_t line_start = loc.idx; while (line_start > 0 && text[line_start] != '\n') { line_start -= 1; } if (text[line_start] == '\n') { line_start += 1; } size_t line_end = loc.idx + 1; while (line_end < text_len && text[line_end] != '\n') { line_end += 1; } const char* line = &text[line_start]; int line_len = (int)line_end - (int)line_start; fprintf(stderr, " \x1b[96m--> ./%s:%d:%d\n " "\x1b[37m|\n\x1b[96m%5d\x1b[37m|%.*s\n " "|%*c\x1b[1;91m^\x1b[0m\n", filename, loc.line, loc.col, loc.line, line_len, line, loc.col - 1, ' '); } void reporter_print_loc(Reporter* rep, Loc loc) { print_report_loc(rep->filename, rep->text, rep->text_len, loc); } void reporter_error_with_loc(Reporter* rep, const char* msg, Loc loc) { REPORTF_ERROR("%s", msg); reporter_print_loc(rep, loc); }