1 2 17 package com.lutris.util; 18 19 public class TokenMgrError extends Error 20 { 21 24 25 28 static final int LEXICAL_ERROR = 0; 29 30 33 static final int STATIC_LEXER_ERROR = 1; 34 35 38 static final int INVALID_LEXICAL_STATE = 2; 39 40 43 static final int LOOP_DETECTED = 3; 44 45 49 int errorCode; 50 51 55 protected static final String addEscapes(String str) { 56 StringBuffer retval = new StringBuffer (); 57 char ch; 58 for (int i = 0; i < str.length(); i++) { 59 switch (str.charAt(i)) 60 { 61 case 0 : 62 continue; 63 case '\b': 64 retval.append("\\b"); 65 continue; 66 case '\t': 67 retval.append("\\t"); 68 continue; 69 case '\n': 70 retval.append("\\n"); 71 continue; 72 case '\f': 73 retval.append("\\f"); 74 continue; 75 case '\r': 76 retval.append("\\r"); 77 continue; 78 case '\"': 79 retval.append("\\\""); 80 continue; 81 case '\'': 82 retval.append("\\\'"); 83 continue; 84 case '\\': 85 retval.append("\\\\"); 86 continue; 87 default: 88 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 89 String s = "0000" + Integer.toString(ch, 16); 90 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 91 } else { 92 retval.append(ch); 93 } 94 continue; 95 } 96 } 97 return retval.toString(); 98 } 99 100 112 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 113 return("Lexical error at line " + 114 errorLine + ", column " + 115 errorColumn + ". Encountered: " + 116 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 117 "after : \"" + addEscapes(errorAfter) + "\""); 118 } 119 120 129 public String getMessage() { 130 return super.getMessage(); 131 } 132 133 136 137 public TokenMgrError() { 138 } 139 140 public TokenMgrError(String message, int reason) { 141 super(message); 142 errorCode = reason; 143 } 144 145 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 146 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 147 } 148 } 149 | Popular Tags |