01: package antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: public class NoViableAltForCharException extends RecognitionException {
09: public char foundChar;
10:
11: public NoViableAltForCharException(char c, CharScanner scanner) {
12: super ("NoViableAlt", scanner.getFilename(), scanner.getLine(),
13: scanner.getColumn());
14: foundChar = c;
15: }
16:
17: /** @deprecated As of ANTLR 2.7.2 use {@see #NoViableAltForCharException(char, String, int, int) } */
18: public NoViableAltForCharException(char c, String fileName, int line) {
19: this (c, fileName, line, -1);
20: }
21:
22: public NoViableAltForCharException(char c, String fileName,
23: int line, int column) {
24: super ("NoViableAlt", fileName, line, column);
25: foundChar = c;
26: }
27:
28: /**
29: * Returns a clean error message (no line number/column information)
30: */
31: public String getMessage() {
32: String mesg = "unexpected char: ";
33:
34: // I'm trying to mirror a change in the C++ stuff.
35: // But java seems to lack something convenient isprint-ish..
36: // actually we're kludging around unicode and non unicode savy
37: // output stuff like most terms.. Basically one would want to
38: // be able to tweak the generation of this message.
39:
40: if ((foundChar >= ' ') && (foundChar <= '~')) {
41: mesg += '\'';
42: mesg += foundChar;
43: mesg += '\'';
44: } else {
45: mesg += "0x"
46: + Integer.toHexString((int) foundChar)
47: .toUpperCase();
48: }
49: return mesg;
50: }
51: }
|