1 2 8 package org.codehaus.aspectwerkz.expression.ast; 9 10 public class TokenMgrError extends Error { 11 14 15 18 static final int LEXICAL_ERROR = 0; 19 20 23 static final int STATIC_LEXER_ERROR = 1; 24 25 28 static final int INVALID_LEXICAL_STATE = 2; 29 30 33 static final int LOOP_DETECTED = 3; 34 35 38 int errorCode; 39 40 43 protected static final String addEscapes(String str) { 44 StringBuffer retval = new StringBuffer (); 45 char ch; 46 for (int i = 0; i < str.length(); i++) { 47 switch (str.charAt(i)) { 48 case 0: 49 continue; 50 case '\b': 51 retval.append("\\b"); 52 continue; 53 case '\t': 54 retval.append("\\t"); 55 continue; 56 case '\n': 57 retval.append("\\n"); 58 continue; 59 case '\f': 60 retval.append("\\f"); 61 continue; 62 case '\r': 63 retval.append("\\r"); 64 continue; 65 case '\"': 66 retval.append("\\\""); 67 continue; 68 case '\'': 69 retval.append("\\\'"); 70 continue; 71 case '\\': 72 retval.append("\\\\"); 73 continue; 74 default: 75 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 76 String s = "0000" + Integer.toString(ch, 16); 77 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 78 } else { 79 retval.append(ch); 80 } 81 continue; 82 } 83 } 84 return retval.toString(); 85 } 86 87 94 protected static String LexicalError(boolean EOFSeen, 95 int lexState, 96 int errorLine, 97 int errorColumn, 98 String errorAfter, 99 char curChar) { 100 return ("Lexical error at line " 101 + errorLine 102 + ", column " 103 + errorColumn 104 + ". Encountered: " 105 + 106 (EOFSeen ? 107 "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") 108 + "after : \"" 109 + addEscapes(errorAfter) + "\""); 110 } 111 112 118 public String getMessage() { 119 return super.getMessage(); 120 } 121 122 125 126 public TokenMgrError() { 127 } 128 129 public TokenMgrError(String message, int reason) { 130 super(message); 131 errorCode = reason; 132 } 133 134 public TokenMgrError(boolean EOFSeen, 135 int lexState, 136 int errorLine, 137 int errorColumn, 138 String errorAfter, 139 char curChar, 140 int reason) { 141 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 142 } 143 } | Popular Tags |