001:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
002:package org.objectweb.speedo.query.jdo.parser;
003:
004:public class TokenMgrError extends Error {
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: case 0:
045: continue;
046: case '\b':
047: retval.append("\\b");
048: continue;
049: case '\t':
050: retval.append("\\t");
051: continue;
052: case '\n':
053: retval.append("\\n");
054: continue;
055: case '\f':
056: retval.append("\\f");
057: continue;
058: case '\r':
059: retval.append("\\r");
060: continue;
061: case '\"':
062: retval.append("\\\"");
063: continue;
064: case '\'':
065: retval.append("\\\'");
066: continue;
067: case '\\':
068: retval.append("\\\\");
069: continue;
070: default:
071: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
072: String s = "0000" + Integer.toString(ch, 16);
073: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
074: } else {
075: retval.append(ch);
076: }
077: continue;
078: }
079: }
080: return retval.toString();
081: }
082:
083: /**
084: * Returns a detailed message for the Error when it is thrown by the
085: * token manager to indicate a lexical error.
086: * Parameters :
087: * EOFSeen : indicates if EOF caused the lexicl error
088: * curLexState : lexical state in which this error occured
089: * errorLine : line number when the error occured
090: * errorColumn : column number when the error occured
091: * errorAfter : prefix that was seen before this error occured
092: * curchar : the offending character
093: * Note: You can customize the lexical error message by modifying this method.
094: */
095: private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
096: return ("Lexical error at line " +
097: errorLine + ", column " +
098: errorColumn + ". Encountered: " +
099: (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") +
100: "after : \"" + addEscapes(errorAfter) + "\"");
101: }
102:
103: /**
104: * You can also modify the body of this method to customize your error messages.
105: * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
106: * of end-users concern, so you can return something like :
107: *
108: * "Internal Error : Please file a bug report .... "
109: *
110: * from this method for such cases in the release version of your parser.
111: */
112: public String getMessage() {
113: return super .getMessage();
114: }
115:
116: /*
117: * Constructors of various flavors follow.
118: */
119:
120: public TokenMgrError() {
121: }
122:
123: public TokenMgrError(String message, int reason) {
124: super (message);
125: errorCode = reason;
126: }
127:
128: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
129: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
130: }
131:}
|