1 2 package com.genimen.djeneric.tools.generator.core; 3 4 public class TokenMgrError extends Error 5 { 6 private static final long serialVersionUID = 1L; 7 10 11 14 static final int LEXICAL_ERROR = 0; 15 16 19 static final int STATIC_LEXER_ERROR = 1; 20 21 24 static final int INVALID_LEXICAL_STATE = 2; 25 26 29 static final int LOOP_DETECTED = 3; 30 31 35 int errorCode; 36 37 41 protected static final String addEscapes(String str) 42 { 43 StringBuffer retval = new StringBuffer (); 44 char ch; 45 for (int i = 0; i < str.length(); i++) 46 { 47 switch (str.charAt(i)) 48 { 49 case 0 : 50 continue; 51 case '\b' : 52 retval.append("\\b"); 53 continue; 54 case '\t' : 55 retval.append("\\t"); 56 continue; 57 case '\n' : 58 retval.append("\\n"); 59 continue; 60 case '\f' : 61 retval.append("\\f"); 62 continue; 63 case '\r' : 64 retval.append("\\r"); 65 continue; 66 case '\"' : 67 retval.append("\\\""); 68 continue; 69 case '\'' : 70 retval.append("\\\'"); 71 continue; 72 case '\\' : 73 retval.append("\\\\"); 74 continue; 75 default : 76 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) 77 { 78 String s = "0000" + Integer.toString(ch, 16); 79 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 80 } 81 else 82 { 83 retval.append(ch); 84 } 85 continue; 86 } 87 } 88 return retval.toString(); 89 } 90 91 103 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, 104 String errorAfter, char curChar) 105 { 106 return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " 107 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") 108 + "after : \"" + addEscapes(errorAfter) + "\""); 109 } 110 111 120 public String getMessage() 121 { 122 return super.getMessage(); 123 } 124 125 128 129 public TokenMgrError() 130 { 131 } 132 133 public TokenMgrError(String message, int reason) 134 { 135 super(message); 136 errorCode = reason; 137 } 138 139 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, 140 int reason) 141 { 142 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 143 } 144 } | Popular Tags |