1 2 3 21 22 23 package org.apache.cayenne.wocompat.parser; 24 25 public class TokenMgrError extends Error 26 { 27 30 31 34 static final int LEXICAL_ERROR = 0; 35 36 39 static final int STATIC_LEXER_ERROR = 1; 40 41 44 static final int INVALID_LEXICAL_STATE = 2; 45 46 49 static final int LOOP_DETECTED = 3; 50 51 55 int errorCode; 56 57 61 protected static final String addEscapes(String str) { 62 StringBuffer retval = new StringBuffer (); 63 char ch; 64 for (int i = 0; i < str.length(); i++) { 65 switch (str.charAt(i)) 66 { 67 case 0 : 68 continue; 69 case '\b': 70 retval.append("\\b"); 71 continue; 72 case '\t': 73 retval.append("\\t"); 74 continue; 75 case '\n': 76 retval.append("\\n"); 77 continue; 78 case '\f': 79 retval.append("\\f"); 80 continue; 81 case '\r': 82 retval.append("\\r"); 83 continue; 84 case '\"': 85 retval.append("\\\""); 86 continue; 87 case '\'': 88 retval.append("\\\'"); 89 continue; 90 case '\\': 91 retval.append("\\\\"); 92 continue; 93 default: 94 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 95 String s = "0000" + Integer.toString(ch, 16); 96 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 97 } else { 98 retval.append(ch); 99 } 100 continue; 101 } 102 } 103 return retval.toString(); 104 } 105 106 118 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 119 return("Lexical error at line " + 120 errorLine + ", column " + 121 errorColumn + ". Encountered: " + 122 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 123 "after : \"" + addEscapes(errorAfter) + "\""); 124 } 125 126 135 public String getMessage() { 136 return super.getMessage(); 137 } 138 139 142 143 public TokenMgrError() { 144 } 145 146 public TokenMgrError(String message, int reason) { 147 super(message); 148 errorCode = reason; 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, errorAfter, curChar), reason); 153 } 154 } 155 | Popular Tags |