1 16 package org.apache.cocoon.components.xpointer.parser; 17 18 22 public class TokenMgrError extends Error { 23 26 27 30 static final int LEXICAL_ERROR = 0; 31 32 35 static final int STATIC_LEXER_ERROR = 1; 36 37 40 static final int INVALID_LEXICAL_STATE = 2; 41 42 45 static final int LOOP_DETECTED = 3; 46 47 51 int errorCode; 52 53 57 protected static final String addEscapes(String str) { 58 StringBuffer retval = new StringBuffer (); 59 char ch; 60 for (int i = 0; i < str.length(); i++) { 61 switch (str.charAt(i)) { 62 case 0 : 63 continue; 64 case '\b' : 65 retval.append("\\b"); 66 continue; 67 case '\t' : 68 retval.append("\\t"); 69 continue; 70 case '\n' : 71 retval.append("\\n"); 72 continue; 73 case '\f' : 74 retval.append("\\f"); 75 continue; 76 case '\r' : 77 retval.append("\\r"); 78 continue; 79 case '\"' : 80 retval.append("\\\""); 81 continue; 82 case '\'' : 83 retval.append("\\\'"); 84 continue; 85 case '\\' : 86 retval.append("\\\\"); 87 continue; 88 default : 89 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 90 String s = "0000" + Integer.toString(ch, 16); 91 retval.append( 92 "\\u" + s.substring(s.length() - 4, s.length())); 93 } else { 94 retval.append(ch); 95 } 96 continue; 97 } 98 } 99 return retval.toString(); 100 } 101 102 114 protected static String lexicalError( 115 boolean EOFSeen, 116 int lexState, 117 int errorLine, 118 int errorColumn, 119 String errorAfter, 120 char curChar) { 121 return ( 122 "Lexical error at line " 123 + errorLine 124 + ", column " 125 + errorColumn 126 + ". Encountered: " 127 + (EOFSeen 128 ? "<EOF> " 129 : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") 130 + " (" 131 + (int) curChar 132 + "), ") 133 + "after : \"" 134 + addEscapes(errorAfter) 135 + "\""); 136 } 137 138 147 public String getMessage() { 148 return super.getMessage(); 149 } 150 151 154 155 public TokenMgrError() { 156 } 157 158 public TokenMgrError(String message, int reason) { 159 super(message); 160 errorCode = reason; 161 } 162 163 public TokenMgrError( 164 boolean EOFSeen, 165 int lexState, 166 int errorLine, 167 int errorColumn, 168 String errorAfter, 169 char curChar, 170 int reason) { 171 this( 172 lexicalError( 173 EOFSeen, 174 lexState, 175 errorLine, 176 errorColumn, 177 errorAfter, 178 curChar), 179 reason); 180 } 181 } 182 | Popular Tags |