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