1
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
7
* The contents of this file are subject to the terms of either the GNU
8
* General Public License Version 2 only ("GPL") or the Common
9
* Development and Distribution License("CDDL") (collectively, the
10
* "License"). You may not use this file except in compliance with the
11
* License. You can obtain a copy of the License at
12
* http://www.netbeans.org/cddl-gplv2.html
13
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14
* specific language governing permissions and limitations under the
15
* License. When distributing the software, include this License Header
16
* Notice in each file and include the License file at
17
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
18
* particular file as subject to the "Classpath" exception as provided
19
* by Sun in the GPL Version 2 section of the License file that
20
* accompanied this code. If applicable, add the following below the
21
* License Header, with the fields enclosed by brackets [] replaced by
22
* your own identifying information:
23
* "Portions Copyrighted [year] [name of copyright owner]"
27
* The Original Software is NetBeans. The Initial Developer of the Original
28
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
29
* Microsystems, Inc. All Rights Reserved.
31
* If you wish your version of this file to be governed by only the CDDL
32
* or only the GPL Version 2, indicate your decision by adding
33
* "[Contributor] elects to include this software in this distribution
34
* under the [CDDL or GPL Version 2] license." If you do not indicate a
35
* single choice of license, a recipient has the option to distribute
36
* your version of this file under either the CDDL, the GPL Version 2 or
37
* to extend the choice of license to its licensees as provided above.
38
* However, if you add GPL Version 2 code and therefore, elected the GPL
39
* Version 2 license, then the option applies only if the new code is
40
* made subject to such option by the copyright holder.
43
package org.netbeans.modules.xml.text.syntax.javacc;
46
* This exception is thrown when parse errors are encountered.
47
* You can explicitly create objects of this exception type by
48
* calling the method generateParseException in the generated
51
* You can modify this class to customize your error reporting
52
* mechanisms so long as you retain the public fields.
54
public class ParseException extends Exception {
57
* This constructor is used by the method "generateParseException"
58
* in the generated parser. Calling this constructor generates
59
* a new object of this type with the fields "currentToken",
60
* "expectedTokenSequences", and "tokenImage" set. The boolean
61
* flag "specialConstructor" is also set to true to indicate that
62
* this constructor was used to create this object.
63
* This constructor calls its super class with the empty string
64
* to force the "toString" method of parent class "Throwable" to
65
* print the error message in the form:
66
* ParseException: <result of getMessage>
68
public ParseException(Token currentTokenVal,
69
int[][] expectedTokenSequencesVal,
70
String[] tokenImageVal
74
specialConstructor = true;
75
currentToken = currentTokenVal;
76
expectedTokenSequences = expectedTokenSequencesVal;
77
tokenImage = tokenImageVal;
81
* The following constructors are for use by you for whatever
82
* purpose you can think of. Constructing the exception in this
83
* manner makes the exception behave in the normal way - i.e., as
84
* documented in the class "Throwable". The fields "errorToken",
85
* "expectedTokenSequences", and "tokenImage" do not contain
86
* relevant information. The JavaCC generated code does not use
90
public ParseException() {
92
specialConstructor = false;
95
public ParseException(String message) {
97
specialConstructor = false;
101
* This variable determines which constructor was used to create
102
* this object and thereby affects the semantics of the
103
* "getMessage" method (see below).
105
protected boolean specialConstructor;
108
* This is the last token that has been consumed successfully. If
109
* this object has been created due to a parse error, the token
110
* followng this token will (therefore) be the first error token.
112
public Token currentToken;
115
* Each entry in this array is an array of integers. Each array
116
* of integers represents a sequence of tokens (by their ordinal
117
* values) that is expected at this point of the parse.
119
public int[][] expectedTokenSequences;
122
* This is a reference to the "tokenImage" array of the generated
123
* parser within which the parse error occurred. This array is
124
* defined in the generated ...Constants interface.
126
public String[] tokenImage;
129
* This method has the standard behavior when this object has been
130
* created using the standard constructors. Otherwise, it uses
131
* "currentToken" and "expectedTokenSequences" to generate a parse
132
* error message and returns it. If this object has been created
133
* due to a parse error, and you do not catch it (it gets thrown
134
* from the parser), then this method is called during the printing
135
* of the final stack trace, and hence the correct error message
138
public String getMessage() {
139
if (!specialConstructor) {
140
return super.getMessage();
142
String expected = "";
144
for (int i = 0; i < expectedTokenSequences.length; i++) {
145
if (maxSize < expectedTokenSequences[i].length) {
146
maxSize = expectedTokenSequences[i].length;
148
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
149
expected += tokenImage[expectedTokenSequences[i][j]] + " ";
151
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
154
expected += eol + " ";
156
String retval = "Encountered \"";
157
Token tok = currentToken.next;
158
for (int i = 0; i < maxSize; i++) {
159
if (i != 0) retval += " ";
161
retval += tokenImage[0];
164
retval += add_escapes(tok.image);
167
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
169
if (expectedTokenSequences.length == 1) {
170
retval += "Was expecting:" + eol + " ";
172
retval += "Was expecting one of:" + eol + " ";
179
* The end of line string for this machine.
181
protected String eol = System.getProperty("line.separator", "\n");
184
* Used to convert raw characters to their escaped version
185
* when these raw version cannot be used as part of an ASCII
188
protected String add_escapes(String str) {
189
StringBuffer retval = new StringBuffer();
191
for (int i = 0; i < str.length(); i++) {
192
switch (str.charAt(i))
197
retval.append("\\b");
200
retval.append("\\t");
203
retval.append("\\n");
206
retval.append("\\f");
209
retval.append("\\r");
212
retval.append("\\\"");
215
retval.append("\\\'");
218
retval.append("\\\\");
221
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
222
String s = "0000" + Integer.toString(ch, 16);
223
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
230
return retval.toString();