KickJava   Java API By Example, From Geeks To Geeks.

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


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

9
10   private static final long serialVersionUID = 3688506584624215603L;
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   public int line;
38   public int column;
39
40   /**
41    * Replaces unprintable characters by their espaced (or unicode escaped)
42    * equivalents in the given string
43    */

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

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

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

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