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