1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "errors.h"
static const char* error_msgs[] = {
[ERR_UNKNOWN] = "error: something unexpected happened",
[ERR_UNMATCHED_STRING] = "error: unmatched string delimiter",
[ERR_UNBALANCED_PAREN] = "error: unbalanced parentheses",
[ERR_NOT_IMPLEMENTED] = "error: not implemented",
[ERR_EOF_REACHED] = "error: EOF reached",
[ERR_UNKNOWN_TOKEN] = "error: unknown token",
[ERR_UNKNOWN_OBJ_TYPE] = "error: can't eval unknown object type",
[ERR_NOT_A_SYMBOL] = "error: object is not a symbol",
[ERR_SYMBOL_NOT_FOUND] = "error: symbol not found",
[ERR_NOT_CALLABLE] = "error: not callable",
[ERR_NOT_ENOUGH_ARGS] = "error: not enough arguments",
[ERR_TOO_MANY_ARGS] = "error: too many arguments",
[ERR_WRONG_ARG_TYPE] = "error: wrong argument type",
[ERR_DIVISION_BY_ZERO] = "error: division by zero",
[ERR_AMBIGUOUS_PARAMS] = "error: ambiguous parameter names",
};
void
error_push(Errors *errors, Error error) {
if (errors->n < ERR_MAX_NUMBER) {
errors->errors[errors->n++] = error;
}
}
void
report_errors(Errors *errors, const char *file_name) {
for (size_t i = 0; i < errors->n; i++) {
Error err = errors->errors[i];
fprintf(stderr, "%s", file_name);
if (err.line != 0) {
fprintf(stderr, ":%ld:%ld", err.line, err.col);
}
switch (err.type) {
case ERR_TYPE_LEXER: { fprintf(stderr, ": [lexer]"); } break;
case ERR_TYPE_COMPILER: { fprintf(stderr, ": [compiler]"); } break;
case ERR_TYPE_RUNTIME: { fprintf(stderr, ": [runtime]"); } break;
case ERR_TYPE_PARSER: { fprintf(stderr, ": [parser]"); } break;
default: break;
}
fprintf(stderr, " %s\n", error_msgs[err.value]);
}
errors->n = 0;
}
|