001/*
002 * Cobertura - http://cobertura.sourceforge.net/
003 *
004 * This file was taken from JavaNCSS
005 * http://www.kclee.com/clemens/java/javancss/
006 * Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
007 *
008 * Cobertura is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License as published
010 * by the Free Software Foundation; either version 2 of the License,
011 * or (at your option) any later version.
012 *
013 * Cobertura is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016 * General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with Cobertura; if not, write to the Free Software
020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021 * USA
022 */
023
024
025/*
026 *
027 * WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING  
028 *
029 * WARNING TO COBERTURA DEVELOPERS
030 *
031 * DO NOT MODIFY THIS FILE!
032 *
033 * MODIFY THE FILES UNDER THE JAVANCSS DIRECTORY LOCATED AT THE ROOT OF THE COBERTURA PROJECT.
034 *
035 * FOLLOW THE PROCEDURE FOR MERGING THE LATEST JAVANCSS INTO COBERTURA LOCATED AT
036 * javancss/coberturaREADME.txt
037 *
038 * WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   
039 */
040/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */
041/* JavaCCOptions: */
042//cobertura - put the import on its own line - otherwise, it messes up the script that changes the package.
043package net.sourceforge.cobertura.javancss.parser.debug;
044
045/** Token Manager Error. */
046public class TokenMgrError extends Error
047{
048
049   /*
050    * Ordinals for various reasons why an Error of this type can be thrown.
051    */
052
053   /**
054    * Lexical error occurred.
055    */
056   static final int LEXICAL_ERROR = 0;
057
058   /**
059    * An attempt was made to create a second instance of a static token manager.
060    */
061   static final int STATIC_LEXER_ERROR = 1;
062
063   /**
064    * Tried to change to an invalid lexical state.
065    */
066   static final int INVALID_LEXICAL_STATE = 2;
067
068   /**
069    * Detected (and bailed out of) an infinite loop in the token manager.
070    */
071   static final int LOOP_DETECTED = 3;
072
073   /**
074    * Indicates the reason why the exception is thrown. It will have
075    * one of the above 4 values.
076    */
077   int errorCode;
078
079   /**
080    * Replaces unprintable characters by their escaped (or unicode escaped)
081    * equivalents in the given string
082    */
083   protected static final String addEscapes(String str) {
084      StringBuffer retval = new StringBuffer();
085      char ch;
086      for (int i = 0; i < str.length(); i++) {
087        switch (str.charAt(i))
088        {
089           case 0 :
090              continue;
091           case '\b':
092              retval.append("\\b");
093              continue;
094           case '\t':
095              retval.append("\\t");
096              continue;
097           case '\n':
098              retval.append("\\n");
099              continue;
100           case '\f':
101              retval.append("\\f");
102              continue;
103           case '\r':
104              retval.append("\\r");
105              continue;
106           case '\"':
107              retval.append("\\\"");
108              continue;
109           case '\'':
110              retval.append("\\\'");
111              continue;
112           case '\\':
113              retval.append("\\\\");
114              continue;
115           default:
116              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
117                 String s = "0000" + Integer.toString(ch, 16);
118                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
119              } else {
120                 retval.append(ch);
121              }
122              continue;
123        }
124      }
125      return retval.toString();
126   }
127
128   /**
129    * Returns a detailed message for the Error when it is thrown by the
130    * token manager to indicate a lexical error.
131    * Parameters :
132    *    EOFSeen     : indicates if EOF caused the lexical error
133    *    curLexState : lexical state in which this error occurred
134    *    errorLine   : line number when the error occurred
135    *    errorColumn : column number when the error occurred
136    *    errorAfter  : prefix that was seen before this error occurred
137    *    curchar     : the offending character
138    * Note: You can customize the lexical error message by modifying this method.
139    */
140   protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
141      return("Lexical error at line " +
142           errorLine + ", column " +
143           errorColumn + ".  Encountered: " +
144           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
145           "after : \"" + addEscapes(errorAfter) + "\"");
146   }
147
148   /**
149    * You can also modify the body of this method to customize your error messages.
150    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
151    * of end-users concern, so you can return something like :
152    *
153    *     "Internal Error : Please file a bug report .... "
154    *
155    * from this method for such cases in the release version of your parser.
156    */
157   public String getMessage() {
158      return super.getMessage();
159   }
160
161   /*
162    * Constructors of various flavors follow.
163    */
164
165   /** No arg constructor. */
166   public TokenMgrError() {
167   }
168
169   /** Constructor with message and reason. */
170   public TokenMgrError(String message, int reason) {
171      super(message);
172      errorCode = reason;
173   }
174
175   /** Full Constructor. */
176   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
177      this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
178   }
179}
180/* JavaCC - OriginalChecksum=78b83ead2b9be6e85dfd6cf582647f66 (do not edit this line) */