KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > scriptengine > core > TokenMgrError


1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
2 package com.genimen.djeneric.tools.scriptengine.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   private static final long serialVersionUID = 1L;
10
11   /**
12    * Lexical error occured.
13    */

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

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

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

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

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

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

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

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

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