00001 package edu.ksu.cis.bandera.abstraction.predicate.parser;
00002
00003
00004 public class TokenMgrError extends Error
00005 {
00006
00007
00008
00009
00010
00011
00012
00013 static final int LEXICAL_ERROR = 0;
00014
00015
00016
00017
00018 static final int STATIC_LEXER_ERROR = 1;
00019
00020
00021
00022
00023 static final int INVALID_LEXICAL_STATE = 2;
00024
00025
00026
00027
00028 static final int LOOP_DETECTED = 3;
00029
00030
00031
00032
00033
00034 int errorCode;
00035
00036
00037
00038
00039
00040 public TokenMgrError() {
00041 }
00042 public TokenMgrError(String message, int reason) {
00043 super(message);
00044 errorCode = reason;
00045 }
00046 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
00047 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
00048 }
00049
00050
00051
00052
00053 protected static final String addEscapes(String str) {
00054 StringBuffer retval = new StringBuffer();
00055 char ch;
00056 for (int i = 0; i < str.length(); i++) {
00057 switch (str.charAt(i))
00058 {
00059 case 0 :
00060 continue;
00061 case '\b':
00062 retval.append("\\b");
00063 continue;
00064 case '\t':
00065 retval.append("\\t");
00066 continue;
00067 case '\n':
00068 retval.append("\\n");
00069 continue;
00070 case '\f':
00071 retval.append("\\f");
00072 continue;
00073 case '\r':
00074 retval.append("\\r");
00075 continue;
00076 case '\"':
00077 retval.append("\\\"");
00078 continue;
00079 case '\'':
00080 retval.append("\\\'");
00081 continue;
00082 case '\\':
00083 retval.append("\\\\");
00084 continue;
00085 default:
00086 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
00087 String s = "0000" + Integer.toString(ch, 16);
00088 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
00089 } else {
00090 retval.append(ch);
00091 }
00092 continue;
00093 }
00094 }
00095 return retval.toString();
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 public String getMessage() {
00107 return super.getMessage();
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
00122 return("Lexical error at line " +
00123 errorLine + ", column " +
00124 errorColumn + ". Encountered: " +
00125 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
00126 "after : \"" + addEscapes(errorAfter) + "\"");
00127 }
00128 }