-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExplainParserMessage.java
82 lines (64 loc) · 2.44 KB
/
ExplainParserMessage.java
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
76
77
78
79
80
81
82
public class ExplainParserMessage {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BOLD = "\u001B[1m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static int warningCount = 0;
public static int errorCount = 0;
private static void stderrLn(String message) {
System.err.println(message);
}
private static void stderr(String message) {
System.err.print(message);
}
public static void die() {
System.exit(1);
}
public static void sendUnqualifiedErrorPrefix() {
stderr("explain: ");
}
public static void sendLocation(String filename) {
String message = ANSI_BOLD + filename + ": " + ANSI_RESET;
stderr(message);
}
public static void sendLocation(String filename, int line, int column) {
String message = ANSI_BOLD + filename + ":" + line + ":" + column + ": " + ANSI_RESET;
stderr(message);
}
public static void send(String message, ExplainSeverityLevel level) {
String messagePrefix = "";
Boolean shouldDie = false;
switch (level) {
case UNFORMATTED:
break;
case WARNING:
messagePrefix = ANSI_BOLD + ANSI_PURPLE + "warning: " + ANSI_WHITE;
warningCount++;
break;
case SYNTAX_ERROR:
messagePrefix = ANSI_BOLD + ANSI_RED + "error: " + ANSI_WHITE;
break;
case ERROR:
messagePrefix = ANSI_BOLD + ANSI_RED + "error: " + ANSI_WHITE;
errorCount++;
break;
case FATAL_ERROR:
messagePrefix = ANSI_BOLD + ANSI_RED + "error: " + ANSI_WHITE;
shouldDie = true;
break;
default:
messagePrefix = ANSI_BOLD + ANSI_YELLOW + "message: " + ANSI_WHITE;
break;
}
stderrLn(messagePrefix + message + ANSI_RESET);
if (shouldDie) {
die();
}
}
}