12_error_print_line(
module_t*
module,
unsigned int line,
unsigned int err_column,
bool has_error);
15_error_print_indicator(
unsigned int start_column,
unsigned int length);
18_error_print_info(
module_t*
module,
unsigned int err_line,
unsigned int err_column);
28 unsigned int current_line = 0;
33 while (feof(
module->
file) == 0 && current_line < line - 1) {
36 if (current_line >= ctx_start_line) {
37 _error_print_line(
module, current_line, 0,
false);
41 _error_remove_line(
module);
46 unsigned int correction = _error_print_line(
module, current_line, column,
true);
47 _error_print_indicator(column + correction, length);
48 fprintf(stderr,
"%s%s\n",
ERR_PREFIX, message);
50 while (feof(
module->
file) == 0 && current_line < ctx_end_line) {
53 _error_print_line(
module, current_line, 0,
false);
56 _error_print_info(
module, line, column);
59#define COL_PREFIX_SIZE 7
68_error_print_line(
module_t*
module,
unsigned int line,
unsigned int err_column,
bool has_error)
73 unsigned int buffer_index = 0;
79 fprintf(stderr,
"%4d | ", line);
89 buffer[buffer_index] =
'\n';
90 buffer[buffer_index + 1] =
'\0';
91 fputs(buffer, stderr);
96 buffer[buffer_index++] = ch;
104 fputs(buffer, stderr);
110 if (buffer_index > 0) {
111 buffer[buffer_index] =
'\0';
112 fputs(buffer, stderr);
115 return column_correction;
119_error_print_indicator(
unsigned int start_column,
unsigned int length)
123 fprintf(stderr,
"%*c" C_RED, start_column - 1,
' ');
125 for (
int i = 0; i < length; i++) {
133_error_print_info(
module_t*
module,
unsigned int err_line,
unsigned int err_column)
135 fprintf(stderr,
"On module %s:%d:%d.\n",
module->
filepath, err_line, err_column);
145 }
while (ch !=
'\n' && ch != EOF);
#define ERR_CTX_LINE_WRAP
void error_module_ctx(module_t *module, unsigned int line, unsigned int column, unsigned int length, const char *message)
Print a error message formated to show the code context inside the module.
Struct that represents a Mya module.
char filepath[MODULE_MAX_FILEPATH_SIZE+1]
Module's filepath.
FILE * file
Module's file handler.
struct module module_t
Struct that represents a Mya module.