-
Notifications
You must be signed in to change notification settings - Fork 27
/
errors.c
75 lines (72 loc) · 2.11 KB
/
errors.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "errors.h"
int warningMsg(const char *format, ...)
{
int ret;
//fprintf(stderr,"Line %d: Column:%d - ",lineNum,linePos);
fprintf(stderr, ANSI_COLOR_YELLOW);
va_list arg;
va_start(arg, format);
ret = vfprintf(stderr, format, arg);
va_end(arg);
fprintf(stderr, ANSI_COLOR_RESET);
return ret;
}
int errorMsg(const char *format, ...)
{
int ret;
fprintf(stderr, ANSI_COLOR_RED);
//fprintf(stderr, "Line %d: Column:%d - ", g_lineNum-g_headerLines, g_lineCol);
fprintf(stderr, "Line %d: Column:%d - ", g_lineNum, g_lineCol);
va_list arg;
va_start(arg, format);
ret = vfprintf(stderr, format, arg);
fprintf(stderr, ANSI_COLOR_RESET);
va_end(arg);
return ret;
}
void criticalError(ErrorCode code, char *message)
{
fprintf(stderr, "\t");
switch (code) {
case ERROR_EndlessString:
errorMsg("Error parsing string. No closing quote.\n");
break;
case ERROR_IncompatibleTypes:
errorMsg("Type mismatch.\n");
break;
case ERROR_UnexpectedIndent:
errorMsg("Unexpected scope increase\n");
break;
case ERROR_AssignToLiteral:
errorMsg("Cannot assign to a literal.\n");
break;
case ERROR_UnrecognizedSymbol:
errorMsg("Unknown symbol detected.\n");
break;
case ERROR_CannotAllocateMemory:
errorMsg("Cannot allocate new space.\n");
break;
case ERROR_UndefinedVerb:
errorMsg("Verb encountered without definition.\n");
break;
case ERROR_UndefinedVariable:
errorMsg("Variable encountered without definition.\n");
break;
case ERROR_UndefinedType:
errorMsg("Type encountered without definition.\n");
break;
case ERROR_InvalidArguments:
errorMsg("Attempted to run a function with invalid arguments.\n");
break;
case ERROR_ParseError:
errorMsg("Error while parsing file.\n");
break;
default:
errorMsg("Unknown critical error. Aborting.\n");
}
if (message) {
fprintf(stderr, "\t");
fprintf(stderr, "%s", message);
}
exit((int)code);
}