1 18 package org.apache.beehive.netui.script.el.parser; 19 20 import org.apache.beehive.netui.util.internal.InternalStringBuilder; 21 22 public class TokenMgrError 23 extends Error { 24 25 28 29 32 static final int LEXICAL_ERROR = 0; 33 34 37 static final int STATIC_LEXER_ERROR = 1; 38 39 42 static final int INVALID_LEXICAL_STATE = 2; 43 44 47 static final int LOOP_DETECTED = 3; 48 49 53 int errorCode; 54 55 59 protected static final String addEscapes(String str) { 60 InternalStringBuilder retval = new InternalStringBuilder(); 61 char ch; 62 for(int i = 0; i < str.length(); i++) { 63 switch(str.charAt(i)) { 64 case 0: 65 continue; 66 case '\b': 67 retval.append("\\b"); 68 continue; 69 case '\t': 70 retval.append("\\t"); 71 continue; 72 case '\n': 73 retval.append("\\n"); 74 continue; 75 case '\f': 76 retval.append("\\f"); 77 continue; 78 case '\r': 79 retval.append("\\r"); 80 continue; 81 case '\"': 82 retval.append("\\\""); 83 continue; 84 case '\'': 85 retval.append("\\\'"); 86 continue; 87 case '\\': 88 retval.append("\\\\"); 89 continue; 90 default: 91 if((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 92 String s = "0000" + Integer.toString(ch, 16); 93 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 94 } else { 95 retval.append(ch); 96 } 97 continue; 98 } 99 } 100 return retval.toString(); 101 } 102 103 115 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 116 return ("Lexical error at line " + 117 errorLine + ", column " + 118 errorColumn + ". Encountered: " + 119 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 120 "after : \"" + addEscapes(errorAfter) + "\""); 121 } 122 123 132 public String getMessage() { 133 return super.getMessage(); 134 } 135 136 139 140 public TokenMgrError() { 141 } 142 143 public TokenMgrError(String message, int reason) { 144 super(message); 145 errorCode = reason; 146 } 147 148 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 149 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 150 } 151 } 152 | Popular Tags |