0N/A/*
2362N/A * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 0.7pre6 */
0N/Apackage com.sun.tools.example.debug.expr;
0N/A
0N/A/**
0N/A * This exception is thrown when parse errors are encountered.
0N/A * You can explicitly create objects of this exception type by
0N/A * calling the method generateParseException in the generated
0N/A * parser.
0N/A *
0N/A * You can modify this class to customize your error reporting
0N/A * mechanisms so long as you retain the public fields.
0N/A */
0N/Apublic class ParseException extends Exception {
0N/A
4123N/A private static final long serialVersionUID = 7978489144303647901L;
4123N/A
0N/A /**
0N/A * This constructor is used by the method "generateParseException"
0N/A * in the generated parser. Calling this constructor generates
0N/A * a new object of this type with the fields "currentToken",
0N/A * "expectedTokenSequences", and "tokenImage" set. The boolean
0N/A * flag "specialConstructor" is also set to true to indicate that
0N/A * this constructor was used to create this object.
0N/A * This constructor calls its super class with the empty string
0N/A * to force the "toString" method of parent class "Throwable" to
0N/A * print the error message in the form:
0N/A * ParseException: <result of getMessage>
0N/A */
0N/A public ParseException(Token currentTokenVal,
0N/A int[][] expectedTokenSequencesVal,
0N/A String[] tokenImageVal
0N/A )
0N/A {
0N/A super("");
0N/A specialConstructor = true;
0N/A currentToken = currentTokenVal;
0N/A expectedTokenSequences = expectedTokenSequencesVal;
0N/A tokenImage = tokenImageVal;
0N/A }
0N/A
0N/A /**
0N/A * The following constructors are for use by you for whatever
0N/A * purpose you can think of. Constructing the exception in this
0N/A * manner makes the exception behave in the normal way - i.e., as
0N/A * documented in the class "Throwable". The fields "errorToken",
0N/A * "expectedTokenSequences", and "tokenImage" do not contain
0N/A * relevant information. The JavaCC generated code does not use
0N/A * these constructors.
0N/A */
0N/A
0N/A public ParseException() {
0N/A super();
0N/A specialConstructor = false;
0N/A }
0N/A
0N/A public ParseException(String message) {
0N/A super(message);
0N/A specialConstructor = false;
0N/A }
0N/A
0N/A /**
0N/A * This variable determines which constructor was used to create
0N/A * this object and thereby affects the semantics of the
0N/A * "getMessage" method (see below).
0N/A */
0N/A protected boolean specialConstructor;
0N/A
0N/A /**
0N/A * This is the last token that has been consumed successfully. If
0N/A * this object has been created due to a parse error, the token
0N/A * followng this token will (therefore) be the first error token.
0N/A */
0N/A public Token currentToken;
0N/A
0N/A /**
0N/A * Each entry in this array is an array of integers. Each array
0N/A * of integers represents a sequence of tokens (by their ordinal
0N/A * values) that is expected at this point of the parse.
0N/A */
0N/A public int[][] expectedTokenSequences;
0N/A
0N/A /**
0N/A * This is a reference to the "tokenImage" array of the generated
0N/A * parser within which the parse error occurred. This array is
0N/A * defined in the generated ...Constants interface.
0N/A */
0N/A public String[] tokenImage;
0N/A
0N/A /**
0N/A * This method has the standard behavior when this object has been
0N/A * created using the standard constructors. Otherwise, it uses
0N/A * "currentToken" and "expectedTokenSequences" to generate a parse
0N/A * error message and returns it. If this object has been created
0N/A * due to a parse error, and you do not catch it (it gets thrown
0N/A * from the parser), then this method is called during the printing
0N/A * of the final stack trace, and hence the correct error message
0N/A * gets displayed.
0N/A */
4123N/A @Override
0N/A public String getMessage() {
0N/A if (!specialConstructor) {
0N/A return super.getMessage();
0N/A }
0N/A String expected = "";
0N/A int maxSize = 0;
4123N/A for (int[] expectedTokenSequence : expectedTokenSequences) {
4123N/A if (maxSize < expectedTokenSequence.length) {
4123N/A maxSize = expectedTokenSequence.length;
0N/A }
4123N/A for (int j = 0; j < expectedTokenSequence.length; j++) {
4123N/A expected += tokenImage[expectedTokenSequence[j]] + " ";
0N/A }
4123N/A if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) {
0N/A expected += "...";
0N/A }
0N/A expected += eol + " ";
0N/A }
0N/A String retval = "Encountered \"";
0N/A Token tok = currentToken.next;
0N/A for (int i = 0; i < maxSize; i++) {
4123N/A if (i != 0) {
4123N/A retval += " ";
4123N/A }
0N/A if (tok.kind == 0) {
0N/A retval += tokenImage[0];
0N/A break;
0N/A }
0N/A retval += add_escapes(tok.image);
0N/A tok = tok.next;
0N/A }
0N/A retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + "." + eol;
0N/A if (expectedTokenSequences.length == 1) {
0N/A retval += "Was expecting:" + eol + " ";
0N/A } else {
0N/A retval += "Was expecting one of:" + eol + " ";
0N/A }
0N/A retval += expected;
0N/A return retval;
0N/A }
0N/A
0N/A /**
0N/A * The end of line string for this machine.
0N/A */
0N/A protected String eol = System.getProperty("line.separator", "\n");
0N/A
0N/A /**
0N/A * Used to convert raw characters to their escaped version
0N/A * when these raw version cannot be used as part of an ASCII
0N/A * string literal.
0N/A */
0N/A protected String add_escapes(String str) {
0N/A StringBuffer retval = new StringBuffer();
0N/A char ch;
0N/A for (int i = 0; i < str.length(); i++) {
0N/A switch (str.charAt(i))
0N/A {
0N/A case 0 :
0N/A continue;
0N/A case '\b':
0N/A retval.append("\\b");
0N/A continue;
0N/A case '\t':
0N/A retval.append("\\t");
0N/A continue;
0N/A case '\n':
0N/A retval.append("\\n");
0N/A continue;
0N/A case '\f':
0N/A retval.append("\\f");
0N/A continue;
0N/A case '\r':
0N/A retval.append("\\r");
0N/A continue;
0N/A case '\"':
0N/A retval.append("\\\"");
0N/A continue;
0N/A case '\'':
0N/A retval.append("\\\'");
0N/A continue;
0N/A case '\\':
0N/A retval.append("\\\\");
0N/A continue;
0N/A default:
0N/A if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
0N/A String s = "0000" + Integer.toString(ch, 16);
0N/A retval.append("\\u" + s.substring(s.length() - 4, s.length()));
0N/A } else {
0N/A retval.append(ch);
0N/A }
0N/A continue;
0N/A }
0N/A }
0N/A return retval.toString();
0N/A }
0N/A
0N/A}