-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorPrinter.java
37 lines (36 loc) · 914 Bytes
/
ErrorPrinter.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
import java.io.IOException;
import xtc.parser.ParseError;
import xtc.parser.ParseException;
import xtc.parser.ParserBase;
import xtc.tree.Location;
class ErrorPrinter {
static int _count;
ErrorPrinter() { _count = 0; }
static void exit() {
if (0 == _count)
System.exit(0);
if (1 == _count)
System.err.println("There was 1 error.");
else
System.err.println("There were " + _count + " errors.");
System.exit(-1);
}
static void print(ParserBase parser, ParseError err) {
_count++;
try {
parser.signal(err);
} catch (ParseException exc) {
System.err.println(exc.getMessage());
} catch (IOException exc) {
System.exit(-2);
}
if (100 <= _count)
exit();
}
static void print(Location loc, String msg) {
_count++;
System.err.println(loc.toString() + ": " + msg + ".");
if (100 <= _count)
exit();
}
}