1 2 3 25 26 package net.sourceforge.cobertura.javancss; 27 28 class TokenMgrError extends Error 29 { 30 31 private static final long serialVersionUID = 0L; 32 33 36 37 40 static final int LEXICAL_ERROR = 0; 41 42 45 static final int STATIC_LEXER_ERROR = 1; 46 47 50 static final int INVALID_LEXICAL_STATE = 2; 51 52 55 static final int LOOP_DETECTED = 3; 56 57 61 int errorCode; 62 63 67 static final String addEscapes(String str) 68 { 69 StringBuffer retval = new StringBuffer (); 70 char ch; 71 for (int i = 0; i < str.length(); i++) 72 { 73 switch (str.charAt(i)) 74 { 75 case 0: 76 continue; 77 case '\b': 78 retval.append("\\b"); 79 continue; 80 case '\t': 81 retval.append("\\t"); 82 continue; 83 case '\n': 84 retval.append("\\n"); 85 continue; 86 case '\f': 87 retval.append("\\f"); 88 continue; 89 case '\r': 90 retval.append("\\r"); 91 continue; 92 case '\"': 93 retval.append("\\\""); 94 continue; 95 case '\'': 96 retval.append("\\\'"); 97 continue; 98 case '\\': 99 retval.append("\\\\"); 100 continue; 101 default: 102 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) 103 { 104 String s = "0000" + Integer.toString(ch, 16); 105 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 106 } 107 else 108 { 109 retval.append(ch); 110 } 111 continue; 112 } 113 } 114 return retval.toString(); 115 } 116 117 129 private static final String LexicalError(boolean EOFSeen, int errorLine, int errorColumn, 130 String errorAfter, char curChar) 131 { 132 return ("Lexical error at line " 133 + errorLine 134 + ", column " 135 + errorColumn 136 + ". Encountered: " 137 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" 138 + (int)curChar + "), ") + "after : \"" + addEscapes(errorAfter) + "\""); 139 } 140 141 150 public String getMessage() 151 { 152 return super.getMessage(); 153 } 154 155 158 159 TokenMgrError() 160 { 161 } 162 163 TokenMgrError(String message, int reason) 164 { 165 super(message); 166 errorCode = reason; 167 } 168 169 TokenMgrError(boolean EOFSeen, int errorLine, int errorColumn, String errorAfter, char curChar, 170 int reason) 171 { 172 this(LexicalError(EOFSeen, errorLine, errorColumn, errorAfter, curChar), reason); 173 } 174 } 175 | Popular Tags |