1 2 20 21 22 package org.apache.cayenne.exp.parser; 23 24 class TokenMgrError extends Error { 25 28 29 32 static final int LEXICAL_ERROR = 0; 33 34 37 static final int STATIC_LEXER_ERROR = 1; 38 39 42 static final int INVALID_LEXICAL_STATE = 2; 43 44 47 static final int LOOP_DETECTED = 3; 48 49 53 int errorCode; 54 55 59 protected static final String addEscapes(String str) { 60 StringBuffer retval = new StringBuffer (); 61 char ch; 62 for (int i = 0; i < str.length(); i++) { 63 switch (str.charAt(i)) { 64 case 0 : 65 continue; 66 case '\b' : 67 retval.append("\\b"); 68 continue; 69 case '\t' : 70 retval.append("\\t"); 71 continue; 72 case '\n' : 73 retval.append("\\n"); 74 continue; 75 case '\f' : 76 retval.append("\\f"); 77 continue; 78 case '\r' : 79 retval.append("\\r"); 80 continue; 81 case '\"' : 82 retval.append("\\\""); 83 continue; 84 case '\'' : 85 retval.append("\\\'"); 86 continue; 87 case '\\' : 88 retval.append("\\\\"); 89 continue; 90 default : 91 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 92 String s = "0000" + Integer.toString(ch, 16); 93 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 94 } 95 else { 96 retval.append(ch); 97 } 98 continue; 99 } 100 } 101 return retval.toString(); 102 } 103 104 116 protected static String LexicalError( 117 boolean EOFSeen, 118 int lexState, 119 int errorLine, 120 int errorColumn, 121 String errorAfter, 122 char curChar) { 123 return ( 124 "Lexical error at line " 125 + errorLine 126 + ", column " 127 + errorColumn 128 + ". Encountered: " 129 + (EOFSeen 130 ? "<EOF> " 131 : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") 132 + " (" 133 + (int) curChar 134 + "), ") 135 + "after : \"" 136 + addEscapes(errorAfter) 137 + "\""); 138 } 139 140 149 public String getMessage() { 150 return super.getMessage(); 151 } 152 153 156 157 public TokenMgrError() { 158 } 159 160 public TokenMgrError(String message, int reason) { 161 super(message); 162 errorCode = reason; 163 } 164 165 public TokenMgrError( 166 boolean EOFSeen, 167 int lexState, 168 int errorLine, 169 int errorColumn, 170 String errorAfter, 171 char curChar, 172 int reason) { 173 this( 174 LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), 175 reason); 176 } 177 } 178 | Popular Tags |