View Javadoc

    1   /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */
    2   /* JavaCCOptions: */
    3   package net.sourceforge.pmd.ast;
    4
    5   /** Token Manager Error. */
    6   @SuppressWarnings("serial")
    7   public class TokenMgrError extends RuntimeException
    8   {
    9
    10     /*
    11      * Ordinals for various reasons why an Error of this type can be thrown.
    12      */
    13
    14     /**
    15      * Lexical error occurred.
    16      */
    17     static final int LEXICAL_ERROR = 0;
    18
    19     /**
    20      * An attempt was made to create a second instance of a static token manager.
    21      */
    22     static final int STATIC_LEXER_ERROR = 1;
    23
    24     /**
    25      * Tried to change to an invalid lexical state.
    26      */
    27     static final int INVALID_LEXICAL_STATE = 2;
    28
    29     /**
    30      * Detected (and bailed out of) an infinite loop in the token manager.
    31      */
    32     static final int LOOP_DETECTED = 3;
    33
    34     /**
    35      * Indicates the reason why the exception is thrown. It will have
    36      * one of the above 4 values.
    37      */
    38     int errorCode;
    39
    40     /**
    41      * Replaces unprintable characters by their escaped (or unicode escaped)
    42      * equivalents in the given string
    43      */
    44     protected static final String addEscapes(String str) {
    45        StringBuffer retval = new StringBuffer();
    46        char ch;
    47        for (int i = 0; i < str.length(); i++) {
    48          switch (str.charAt(i))
    49          {
    50             case 0 :
    51                continue;
    52             case '\b':
    53                retval.append("\\b");
    54                continue;
    55             case '\t':
    56                retval.append("\\t");
    57                continue;
    58             case '\n':
    59                retval.append("\\n");
    60                continue;
    61             case '\f':
    62                retval.append("\\f");
    63                continue;
    64             case '\r':
    65                retval.append("\\r");
    66                continue;
    67             case '\"':
    68                retval.append("\\\"");
    69                continue;
    70             case '\'':
    71                retval.append("\\\'");
    72                continue;
    73             case '\\':
    74                retval.append("\\\\");
    75                continue;
    76             default:
    77                if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
    78                   String s = "0000" + Integer.toString(ch, 16);
    79                   retval.append("\\u" + s.substring(s.length() - 4, s.length()));
    80                } else {
    81                   retval.append(ch);
    82                }
    83                continue;
    84          }
    85        }
    86        return retval.toString();
    87     }
    88
    89     /**
    90      * Returns a detailed message for the Error when it is thrown by the
    91      * token manager to indicate a lexical error.
    92      * Parameters :
    93      *    EOFSeen     : indicates if EOF caused the lexical error
    94      *    curLexState : lexical state in which this error occurred
    95      *    errorLine   : line number when the error occurred
    96      *    errorColumn : column number when the error occurred
    97      *    errorAfter  : prefix that was seen before this error occurred
    98      *    curchar     : the offending character
    99      * Note: You can customize the lexical error message by modifying this method.
    100     */
    101    protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
    102       return("Lexical error at line " +
    103            errorLine + ", column " +
    104            errorColumn + ".  Encountered: " +
    105            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
    106            "after : \"" + addEscapes(errorAfter) + "\"");
    107    }
    108
    109    /**
    110     * You can also modify the body of this method to customize your error messages.
    111     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
    112     * of end-users concern, so you can return something like :
    113     *
    114     *     "Internal Error : Please file a bug report .... "
    115     *
    116     * from this method for such cases in the release version of your parser.
    117     */
    118    public String getMessage() {
    119       return super.getMessage();
    120    }
    121
    122    /*
    123     * Constructors of various flavors follow.
    124     */
    125
    126    /** No arg constructor. */
    127    public TokenMgrError() {
    128    }
    129
    130    /** Constructor with message and reason. */
    131    public TokenMgrError(String message, int reason) {
    132       super(message);
    133       errorCode = reason;
    134    }
    135
    136    /** Full Constructor. */
    137    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
    138       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
    139    }
    140 }
    141 /* JavaCC - OriginalChecksum=d89e07f1292843b46af7dff7e1b97290 (do not edit this line) */