001:package org.mandarax.jdbc.server.parser;
002:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
003:public class TokenMgrError extends Error
004:{
005: /*
006: * Ordinals for various reasons why an Error of this type can be thrown.
007: */
008:
009: /**
010: * Lexical error occured.
011: */
012: static final int LEXICAL_ERROR = 0;
013:
014: /**
015: * An attempt wass made to create a second instance of a static token manager.
016: */
017: static final int STATIC_LEXER_ERROR = 1;
018:
019: /**
020: * Tried to change to an invalid lexical state.
021: */
022: static final int INVALID_LEXICAL_STATE = 2;
023:
024: /**
025: * Detected (and bailed out of) an infinite loop in the token manager.
026: */
027: static final int LOOP_DETECTED = 3;
028:
029: /**
030: * Indicates the reason why the exception is thrown. It will have
031: * one of the above 4 values.
032: */
033: int errorCode;
034:
035: /**
036: * Replaces unprintable characters by their espaced (or unicode escaped)
037: * equivalents in the given string
038: */
039: protected static final String addEscapes(String str) {
040: StringBuffer retval = new StringBuffer();
041: char ch;
042: for (int i = 0; i < str.length(); i++) {
043: switch (str.charAt(i))
044: {
045: case 0 :
046: continue;
047: case '\b':
048: retval.append("\\b");
049: continue;
050: case '\t':
051: retval.append("\\t");
052: continue;
053: case '\n':
054: retval.append("\\n");
055: continue;
056: case '\f':
057: retval.append("\\f");
058: continue;
059: case '\r':
060: retval.append("\\r");
061: continue;
062: case '\"':
063: retval.append("\\\"");
064: continue;
065: case '\'':
066: retval.append("\\\'");
067: continue;
068: case '\\':
069: retval.append("\\\\");
070: continue;
071: default:
072: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
073: String s = "0000" + Integer.toString(ch, 16);
074: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
075: } else {
076: retval.append(ch);
077: }
078: continue;
079: }
080: }
081: return retval.toString();
082: }
083:
084: /**
085: * Returns a detailed message for the Error when it is thrown by the
086: * token manager to indicate a lexical error.
087: * Parameters :
088: * EOFSeen : indicates if EOF caused the lexicl error
089: * curLexState : lexical state in which this error occured
090: * errorLine : line number when the error occured
091: * errorColumn : column number when the error occured
092: * errorAfter : prefix that was seen before this error occured
093: * curchar : the offending character
094: * Note: You can customize the lexical error message by modifying this method.
095: */
096: protected 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: * You can also modify the body of this method to customize your error messages.
106: * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
107: * of end-users concern, so you can return something like :
108: *
109: * "Internal Error : Please file a bug report .... "
110: *
111: * from this method for such cases in the release version of your parser.
112: */
113: public String getMessage() {
114: return super .getMessage();
115: }
116:
117: /*
118: * Constructors of various flavors follow.
119: */
120:
121: public TokenMgrError() {
122: }
123:
124: public TokenMgrError(String message, int reason) {
125: super (message);
126: errorCode = reason;
127: }
128:
129: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
130: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
131: }
132:}
|