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