1 16 17 package org.apache.commons.jexl.parser; 18 19 public class TokenMgrError extends Error { 20 21 static final long serialVersionUID = 2843513002462329650L; 22 23 26 27 30 static final int LEXICAL_ERROR = 0; 31 32 36 static final int STATIC_LEXER_ERROR = 1; 37 38 41 static final int INVALID_LEXICAL_STATE = 2; 42 43 46 static final int LOOP_DETECTED = 3; 47 48 52 int errorCode; 53 54 58 protected static final String addEscapes(String str) { 59 StringBuffer retval = new StringBuffer (); 60 char ch; 61 for (int i = 0; i < str.length(); i++) { 62 switch (str.charAt(i)) { 63 case 0: 64 continue; 65 case '\b': 66 retval.append("\\b"); 67 continue; 68 case '\t': 69 retval.append("\\t"); 70 continue; 71 case '\n': 72 retval.append("\\n"); 73 continue; 74 case '\f': 75 retval.append("\\f"); 76 continue; 77 case '\r': 78 retval.append("\\r"); 79 continue; 80 case '\"': 81 retval.append("\\\""); 82 continue; 83 case '\'': 84 retval.append("\\\'"); 85 continue; 86 case '\\': 87 retval.append("\\\\"); 88 continue; 89 default: 90 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 91 String s = "0000" + Integer.toString(ch, 16); 92 retval.append("\\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 111 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, 112 String errorAfter, char curChar) { 113 return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " 114 + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") 115 + "after : \"" + addEscapes(errorAfter) + "\""); 116 } 117 118 127 public String getMessage() { 128 return super.getMessage(); 129 } 130 131 134 135 public TokenMgrError() { 136 } 137 138 public TokenMgrError(String message, int reason) { 139 super(message); 140 errorCode = reason; 141 } 142 143 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, 144 char curChar, int reason) { 145 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 146 } 147 } 148 | Popular Tags |