001:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
002:// package com.tchibo.misc.lucene;
003:package vqwiki.utils.lucene;
004:
005:
006:/**
007: * TODO: Document this class.
008: *
009: * @version $Id: TokenMgrError.java 234 2003-04-15 23:11:06Z garethc $
010: */
011:public class TokenMgrError extends Error {
012:
013: /**
014: * Tried to change to an invalid lexical state.
015: */
016: final static int INVALID_LEXICAL_STATE = 2;
017: /*
018:* Ordinals for various reasons why an Error of this type can be thrown.
019:*/
020: /**
021: * Lexical error occured.
022: */
023: final static int LEXICAL_ERROR = 0;
024:
025: /**
026: * Detected (and bailed out of) an infinite loop in the token manager.
027: */
028: final static int LOOP_DETECTED = 3;
029:
030: /**
031: * An attempt wass made to create a second instance of a static token manager.
032: */
033: final static int STATIC_LEXER_ERROR = 1;
034:
035: /**
036: * Indicates the reason why the exception is thrown. It will have
037: * one of the above 4 values.
038: */
039: int errorCode;
040:
041: /*
042:* Constructors of various flavors follow.
043:*/
044: /**
045: *Creates a new TokenMgrError.
046: */
047: public TokenMgrError() {
048: }
049:
050: /**
051: *Creates a new TokenMgrError.
052: *
053: * @param message TODO: Document this parameter.
054: * @param reason TODO: Document this parameter.
055: */
056: public TokenMgrError(String message, int reason) {
057: super (message);
058: errorCode = reason;
059: }
060:
061: /**
062: *Creates a new TokenMgrError.
063: *
064: * @param EOFSeen TODO: Document this parameter.
065: * @param lexState TODO: Document this parameter.
066: * @param errorLine TODO: Document this parameter.
067: * @param errorColumn TODO: Document this parameter.
068: * @param errorAfter TODO: Document this parameter.
069: * @param curChar TODO: Document this parameter.
070: * @param reason TODO: Document this parameter.
071: */
072: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
073: this (LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
074: }
075:
076: /**
077: * Returns a detailed message for the Error when it is thrown by the
078: * token manager to indicate a lexical error.
079: * Parameters :
080: * EOFSeen : indicates if EOF caused the lexicl error
081: * curLexState : lexical state in which this error occured
082: * errorLine : line number when the error occured
083: * errorColumn : column number when the error occured
084: * errorAfter : prefix that was seen before this error occured
085: * curchar : the offending character
086: * Note: You can customize the lexical error message by modifying this method.
087: *
088: * @param EOFSeen TODO: Document this parameter.
089: * @param lexState TODO: Document this parameter.
090: * @param errorLine TODO: Document this parameter.
091: * @param errorColumn TODO: Document this parameter.
092: * @param errorAfter TODO: Document this parameter.
093: * @param curChar TODO: Document this parameter.
094: * @return TODO: Document the result.
095: */
096: private final static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
097: return ("Lexical error at line " +
098: errorLine + ", column " +
099: errorColumn + ". Encountered: " +
100: (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") +
101: "after : \"" + addEscapes(errorAfter) + "\"");
102: }
103:
104: /**
105: * Replaces unprintable characters by their espaced (or unicode escaped)
106: * equivalents in the given string
107: *
108: * @param str The feature to be added.
109: * @return TODO: Document the result.
110: */
111: protected final static String addEscapes(String str) {
112: StringBuffer retval = new StringBuffer();
113: char ch;
114: for (int i = 0; i < str.length(); i++) {
115: switch (str.charAt(i)) {
116: case 0:
117: continue;
118: case '\b':
119: retval.append("\\b");
120: continue;
121: case '\t':
122: retval.append("\\t");
123: continue;
124: case '\n':
125: retval.append("\\n");
126: continue;
127: case '\f':
128: retval.append("\\f");
129: continue;
130: case '\r':
131: retval.append("\\r");
132: continue;
133: case '\"':
134: retval.append("\\\"");
135: continue;
136: case '\'':
137: retval.append("\\\'");
138: continue;
139: case '\\':
140: retval.append("\\\\");
141: continue;
142: default:
143: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
144: String s = "0000" + Integer.toString(ch, 16);
145: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
146: }
147: else {
148: retval.append(ch);
149: }
150: continue;
151: }
152: }
153: return retval.toString();
154: }
155:
156: /**
157: * You can also modify the body of this method to customize your error messages.
158: * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
159: * of end-users concern, so you can return something like :
160: *
161: * "Internal Error : Please file a bug report .... "
162: *
163: * from this method for such cases in the release version of your parser.
164: *
165: * @return The Message.
166: */
167: public String getMessage() {
168: return super.getMessage();
169: }
170:}
|