Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ParseException.java

00001 package edu.ksu.cis.bandera.abstraction.predicate.parser;
00002 
00003 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
00004 /**
00005  * This exception is thrown when parse errors are encountered.
00006  * You can explicitly create objects of this exception type by
00007  * calling the method generateParseException in the generated
00008  * parser.
00009  *
00010  * You can modify this class to customize your error reporting
00011  * mechanisms so long as you retain the public fields.
00012  */
00013 public class ParseException extends Exception {
00014 
00015   /**
00016    * This variable determines which constructor was used to create
00017    * this object and thereby affects the semantics of the
00018    * "getMessage" method (see below).
00019    */
00020   protected boolean specialConstructor;
00021 
00022   /**
00023    * This is the last token that has been consumed successfully.  If
00024    * this object has been created due to a parse error, the token
00025    * followng this token will (therefore) be the first error token.
00026    */
00027   public Token currentToken;
00028 
00029   /**
00030    * Each entry in this array is an array of integers.  Each array
00031    * of integers represents a sequence of tokens (by their ordinal
00032    * values) that is expected at this point of the parse.
00033    */
00034   public int[][] expectedTokenSequences;
00035 
00036   /**
00037    * This is a reference to the "tokenImage" array of the generated
00038    * parser within which the parse error occurred.  This array is
00039    * defined in the generated ...Constants interface.
00040    */
00041   public String[] tokenImage;
00042 
00043   /**
00044    * The end of line string for this machine.
00045    */
00046   protected String eol = System.getProperty("line.separator", "\n");
00047 
00048   /**
00049    * The following constructors are for use by you for whatever
00050    * purpose you can think of.  Constructing the exception in this
00051    * manner makes the exception behave in the normal way - i.e., as
00052    * documented in the class "Throwable".  The fields "errorToken",
00053    * "expectedTokenSequences", and "tokenImage" do not contain
00054    * relevant information.  The JavaCC generated code does not use
00055    * these constructors.
00056    */
00057 
00058   public ParseException() {
00059     super();
00060     specialConstructor = false;
00061   }  
00062   /**
00063    * This constructor is used by the method "generateParseException"
00064    * in the generated parser.  Calling this constructor generates
00065    * a new object of this type with the fields "currentToken",
00066    * "expectedTokenSequences", and "tokenImage" set.  The boolean
00067    * flag "specialConstructor" is also set to true to indicate that
00068    * this constructor was used to create this object.
00069    * This constructor calls its super class with the empty string
00070    * to force the "toString" method of parent class "Throwable" to
00071    * print the error message in the form:
00072    *     ParseException: <result of getMessage>
00073    */
00074   public ParseException(Token currentTokenVal,
00075                         int[][] expectedTokenSequencesVal,
00076                         String[] tokenImageVal
00077                        )
00078   {
00079     super("");
00080     specialConstructor = true;
00081     currentToken = currentTokenVal;
00082     expectedTokenSequences = expectedTokenSequencesVal;
00083     tokenImage = tokenImageVal;
00084   }  
00085   public ParseException(String message) {
00086     super(message);
00087     specialConstructor = false;
00088   }  
00089   /**
00090    * Used to convert raw characters to their escaped version
00091    * when these raw version cannot be used as part of an ASCII
00092    * string literal.
00093    */
00094   protected String add_escapes(String str) {
00095       StringBuffer retval = new StringBuffer();
00096       char ch;
00097       for (int i = 0; i < str.length(); i++) {
00098         switch (str.charAt(i))
00099         {
00100            case 0 :
00101               continue;
00102            case '\b':
00103               retval.append("\\b");
00104               continue;
00105            case '\t':
00106               retval.append("\\t");
00107               continue;
00108            case '\n':
00109               retval.append("\\n");
00110               continue;
00111            case '\f':
00112               retval.append("\\f");
00113               continue;
00114            case '\r':
00115               retval.append("\\r");
00116               continue;
00117            case '\"':
00118               retval.append("\\\"");
00119               continue;
00120            case '\'':
00121               retval.append("\\\'");
00122               continue;
00123            case '\\':
00124               retval.append("\\\\");
00125               continue;
00126            default:
00127               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
00128                  String s = "0000" + Integer.toString(ch, 16);
00129                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
00130               } else {
00131                  retval.append(ch);
00132               }
00133               continue;
00134         }
00135       }
00136       return retval.toString();
00137    }   
00138   /**
00139    * This method has the standard behavior when this object has been
00140    * created using the standard constructors.  Otherwise, it uses
00141    * "currentToken" and "expectedTokenSequences" to generate a parse
00142    * error message and returns it.  If this object has been created
00143    * due to a parse error, and you do not catch it (it gets thrown
00144    * from the parser), then this method is called during the printing
00145    * of the final stack trace, and hence the correct error message
00146    * gets displayed.
00147    */
00148   public String getMessage() {
00149     if (!specialConstructor) {
00150       return super.getMessage();
00151     }
00152     String expected = "";
00153     int maxSize = 0;
00154     for (int i = 0; i < expectedTokenSequences.length; i++) {
00155       if (maxSize < expectedTokenSequences[i].length) {
00156         maxSize = expectedTokenSequences[i].length;
00157       }
00158       for (int j = 0; j < expectedTokenSequences[i].length; j++) {
00159         expected += tokenImage[expectedTokenSequences[i][j]] + " ";
00160       }
00161       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
00162         expected += "...";
00163       }
00164       expected += eol + "    ";
00165     }
00166     String retval = "Encountered \"";
00167     Token tok = currentToken.next;
00168     for (int i = 0; i < maxSize; i++) {
00169       if (i != 0) retval += " ";
00170       if (tok.kind == 0) {
00171         retval += tokenImage[0];
00172         break;
00173       }
00174       retval += add_escapes(tok.image);
00175       tok = tok.next;
00176     }
00177     retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + "." + eol;
00178     if (expectedTokenSequences.length == 1) {
00179       retval += "Was expecting:" + eol + "    ";
00180     } else {
00181       retval += "Was expecting one of:" + eol + "    ";
00182     }
00183     retval += expected;
00184     return retval;
00185   }  
00186 }

Generated at Thu Feb 7 06:51:06 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001