KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2 package com.genimen.djeneric.repository.sqlparser.core;
3
4 public class TokenMgrError extends Error JavaDoc
5 {
6   private static final long serialVersionUID = 1L;
7
8   /*
9    * Ordinals for various reasons why an Error of this type can be thrown.
10    */

11
12   /**
13    * Lexical error occured.
14    */

15   static final int LEXICAL_ERROR = 0;
16
17   /**
18    * An attempt wass made to create a second instance of a static token manager.
19    */

20   static final int STATIC_LEXER_ERROR = 1;
21
22   /**
23    * Tried to change to an invalid lexical state.
24    */

25   static final int INVALID_LEXICAL_STATE = 2;
26
27   /**
28    * Detected (and bailed out of) an infinite loop in the token manager.
29    */

30   static final int LOOP_DETECTED = 3;
31
32   /**
33    * Indicates the reason why the exception is thrown. It will have
34    * one of the above 4 values.
35    */

36   int errorCode;
37
38   /**
39    * Replaces unprintable characters by their espaced (or unicode escaped)
40    * equivalents in the given string
41    */

42   protected static final String JavaDoc addEscapes(String JavaDoc str)
43   {
44     StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
45     char ch;
46     for (int i = 0; i < str.length(); i++)
47     {
48       switch (str.charAt(i))
49       {
50         case 0 :
51           continue;
52         case '\b' :
53           retval.append("\\b");
54           continue;
55         case '\t' :
56           retval.append("\\t");
57           continue;
58         case '\n' :
59           retval.append("\\n");
60           continue;
61         case '\f' :
62           retval.append("\\f");
63           continue;
64         case '\r' :
65           retval.append("\\r");
66           continue;
67         case '\"' :
68           retval.append("\\\"");
69           continue;
70         case '\'' :
71           retval.append("\\\'");
72           continue;
73         case '\\' :
74           retval.append("\\\\");
75           continue;
76         default :
77           if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e)
78           {
79             String JavaDoc s = "0000" + Integer.toString(ch, 16);
80             retval.append("\\u" + s.substring(s.length() - 4, s.length()));
81           }
82           else
83           {
84             retval.append(ch);
85           }
86           continue;
87       }
88     }
89     return retval.toString();
90   }
91
92   /**
93    * Returns a detailed message for the Error when it is thrown by the
94    * token manager to indicate a lexical error.
95    * Parameters :
96    * EOFSeen : indicates if EOF caused the lexicl error
97    * curLexState : lexical state in which this error occured
98    * errorLine : line number when the error occured
99    * errorColumn : column number when the error occured
100    * errorAfter : prefix that was seen before this error occured
101    * curchar : the offending character
102    * Note: You can customize the lexical error message by modifying this method.
103    */

104   protected static String JavaDoc LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn,
105                                        String JavaDoc errorAfter, char curChar)
106   {
107     return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: "
108             + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ")
109             + "after : \"" + addEscapes(errorAfter) + "\"");
110   }
111
112   /**
113    * You can also modify the body of this method to customize your error messages.
114    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
115    * of end-users concern, so you can return something like :
116    *
117    * "Internal Error : Please file a bug report .... "
118    *
119    * from this method for such cases in the release version of your parser.
120    */

121   public String JavaDoc getMessage()
122   {
123     return super.getMessage();
124   }
125
126   /*
127    * Constructors of various flavors follow.
128    */

129
130   public TokenMgrError()
131   {
132   }
133
134   public TokenMgrError(String JavaDoc message, int reason)
135   {
136     super(message);
137     errorCode = reason;
138   }
139
140   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar,
141                        int reason)
142   {
143     this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
144   }
145 }
Popular Tags