svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / labeling / parse / ParseException.java @ 36624
History | View | Annotate | Download (7.53 KB)
1 |
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
|
---|---|
2 |
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ibáñez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package org.gvsig.symbology.fmap.labeling.parse; |
43 |
|
44 |
/**
|
45 |
* This exception is thrown when parse errors are encountered.
|
46 |
* You can explicitly create objects of this exception type by
|
47 |
* calling the method generateParseException in the generated
|
48 |
* parser.
|
49 |
*
|
50 |
* You can modify this class to customize your error reporting
|
51 |
* mechanisms so long as you retain the public fields.
|
52 |
*/
|
53 |
public class ParseException extends Exception { |
54 |
|
55 |
/**
|
56 |
* This constructor is used by the method "generateParseException"
|
57 |
* in the generated parser. Calling this constructor generates
|
58 |
* a new object of this type with the fields "currentToken",
|
59 |
* "expectedTokenSequences", and "tokenImage" set. The boolean
|
60 |
* flag "specialConstructor" is also set to true to indicate that
|
61 |
* this constructor was used to create this object.
|
62 |
* This constructor calls its super class with the empty string
|
63 |
* to force the "toString" method of parent class "Throwable" to
|
64 |
* print the error message in the form:
|
65 |
* ParseException: <result of getMessage>
|
66 |
*/
|
67 |
public ParseException(Token currentTokenVal, |
68 |
int[][] expectedTokenSequencesVal, |
69 |
String[] tokenImageVal |
70 |
) |
71 |
{ |
72 |
super(""); |
73 |
specialConstructor = true;
|
74 |
currentToken = currentTokenVal; |
75 |
expectedTokenSequences = expectedTokenSequencesVal; |
76 |
tokenImage = tokenImageVal; |
77 |
} |
78 |
|
79 |
/**
|
80 |
* The following constructors are for use by you for whatever
|
81 |
* purpose you can think of. Constructing the exception in this
|
82 |
* manner makes the exception behave in the normal way - i.e., as
|
83 |
* documented in the class "Throwable". The fields "errorToken",
|
84 |
* "expectedTokenSequences", and "tokenImage" do not contain
|
85 |
* relevant information. The JavaCC generated code does not use
|
86 |
* these constructors.
|
87 |
*/
|
88 |
|
89 |
public ParseException() { |
90 |
super();
|
91 |
specialConstructor = false;
|
92 |
} |
93 |
|
94 |
public ParseException(String message) { |
95 |
super(message);
|
96 |
specialConstructor = false;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* This variable determines which constructor was used to create
|
101 |
* this object and thereby affects the semantics of the
|
102 |
* "getMessage" method (see below).
|
103 |
*/
|
104 |
protected boolean specialConstructor; |
105 |
|
106 |
/**
|
107 |
* This is the last token that has been consumed successfully. If
|
108 |
* this object has been created due to a parse error, the token
|
109 |
* followng this token will (therefore) be the first error token.
|
110 |
*/
|
111 |
public Token currentToken;
|
112 |
|
113 |
/**
|
114 |
* Each entry in this array is an array of integers. Each array
|
115 |
* of integers represents a sequence of tokens (by their ordinal
|
116 |
* values) that is expected at this point of the parse.
|
117 |
*/
|
118 |
public int[][] expectedTokenSequences; |
119 |
|
120 |
/**
|
121 |
* This is a reference to the "tokenImage" array of the generated
|
122 |
* parser within which the parse error occurred. This array is
|
123 |
* defined in the generated ...Constants interface.
|
124 |
*/
|
125 |
public String[] tokenImage; |
126 |
|
127 |
/**
|
128 |
* This method has the standard behavior when this object has been
|
129 |
* created using the standard constructors. Otherwise, it uses
|
130 |
* "currentToken" and "expectedTokenSequences" to generate a parse
|
131 |
* error message and returns it. If this object has been created
|
132 |
* due to a parse error, and you do not catch it (it gets thrown
|
133 |
* from the parser), then this method is called during the printing
|
134 |
* of the final stack trace, and hence the correct error message
|
135 |
* gets displayed.
|
136 |
*/
|
137 |
public String getMessage() { |
138 |
if (!specialConstructor) {
|
139 |
return super.getMessage(); |
140 |
} |
141 |
StringBuffer expected = new StringBuffer(); |
142 |
int maxSize = 0; |
143 |
for (int i = 0; i < expectedTokenSequences.length; i++) { |
144 |
if (maxSize < expectedTokenSequences[i].length) {
|
145 |
maxSize = expectedTokenSequences[i].length; |
146 |
} |
147 |
for (int j = 0; j < expectedTokenSequences[i].length; j++) { |
148 |
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
|
149 |
} |
150 |
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { |
151 |
expected.append("...");
|
152 |
} |
153 |
expected.append(eol).append(" ");
|
154 |
} |
155 |
String retval = "Encountered \""; |
156 |
Token tok = currentToken.next; |
157 |
for (int i = 0; i < maxSize; i++) { |
158 |
if (i != 0) retval += " "; |
159 |
if (tok.kind == 0) { |
160 |
retval += tokenImage[0];
|
161 |
break;
|
162 |
} |
163 |
retval += add_escapes(tok.image); |
164 |
tok = tok.next; |
165 |
} |
166 |
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; |
167 |
retval += "." + eol;
|
168 |
if (expectedTokenSequences.length == 1) { |
169 |
retval += "Was expecting:" + eol + " "; |
170 |
} else {
|
171 |
retval += "Was expecting one of:" + eol + " "; |
172 |
} |
173 |
retval += expected.toString(); |
174 |
return retval;
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* The end of line string for this machine.
|
179 |
*/
|
180 |
protected String eol = System.getProperty("line.separator", "\n"); |
181 |
|
182 |
/**
|
183 |
* Used to convert raw characters to their escaped version
|
184 |
* when these raw version cannot be used as part of an ASCII
|
185 |
* string literal.
|
186 |
*/
|
187 |
protected String add_escapes(String str) { |
188 |
StringBuffer retval = new StringBuffer(); |
189 |
char ch;
|
190 |
for (int i = 0; i < str.length(); i++) { |
191 |
switch (str.charAt(i))
|
192 |
{ |
193 |
case 0 : |
194 |
continue;
|
195 |
case '\b': |
196 |
retval.append("\\b");
|
197 |
continue;
|
198 |
case '\t': |
199 |
retval.append("\\t");
|
200 |
continue;
|
201 |
case '\n': |
202 |
retval.append("\\n");
|
203 |
continue;
|
204 |
case '\f': |
205 |
retval.append("\\f");
|
206 |
continue;
|
207 |
case '\r': |
208 |
retval.append("\\r");
|
209 |
continue;
|
210 |
case '\"': |
211 |
retval.append("\\\"");
|
212 |
continue;
|
213 |
case '\'': |
214 |
retval.append("\\\'");
|
215 |
continue;
|
216 |
case '\\': |
217 |
retval.append("\\\\");
|
218 |
continue;
|
219 |
default:
|
220 |
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { |
221 |
String s = "0000" + Integer.toString(ch, 16); |
222 |
retval.append("\\u" + s.substring(s.length() - 4, s.length())); |
223 |
} else {
|
224 |
retval.append(ch); |
225 |
} |
226 |
continue;
|
227 |
} |
228 |
} |
229 |
return retval.toString();
|
230 |
} |
231 |
|
232 |
} |