1 package org.gnunet.seaspider.parser;
2 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */
3 /* JavaCCOptions:KEEP_LINE_COL=null */
5 * This exception is thrown when parse errors are encountered.
6 * You can explicitly create objects of this exception type by
7 * calling the method generateParseException in the generated
10 * You can modify this class to customize your error reporting
11 * mechanisms so long as you retain the public fields.
13 public class ParseException extends Exception {
16 * The version identifier for this Serializable class.
17 * Increment only if the <i>serialized</i> form of the
20 private static final long serialVersionUID = 1L;
23 * This constructor is used by the method "generateParseException"
24 * in the generated parser. Calling this constructor generates
25 * a new object of this type with the fields "currentToken",
26 * "expectedTokenSequences", and "tokenImage" set.
28 public ParseException(Token currentTokenVal,
29 int[][] expectedTokenSequencesVal,
30 String[] tokenImageVal
33 super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
34 currentToken = currentTokenVal;
35 expectedTokenSequences = expectedTokenSequencesVal;
36 tokenImage = tokenImageVal;
40 * The following constructors are for use by you for whatever
41 * purpose you can think of. Constructing the exception in this
42 * manner makes the exception behave in the normal way - i.e., as
43 * documented in the class "Throwable". The fields "errorToken",
44 * "expectedTokenSequences", and "tokenImage" do not contain
45 * relevant information. The JavaCC generated code does not use
49 public ParseException() {
53 /** Constructor with message. */
54 public ParseException(String message) {
60 * This is the last token that has been consumed successfully. If
61 * this object has been created due to a parse error, the token
62 * followng this token will (therefore) be the first error token.
64 public Token currentToken;
67 * Each entry in this array is an array of integers. Each array
68 * of integers represents a sequence of tokens (by their ordinal
69 * values) that is expected at this point of the parse.
71 public int[][] expectedTokenSequences;
74 * This is a reference to the "tokenImage" array of the generated
75 * parser within which the parse error occurred. This array is
76 * defined in the generated ...Constants interface.
78 public String[] tokenImage;
81 * It uses "currentToken" and "expectedTokenSequences" to generate a parse
82 * error message and returns it. If this object has been created
83 * due to a parse error, and you do not catch it (it gets thrown
84 * from the parser) the correct error message
87 private static String initialise(Token currentToken,
88 int[][] expectedTokenSequences,
89 String[] tokenImage) {
90 String eol = System.getProperty("line.separator", "\n");
91 StringBuffer expected = new StringBuffer();
93 for (int i = 0; i < expectedTokenSequences.length; i++) {
94 if (maxSize < expectedTokenSequences[i].length) {
95 maxSize = expectedTokenSequences[i].length;
97 for (int j = 0; j < expectedTokenSequences[i].length; j++) {
98 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
100 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
101 expected.append("...");
103 expected.append(eol).append(" ");
105 String retval = "Encountered \"";
106 Token tok = currentToken.next;
107 for (int i = 0; i < maxSize; i++) {
108 if (i != 0) retval += " ";
110 retval += tokenImage[0];
113 retval += " " + tokenImage[tok.kind];
115 retval += add_escapes(tok.image);
119 retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
121 if (expectedTokenSequences.length == 1) {
122 retval += "Was expecting:" + eol + " ";
124 retval += "Was expecting one of:" + eol + " ";
126 retval += expected.toString();
131 * The end of line string for this machine.
133 protected String eol = System.getProperty("line.separator", "\n");
136 * Used to convert raw characters to their escaped version
137 * when these raw version cannot be used as part of an ASCII
140 static String add_escapes(String str) {
141 StringBuffer retval = new StringBuffer();
143 for (int i = 0; i < str.length(); i++) {
144 switch (str.charAt(i))
149 retval.append("\\b");
152 retval.append("\\t");
155 retval.append("\\n");
158 retval.append("\\f");
161 retval.append("\\r");
164 retval.append("\\\"");
167 retval.append("\\\'");
170 retval.append("\\\\");
173 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
174 String s = "0000" + Integer.toString(ch, 16);
175 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
182 return retval.toString();
186 /* JavaCC - OriginalChecksum=c5a983a229aa877dc2b3b3b9933cdd6b (do not edit this line) */