34 * |
34 * |
35 * You can modify this class to customize your error reporting |
35 * You can modify this class to customize your error reporting |
36 * mechanisms so long as you retain the public fields. |
36 * mechanisms so long as you retain the public fields. |
37 */ |
37 */ |
38 public class ParseException extends Exception { |
38 public class ParseException extends Exception { |
|
39 |
|
40 private static final long serialVersionUID = 7978489144303647901L; |
39 |
41 |
40 /** |
42 /** |
41 * This constructor is used by the method "generateParseException" |
43 * This constructor is used by the method "generateParseException" |
42 * in the generated parser. Calling this constructor generates |
44 * in the generated parser. Calling this constructor generates |
43 * a new object of this type with the fields "currentToken", |
45 * a new object of this type with the fields "currentToken", |
117 * due to a parse error, and you do not catch it (it gets thrown |
119 * due to a parse error, and you do not catch it (it gets thrown |
118 * from the parser), then this method is called during the printing |
120 * from the parser), then this method is called during the printing |
119 * of the final stack trace, and hence the correct error message |
121 * of the final stack trace, and hence the correct error message |
120 * gets displayed. |
122 * gets displayed. |
121 */ |
123 */ |
|
124 @Override |
122 public String getMessage() { |
125 public String getMessage() { |
123 if (!specialConstructor) { |
126 if (!specialConstructor) { |
124 return super.getMessage(); |
127 return super.getMessage(); |
125 } |
128 } |
126 String expected = ""; |
129 String expected = ""; |
127 int maxSize = 0; |
130 int maxSize = 0; |
128 for (int i = 0; i < expectedTokenSequences.length; i++) { |
131 for (int[] expectedTokenSequence : expectedTokenSequences) { |
129 if (maxSize < expectedTokenSequences[i].length) { |
132 if (maxSize < expectedTokenSequence.length) { |
130 maxSize = expectedTokenSequences[i].length; |
133 maxSize = expectedTokenSequence.length; |
131 } |
134 } |
132 for (int j = 0; j < expectedTokenSequences[i].length; j++) { |
135 for (int j = 0; j < expectedTokenSequence.length; j++) { |
133 expected += tokenImage[expectedTokenSequences[i][j]] + " "; |
136 expected += tokenImage[expectedTokenSequence[j]] + " "; |
134 } |
137 } |
135 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { |
138 if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) { |
136 expected += "..."; |
139 expected += "..."; |
137 } |
140 } |
138 expected += eol + " "; |
141 expected += eol + " "; |
139 } |
142 } |
140 String retval = "Encountered \""; |
143 String retval = "Encountered \""; |
141 Token tok = currentToken.next; |
144 Token tok = currentToken.next; |
142 for (int i = 0; i < maxSize; i++) { |
145 for (int i = 0; i < maxSize; i++) { |
143 if (i != 0) retval += " "; |
146 if (i != 0) { |
|
147 retval += " "; |
|
148 } |
144 if (tok.kind == 0) { |
149 if (tok.kind == 0) { |
145 retval += tokenImage[0]; |
150 retval += tokenImage[0]; |
146 break; |
151 break; |
147 } |
152 } |
148 retval += add_escapes(tok.image); |
153 retval += add_escapes(tok.image); |