TokenMgrError.java

  1. /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
  2. package gate.mimir.search.query.parser;

  3. public class TokenMgrError extends Error
  4. {
  5.    /*
  6.     * Ordinals for various reasons why an Error of this type can be thrown.
  7.     */

  8.    /**
  9.     * Lexical error occured.
  10.     */
  11.    static final int LEXICAL_ERROR = 0;

  12.    /**
  13.     * An attempt wass made to create a second instance of a static token manager.
  14.     */
  15.    static final int STATIC_LEXER_ERROR = 1;

  16.    /**
  17.     * Tried to change to an invalid lexical state.
  18.     */
  19.    static final int INVALID_LEXICAL_STATE = 2;

  20.    /**
  21.     * Detected (and bailed out of) an infinite loop in the token manager.
  22.     */
  23.    static final int LOOP_DETECTED = 3;

  24.    /**
  25.     * Indicates the reason why the exception is thrown. It will have
  26.     * one of the above 4 values.
  27.     */
  28.    int errorCode;

  29.    /**
  30.     * Replaces unprintable characters by their espaced (or unicode escaped)
  31.     * equivalents in the given string
  32.     */
  33.    protected static final String addEscapes(String str) {
  34.       StringBuffer retval = new StringBuffer();
  35.       char ch;
  36.       for (int i = 0; i < str.length(); i++) {
  37.         switch (str.charAt(i))
  38.         {
  39.            case 0 :
  40.               continue;
  41.            case '\b':
  42.               retval.append("\\b");
  43.               continue;
  44.            case '\t':
  45.               retval.append("\\t");
  46.               continue;
  47.            case '\n':
  48.               retval.append("\\n");
  49.               continue;
  50.            case '\f':
  51.               retval.append("\\f");
  52.               continue;
  53.            case '\r':
  54.               retval.append("\\r");
  55.               continue;
  56.            case '\"':
  57.               retval.append("\\\"");
  58.               continue;
  59.            case '\'':
  60.               retval.append("\\\'");
  61.               continue;
  62.            case '\\':
  63.               retval.append("\\\\");
  64.               continue;
  65.            default:
  66.               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
  67.                  String s = "0000" + Integer.toString(ch, 16);
  68.                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
  69.               } else {
  70.                  retval.append(ch);
  71.               }
  72.               continue;
  73.         }
  74.       }
  75.       return retval.toString();
  76.    }

  77.    /**
  78.     * Returns a detailed message for the Error when it is thrown by the
  79.     * token manager to indicate a lexical error.
  80.     * Parameters :
  81.     *    EOFSeen     : indicates if EOF caused the lexicl error
  82.     *    curLexState : lexical state in which this error occured
  83.     *    errorLine   : line number when the error occured
  84.     *    errorColumn : column number when the error occured
  85.     *    errorAfter  : prefix that was seen before this error occured
  86.     *    curchar     : the offending character
  87.     * Note: You can customize the lexical error message by modifying this method.
  88.     */
  89.    protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
  90.       return("Lexical error at line " +
  91.            errorLine + ", column " +
  92.            errorColumn + ".  Encountered: " +
  93.            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
  94.            "after : \"" + addEscapes(errorAfter) + "\"");
  95.    }

  96.    /**
  97.     * You can also modify the body of this method to customize your error messages.
  98.     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  99.     * of end-users concern, so you can return something like :
  100.     *
  101.     *     "Internal Error : Please file a bug report .... "
  102.     *
  103.     * from this method for such cases in the release version of your parser.
  104.     */
  105.    public String getMessage() {
  106.       return super.getMessage();
  107.    }

  108.    /*
  109.     * Constructors of various flavors follow.
  110.     */

  111.    public TokenMgrError() {
  112.    }

  113.    public TokenMgrError(String message, int reason) {
  114.       super(message);
  115.       errorCode = reason;
  116.    }

  117.    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
  118.       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  119.    }
  120. }