1 2 57 58 package org.objectstyle.cayenne.exp.parser; 59 60 class TokenMgrError extends Error { 61 64 65 68 static final int LEXICAL_ERROR = 0; 69 70 73 static final int STATIC_LEXER_ERROR = 1; 74 75 78 static final int INVALID_LEXICAL_STATE = 2; 79 80 83 static final int LOOP_DETECTED = 3; 84 85 89 int errorCode; 90 91 95 protected static final String addEscapes(String str) { 96 StringBuffer retval = new StringBuffer (); 97 char ch; 98 for (int i = 0; i < str.length(); i++) { 99 switch (str.charAt(i)) { 100 case 0 : 101 continue; 102 case '\b' : 103 retval.append("\\b"); 104 continue; 105 case '\t' : 106 retval.append("\\t"); 107 continue; 108 case '\n' : 109 retval.append("\\n"); 110 continue; 111 case '\f' : 112 retval.append("\\f"); 113 continue; 114 case '\r' : 115 retval.append("\\r"); 116 continue; 117 case '\"' : 118 retval.append("\\\""); 119 continue; 120 case '\'' : 121 retval.append("\\\'"); 122 continue; 123 case '\\' : 124 retval.append("\\\\"); 125 continue; 126 default : 127 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 128 String s = "0000" + Integer.toString(ch, 16); 129 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 130 } 131 else { 132 retval.append(ch); 133 } 134 continue; 135 } 136 } 137 return retval.toString(); 138 } 139 140 152 protected static String LexicalError( 153 boolean EOFSeen, 154 int lexState, 155 int errorLine, 156 int errorColumn, 157 String errorAfter, 158 char curChar) { 159 return ( 160 "Lexical error at line " 161 + errorLine 162 + ", column " 163 + errorColumn 164 + ". Encountered: " 165 + (EOFSeen 166 ? "<EOF> " 167 : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") 168 + " (" 169 + (int) curChar 170 + "), ") 171 + "after : \"" 172 + addEscapes(errorAfter) 173 + "\""); 174 } 175 176 185 public String getMessage() { 186 return super.getMessage(); 187 } 188 189 192 193 public TokenMgrError() { 194 } 195 196 public TokenMgrError(String message, int reason) { 197 super(message); 198 errorCode = reason; 199 } 200 201 public TokenMgrError( 202 boolean EOFSeen, 203 int lexState, 204 int errorLine, 205 int errorColumn, 206 String errorAfter, 207 char curChar, 208 int reason) { 209 this( 210 LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), 211 reason); 212 } 213 } 214 | Popular Tags |