diff options
Diffstat (limited to 'src/monkey/seaspider/org/gnunet/seaspider/parser/ParseException.java')
-rw-r--r-- | src/monkey/seaspider/org/gnunet/seaspider/parser/ParseException.java | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/src/monkey/seaspider/org/gnunet/seaspider/parser/ParseException.java b/src/monkey/seaspider/org/gnunet/seaspider/parser/ParseException.java new file mode 100644 index 000000000..44162fe6e --- /dev/null +++ b/src/monkey/seaspider/org/gnunet/seaspider/parser/ParseException.java | |||
@@ -0,0 +1,186 @@ | |||
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 */ | ||
4 | /** | ||
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 | ||
8 | * parser. | ||
9 | * | ||
10 | * You can modify this class to customize your error reporting | ||
11 | * mechanisms so long as you retain the public fields. | ||
12 | */ | ||
13 | public class ParseException extends Exception { | ||
14 | |||
15 | /** | ||
16 | * The version identifier for this Serializable class. | ||
17 | * Increment only if the <i>serialized</i> form of the | ||
18 | * class changes. | ||
19 | */ | ||
20 | private static final long serialVersionUID = 1L; | ||
21 | |||
22 | /** | ||
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. | ||
27 | */ | ||
28 | public ParseException(Token currentTokenVal, | ||
29 | int[][] expectedTokenSequencesVal, | ||
30 | String[] tokenImageVal | ||
31 | ) | ||
32 | { | ||
33 | super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); | ||
34 | currentToken = currentTokenVal; | ||
35 | expectedTokenSequences = expectedTokenSequencesVal; | ||
36 | tokenImage = tokenImageVal; | ||
37 | } | ||
38 | |||
39 | /** | ||
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 | ||
46 | * these constructors. | ||
47 | */ | ||
48 | |||
49 | public ParseException() { | ||
50 | super(); | ||
51 | } | ||
52 | |||
53 | /** Constructor with message. */ | ||
54 | public ParseException(String message) { | ||
55 | super(message); | ||
56 | } | ||
57 | |||
58 | |||
59 | /** | ||
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. | ||
63 | */ | ||
64 | public Token currentToken; | ||
65 | |||
66 | /** | ||
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. | ||
70 | */ | ||
71 | public int[][] expectedTokenSequences; | ||
72 | |||
73 | /** | ||
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. | ||
77 | */ | ||
78 | public String[] tokenImage; | ||
79 | |||
80 | /** | ||
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 | ||
85 | * gets displayed. | ||
86 | */ | ||
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(); | ||
92 | int maxSize = 0; | ||
93 | for (int i = 0; i < expectedTokenSequences.length; i++) { | ||
94 | if (maxSize < expectedTokenSequences[i].length) { | ||
95 | maxSize = expectedTokenSequences[i].length; | ||
96 | } | ||
97 | for (int j = 0; j < expectedTokenSequences[i].length; j++) { | ||
98 | expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); | ||
99 | } | ||
100 | if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { | ||
101 | expected.append("..."); | ||
102 | } | ||
103 | expected.append(eol).append(" "); | ||
104 | } | ||
105 | String retval = "Encountered \""; | ||
106 | Token tok = currentToken.next; | ||
107 | for (int i = 0; i < maxSize; i++) { | ||
108 | if (i != 0) retval += " "; | ||
109 | if (tok.kind == 0) { | ||
110 | retval += tokenImage[0]; | ||
111 | break; | ||
112 | } | ||
113 | retval += " " + tokenImage[tok.kind]; | ||
114 | retval += " \""; | ||
115 | retval += add_escapes(tok.image); | ||
116 | retval += " \""; | ||
117 | tok = tok.next; | ||
118 | } | ||
119 | retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; | ||
120 | retval += "." + eol; | ||
121 | if (expectedTokenSequences.length == 1) { | ||
122 | retval += "Was expecting:" + eol + " "; | ||
123 | } else { | ||
124 | retval += "Was expecting one of:" + eol + " "; | ||
125 | } | ||
126 | retval += expected.toString(); | ||
127 | return retval; | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * The end of line string for this machine. | ||
132 | */ | ||
133 | protected String eol = System.getProperty("line.separator", "\n"); | ||
134 | |||
135 | /** | ||
136 | * Used to convert raw characters to their escaped version | ||
137 | * when these raw version cannot be used as part of an ASCII | ||
138 | * string literal. | ||
139 | */ | ||
140 | static String add_escapes(String str) { | ||
141 | StringBuffer retval = new StringBuffer(); | ||
142 | char ch; | ||
143 | for (int i = 0; i < str.length(); i++) { | ||
144 | switch (str.charAt(i)) | ||
145 | { | ||
146 | case 0 : | ||
147 | continue; | ||
148 | case '\b': | ||
149 | retval.append("\\b"); | ||
150 | continue; | ||
151 | case '\t': | ||
152 | retval.append("\\t"); | ||
153 | continue; | ||
154 | case '\n': | ||
155 | retval.append("\\n"); | ||
156 | continue; | ||
157 | case '\f': | ||
158 | retval.append("\\f"); | ||
159 | continue; | ||
160 | case '\r': | ||
161 | retval.append("\\r"); | ||
162 | continue; | ||
163 | case '\"': | ||
164 | retval.append("\\\""); | ||
165 | continue; | ||
166 | case '\'': | ||
167 | retval.append("\\\'"); | ||
168 | continue; | ||
169 | case '\\': | ||
170 | retval.append("\\\\"); | ||
171 | continue; | ||
172 | default: | ||
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())); | ||
176 | } else { | ||
177 | retval.append(ch); | ||
178 | } | ||
179 | continue; | ||
180 | } | ||
181 | } | ||
182 | return retval.toString(); | ||
183 | } | ||
184 | |||
185 | } | ||
186 | /* JavaCC - OriginalChecksum=c5a983a229aa877dc2b3b3b9933cdd6b (do not edit this line) */ | ||