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