001:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
002:package com.jeta.forms.gui.common.parsers;
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
016: * manager.
017: */
018: static final int STATIC_LEXER_ERROR = 1;
019:
020: /**
021: * Tried to change to an invalid lexical state.
022: */
023: static final int INVALID_LEXICAL_STATE = 2;
024:
025: /**
026: * Detected (and bailed out of) an infinite loop in the token manager.
027: */
028: static final int LOOP_DETECTED = 3;
029:
030: /**
031: * Indicates the reason why the exception is thrown. It will have one of the
032: * above 4 values.
033: */
034: int errorCode;
035:
036: /**
037: * Replaces unprintable characters by their espaced (or unicode escaped)
038: * equivalents in the given string
039: */
040: protected static final String addEscapes(String str) {
041: StringBuffer retval = new StringBuffer();
042: char ch;
043: for (int i = 0; i < str.length(); i++) {
044: switch (str.charAt(i)) {
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: }
076: else {
077: retval.append(ch);
078: }
079: continue;
080: }
081: }
082: return retval.toString();
083: }
084:
085: /**
086: * Returns a detailed message for the Error when it is thrown by the token
087: * manager to indicate a lexical error. Parameters : EOFSeen : indicates if
088: * EOF caused the lexicl error curLexState : lexical state in which this
089: * error occured errorLine : line number when the error occured errorColumn :
090: * column number when the error occured errorAfter : prefix that was seen
091: * before this error occured curchar : the offending character Note: You can
092: * customize the lexical error message by modifying this method.
093: */
094: protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
095: return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: "
096: + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \""
097: + addEscapes(errorAfter) + "\"");
098: }
099:
100: /**
101: * You can also modify the body of this method to customize your error
102: * messages. For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE
103: * are not of end-users concern, so you can return something like :
104: *
105: * "Internal Error : Please file a bug report .... "
106: *
107: * from this method for such cases in the release version of your parser.
108: */
109: public String getMessage() {
110: return super .getMessage();
111: }
112:
113: /*
114: * Constructors of various flavors follow.
115: */
116:
117: public TokenMgrError() {
118: }
119:
120: public TokenMgrError(String message, int reason) {
121: super (message);
122: errorCode = reason;
123: }
124:
125: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
126: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
127: }
128:}
|