Revision 36624 trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/rendering/filter/parser/ParseException.java
ParseException.java | ||
---|---|---|
1 |
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
|
|
1 |
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ |
|
2 | 2 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
... | ... | |
38 | 38 |
* |
39 | 39 |
* +34 963163400 |
40 | 40 |
* dac@iver.es |
41 |
*/ |
|
42 |
package org.gvsig.symbology.fmap.rendering.filter.parser; |
|
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 |
} |
|
41 |
*/ |
|
42 |
package org.gvsig.symbology.fmap.rendering.filter.parser; |
|
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 |
} |
Also available in: Unified diff