001package jtb; 002 003/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ 004public class TokenMgrError extends Error 005{ 006 // Added by hand to remove serialize warning. (markro) 007 static final long serialVersionUID = 20150406L; 008 009 /* 010 * Ordinals for various reasons why an Error of this type can be thrown. 011 */ 012 013 /** 014 * Lexical error occured. 015 */ 016 static final int LEXICAL_ERROR = 0; 017 018 /** 019 * An attempt wass made to create a second instance of a static token manager. 020 */ 021 static final int STATIC_LEXER_ERROR = 1; 022 023 /** 024 * Tried to change to an invalid lexical state. 025 */ 026 static final int INVALID_LEXICAL_STATE = 2; 027 028 /** 029 * Detected (and bailed out of) an infinite loop in the token manager. 030 */ 031 static final int LOOP_DETECTED = 3; 032 033 /** 034 * Indicates the reason why the exception is thrown. It will have 035 * one of the above 4 values. 036 */ 037 int errorCode; 038 039 /** 040 * Replaces unprintable characters by their espaced (or unicode escaped) 041 * equivalents in the given string 042 */ 043 protected static final String addEscapes(String str) { 044 StringBuffer retval = new StringBuffer(); 045 char ch; 046 for (int i = 0; i < str.length(); i++) { 047 switch (str.charAt(i)) 048 { 049 case 0 : 050 continue; 051 case '\b': 052 retval.append("\\b"); 053 continue; 054 case '\t': 055 retval.append("\\t"); 056 continue; 057 case '\n': 058 retval.append("\\n"); 059 continue; 060 case '\f': 061 retval.append("\\f"); 062 continue; 063 case '\r': 064 retval.append("\\r"); 065 continue; 066 case '\"': 067 retval.append("\\\""); 068 continue; 069 case '\'': 070 retval.append("\\\'"); 071 continue; 072 case '\\': 073 retval.append("\\\\"); 074 continue; 075 default: 076 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 077 String s = "0000" + Integer.toString(ch, 16); 078 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 079 } else { 080 retval.append(ch); 081 } 082 continue; 083 } 084 } 085 return retval.toString(); 086 } 087 088 /** 089 * Returns a detailed message for the Error when it is thrown by the 090 * token manager to indicate a lexical error. 091 * Parameters : 092 * EOFSeen : indicates if EOF caused the lexicl error 093 * curLexState : lexical state in which this error occured 094 * errorLine : line number when the error occured 095 * errorColumn : column number when the error occured 096 * errorAfter : prefix that was seen before this error occured 097 * curchar : the offending character 098 * Note: You can customize the lexical error message by modifying this method. 099 */ 100 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 101 return("Lexical error at line " + 102 errorLine + ", column " + 103 errorColumn + ". Encountered: " + 104 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 105 "after : \"" + addEscapes(errorAfter) + "\""); 106 } 107 108 /** 109 * You can also modify the body of this method to customize your error messages. 110 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 111 * of end-users concern, so you can return something like : 112 * 113 * "Internal Error : Please file a bug report .... " 114 * 115 * from this method for such cases in the release version of your parser. 116 */ 117 public String getMessage() { 118 return super.getMessage(); 119 } 120 121 /* 122 * Constructors of various flavors follow. 123 */ 124 125 public TokenMgrError() { 126 } 127 128 public TokenMgrError(String message, int reason) { 129 super(message); 130 errorCode = reason; 131 } 132 133 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 134 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 135 } 136}