KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > sqlparser > core > ParseException


1 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
2 package com.genimen.djeneric.repository.sqlparser.core;
3
4 /**
5  * This exception is thrown when parse errors are encountered.
6  * You can explicitly create objects of this exception type by
7  * calling the method generateParseException in the generated
8  * parser.
9  *
10  * You can modify this class to customize your error reporting
11  * mechanisms so long as you retain the public fields.
12  */

13 public class ParseException extends com.genimen.djeneric.repository.exceptions.DjenericException
14 {
15   private static final long serialVersionUID = 3688788072401744689L;
16
17   /**
18    * This constructor is used by the method "generateParseException"
19    * in the generated parser. Calling this constructor generates
20    * a new object of this type with the fields "currentToken",
21    * "expectedTokenSequences", and "tokenImage" set. The boolean
22    * flag "specialConstructor" is also set to true to indicate that
23    * this constructor was used to create this object.
24    * This constructor calls its super class with the empty string
25    * to force the "toString" method of parent class "Throwable" to
26    * print the error message in the form:
27    * ParseException: <result of getMessage>
28    */

29   public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String JavaDoc[] tokenImageVal)
30   {
31     super("");
32     specialConstructor = true;
33     currentToken = currentTokenVal;
34     expectedTokenSequences = expectedTokenSequencesVal;
35     tokenImage = tokenImageVal;
36   }
37
38   /**
39    * The following constructors are for use by you for whatever
40    * purpose you can think of. Constructing the exception in this
41    * manner makes the exception behave in the normal way - i.e., as
42    * documented in the class "Throwable". The fields "errorToken",
43    * "expectedTokenSequences", and "tokenImage" do not contain
44    * relevant information. The JavaCC generated code does not use
45    * these constructors.
46    */

47
48   public ParseException()
49   {
50     super();
51     specialConstructor = false;
52   }
53
54   public ParseException(Exception JavaDoc x)
55   {
56     super(x);
57     specialConstructor = false;
58   }
59
60   public ParseException(String JavaDoc message)
61   {
62     super(message);
63     specialConstructor = false;
64   }
65
66   /**
67    * This variable determines which constructor was used to create
68    * this object and thereby affects the semantics of the
69    * "getMessage" method (see below).
70    */

71   protected boolean specialConstructor;
72
73   /**
74    * This is the last token that has been consumed successfully. If
75    * this object has been created due to a parse error, the token
76    * followng this token will (therefore) be the first error token.
77    */

78   public Token currentToken;
79
80   /**
81    * Each entry in this array is an array of integers. Each array
82    * of integers represents a sequence of tokens (by their ordinal
83    * values) that is expected at this point of the parse.
84    */

85   public int[][] expectedTokenSequences;
86
87   /**
88    * This is a reference to the "tokenImage" array of the generated
89    * parser within which the parse error occurred. This array is
90    * defined in the generated ...Constants interface.
91    */

92   public String JavaDoc[] tokenImage;
93
94   /**
95    * This method has the standard behavior when this object has been
96    * created using the standard constructors. Otherwise, it uses
97    * "currentToken" and "expectedTokenSequences" to generate a parse
98    * error message and returns it. If this object has been created
99    * due to a parse error, and you do not catch it (it gets thrown
100    * from the parser), then this method is called during the printing
101    * of the final stack trace, and hence the correct error message
102    * gets displayed.
103    */

104   public String JavaDoc getMessage()
105   {
106     if (!specialConstructor)
107     {
108       return super.getMessage();
109     }
110     String JavaDoc expected = "";
111     int maxSize = 0;
112     for (int i = 0; i < expectedTokenSequences.length; i++)
113     {
114       if (maxSize < expectedTokenSequences[i].length)
115       {
116         maxSize = expectedTokenSequences[i].length;
117       }
118       for (int j = 0; j < expectedTokenSequences[i].length; j++)
119       {
120         expected += tokenImage[expectedTokenSequences[i][j]] + " ";
121       }
122       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0)
123       {
124         expected += "...";
125       }
126       expected += eol + " ";
127     }
128     String JavaDoc retval = "Encountered \"";
129     Token tok = currentToken.next;
130     for (int i = 0; i < maxSize; i++)
131     {
132       if (i != 0) retval += " ";
133       if (tok.kind == 0)
134       {
135         retval += tokenImage[0];
136         break;
137       }
138       retval += add_escapes(tok.image);
139       tok = tok.next;
140     }
141     retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
142     retval += "." + eol;
143     if (expectedTokenSequences.length == 1)
144     {
145       retval += "Was expecting:" + eol + " ";
146     }
147     else
148     {
149       retval += "Was expecting one of:" + eol + " ";
150     }
151     retval += expected;
152     return retval;
153   }
154
155   /**
156    * The end of line string for this machine.
157    */

158   protected String JavaDoc eol = System.getProperty("line.separator", "\n");
159
160   /**
161    * Used to convert raw characters to their escaped version
162    * when these raw version cannot be used as part of an ASCII
163    * string literal.
164    */

165   protected String JavaDoc add_escapes(String JavaDoc str)
166   {
167     StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
168     char ch;
169     for (int i = 0; i < str.length(); i++)
170     {
171       switch (str.charAt(i))
172       {
173         case 0 :
174           continue;
175         case '\b' :
176           retval.append("\\b");
177           continue;
178         case '\t' :
179           retval.append("\\t");
180           continue;
181         case '\n' :
182           retval.append("\\n");
183           continue;
184         case '\f' :
185           retval.append("\\f");
186           continue;
187         case '\r' :
188           retval.append("\\r");
189           continue;
190         case '\"' :
191           retval.append("\\\"");
192           continue;
193         case '\'' :
194           retval.append("\\\'");
195           continue;
196         case '\\' :
197           retval.append("\\\\");
198           continue;
199         default :
200           if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e)
201           {
202             String JavaDoc s = "0000" + Integer.toString(ch, 16);
203             retval.append("\\u" + s.substring(s.length() - 4, s.length()));
204           }
205           else
206           {
207             retval.append(ch);
208           }
209           continue;
210       }
211     }
212     return retval.toString();
213   }
214
215 }
Popular Tags