01: package persistence.antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: public class NoViableAltForCharException extends RecognitionException {
10: public char foundChar;
11:
12: public NoViableAltForCharException(char c, CharScanner scanner) {
13: super ("NoViableAlt", scanner.getFilename(), scanner.getLine(),
14: scanner.getColumn());
15: foundChar = c;
16: }
17:
18: /** @deprecated As of ANTLR 2.7.2 use {@see #NoViableAltForCharException(char, String, int, int) } */
19: public NoViableAltForCharException(char c, String fileName, int line) {
20: this (c, fileName, line, -1);
21: }
22:
23: public NoViableAltForCharException(char c, String fileName,
24: int line, int column) {
25: super ("NoViableAlt", fileName, line, column);
26: foundChar = c;
27: }
28:
29: /**
30: * Returns a clean error message (no line number/column information)
31: */
32: public String getMessage() {
33: String mesg = "unexpected char: ";
34:
35: // I'm trying to mirror a change in the C++ stuff.
36: // But java seems to lack something isprint-ish..
37: // so we do it manually. This is probably to restrictive.
38:
39: if ((foundChar >= ' ') && (foundChar <= '~')) {
40: mesg += '\'';
41: mesg += foundChar;
42: mesg += '\'';
43: } else {
44: mesg += "0x";
45:
46: int t = (int) foundChar >> 4;
47:
48: if (t < 10)
49: mesg += (char) (t | 0x30);
50: else
51: mesg += (char) (t + 0x37);
52:
53: t = (int) foundChar & 0xF;
54:
55: if (t < 10)
56: mesg += (char) (t | 0x30);
57: else
58: mesg += (char) (t + 0x37);
59: }
60: return mesg;
61: }
62: }
|