KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > NoViableAltForCharException


1 package persistence.antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

8
9 public class NoViableAltForCharException extends RecognitionException {
10     public char foundChar;
11
12     public NoViableAltForCharException(char c, CharScanner scanner) {
13         super("NoViableAlt", scanner.getFilename(),
14               scanner.getLine(), 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 JavaDoc fileName, int line) {
20         this(c, fileName, line, -1);
21     }
22     
23     public NoViableAltForCharException(char c, String JavaDoc fileName, 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 JavaDoc getMessage() {
32         String JavaDoc mesg = "unexpected char: ";
33
34         // I'm trying to mirror a change in the C++ stuff.
35
// But java seems to lack something isprint-ish..
36
// so we do it manually. This is probably to restrictive.
37

38         if ((foundChar >= ' ') && (foundChar <= '~')) {
39             mesg += '\'';
40             mesg += foundChar;
41             mesg += '\'';
42         }
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 }
63
Popular Tags