libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
error_handling.h File Reference
#include "colors.h"
#include "module.h"
#include "types/err.h"
Include dependency graph for error_handling.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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.
 

Function Documentation

◆ error_module_ctx()

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.

Parameters
moduleThe module where the error will be showed.
lineThe module's line where the error is.
columnThe line's column where the error starts.
lengthThe length of the part where has an error in the line. It's starts on column and ends on column + length.
messageThe error message to print.

Definition at line 24 of file error_handling.c.

25{
26 unsigned int ctx_start_line = (line > ERR_CTX_SIZE) ? line - ERR_CTX_SIZE : 0;
27 unsigned int ctx_end_line = line + ERR_CTX_SIZE;
28 unsigned int current_line = 0;
29
30 fseek(module->file, 0, SEEK_SET);
31
32
33 while (feof(module->file) == 0 && current_line < line - 1) {
34 current_line++;
35
36 if (current_line >= ctx_start_line) {
37 _error_print_line(module, current_line, 0, false);
38 continue;
39 }
40
41 _error_remove_line(module);
42 }
43
44 current_line++;
45
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);
49
50 while (feof(module->file) == 0 && current_line < ctx_end_line) {
51 current_line++;
52
53 _error_print_line(module, current_line, 0, false);
54 }
55
56 _error_print_info(module, line, column);
57}
#define ERR_CTX_SIZE
Definition err.h:5
#define ERR_PREFIX
Definition err.h:8
Struct that represents a Mya module.
Definition module.h:34
FILE * file
Module's file handler.
Definition module.h:35