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