10#ifdef COMPILED_FROM_MAKE
11 #include "termcolor.h"
13 #include "../libtermcolor/include/termcolor.h"
22#define _PRINTF(...) tcol_fprintf(stream, __VA_ARGS__)
23#define _PRINTF_FST(...) fprintf(stream, __VA_ARGS__)
25#define _PUTCHR(__c) fputc(__c, stream)
27static STR error_scope_strs[] = {
32static STR error_scope_color_strs[] = {
33#define ENUM TO_STRING2
37static STR error_code_strs[] = {
44static usize error_count;
51static const char* ps_color(
const char* tc_color) {
52#define N_COLORS_STORABLE 20
53#define N_ESTIMATED_MAX_COLOR_LENGTH 24
59 static usize used = 0;
67 char* result =
buffer + used;
70 != TermColorErrorNone) {
78#undef N_COLORS_STORABLE
79#undef N_ESTIMATED_MAX_COLOR_LENGTH
88 struct ps_error* err = &errors[error_count++];
102static inline void ps_fprint_error_primary(FILE* stream,
struct ps_error* err) {
111 if (err->
code >= 0) {
122static inline void ps_fprintf_error_line_prefix(FILE* stream,
132static inline void ps_fprintf_error_explain(FILE* stream,
struct ps_error* err,
133 usize chars_before_error) {
135 ps_fprintf_error_line_prefix(stream, err, -1);
137 err->
length > 1 ?
"┌" :
"│");
144 ps_fprintf_error_line_prefix(stream, err, -1);
146 ps_fprintf_error_line_prefix(stream, err, -1);
147 _PRINTF(
"%*s%s{0}{/}%s{0}\n", (
int)chars_before_error,
"", err->
theme,
152static inline void ps_fprintf_error_fix(FILE* stream,
struct ps_error* err) {
158static inline void ps_fprintf_error_line(FILE* stream,
struct ps_error* err) {
159 ps_fprintf_error_line_prefix(stream, err, err->
loc.
line);
163 if (line_start > 0 && err->
file_source[line_start] ==
'\n') {
166 while (line_start > 0 && err->
file_source[line_start] !=
'\n') {
174 usize line_length = 0;
176 while ((end_char = err->
file_source[line_start + line_length]),
177 end_char !=
'\n' && end_char != 0) {
182 usize chars_before_error = err->
loc.
pos - line_start;
183 usize chars_after_error = line_length - (chars_before_error + err->
length);
184 usize start_after_error = line_start + chars_before_error + err->
length;
191 (
int)chars_before_error, &err->
file_source[line_start],
194 &err->
file_source[line_start + chars_before_error],
196 (
int)chars_after_error, &err->
file_source[start_after_error]);
200 ps_fprintf_error_explain(stream, err, chars_before_error);
203 ps_fprintf_error_fix(stream, err);
209 ps_fprint_error_primary(stream, err);
211 ps_fprintf_error_line(stream, err);
218 tcol_auto_color(stream);
221 for (
usize i = 0; i < error_count; i++) {
226 struct ps_error* error = &errors[i];
229 error->
theme = ps_color(error_scope_color_strs[error->
scope]);
Defines assertion and abortion functionality.
#define N_ESTIMATED_MAX_COLOR_LENGTH
usize ps_error_count(void)
The number of errors that have been reported in the error reporting system.
#define N_COLORS_STORABLE
void ps_fprint_errors(FILE *stream)
Prints all errors in the error-reporting system to the given output stream stream.
void ps_fprint_error(FILE *stream, struct ps_error *err)
Displays the err on the given output stream stream.
bool ps_is_loc_none(const struct ps_loc *loc)
Error reporting and displaying utilities.
ps_error_scope
THe domain of error that occured.
char buffer[ITOA_BUFFER_SIZE]
static void usize struct ps_loc loc
Retrieval of associated data from custom enum (see enum.h).
Represents an error or source-referencing display message.
enum ps_error_scope scope
Represents a token location.
STR filename
The file where the token is from.
usize pos
The token's position in the text.
usize line
The line number where the token is found.
usize col
The column number where the token starts.