1 /* Generated By:JavaCC: Do not edit this line. ParseException.cc Version 6.0 */
2 /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3 #include "ParseException.h"
9 * This exception is thrown when parse errors are encountered.
10 * You can explicitly create objects of this exception type by
11 * calling the method generate_ParseException in the generated
14 * You can modify this class to customize your error reporting
15 * mechanisms so long as you retain the fields.
19 * This constructor is used by the method "generate_ParseException"
20 * in the generated parser. Calling this constructor generates
21 * a new object of this type with the fields "currentToken",
22 * "expectedTokenSequences", and "tokenImage" set.
24 ParseException::ParseException(Token currentTokenVal,
25 int** expectedTokenSequencesVal,
26 JAVACC_STRING_TYPE* tokenImageVal
29 initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal);
30 currentToken = currentTokenVal;
31 expectedTokenSequences = expectedTokenSequencesVal;
32 tokenImage = tokenImageVal;
36 * The following constructors are for use by you for whatever
37 * purpose you can think of. Constructing the exception in this
38 * manner makes the exception behave in the normal way - i.e., as
39 * documented in the class "Throwable". The fields "errorToken",
40 * "expectedTokenSequences", and "tokenImage" do not contain
41 * relevant information. The JavaCC generated code does not use
45 ParseException::ParseException() {
48 /** Constructor with message. */
49 ParseException::ParseException(JAVACC_STRING_TYPE message) {
54 * This is the last token that has been consumed successfully. If
55 * this object has been created due to a parse error, the token
56 * followng this token will (therefore) be the first error token.
61 * Each entry in this array is an array of integers. Each array
62 * of integers represents a sequence of tokens (by their ordinal
63 * values) that is expected at this point of the parse.
65 int** expectedTokenSequences;
68 * This is a reference to the "tokenImage" array of the generated
69 * parser within which the parse error occurred. This array is
70 * defined in the generated ...Constants class.
72 JAVACC_STRING_TYPE* tokenImage;
75 * It uses "currentToken" and "expectedTokenSequences" to generate a parse
76 * error message and returns it. If this object has been created
77 * due to a parse error, and you do not catch it (it gets thrown
78 * from the parser) the correct error message
81 JAVACC_STRING_TYPE ParseException::initialise(Token currentToken,
82 int** expectedTokenSequences,
83 JAVACC_STRING_TYPE* tokenImage) {
85 //JAVACC_STRING_TYPE eol = System.getProperty("line.separator", "\n");
86 expected = new JAVACC_STRING_TYPE();
88 for (int i = 0; i < expectedTokenSequences.length; i++) {
89 if (maxSize < expectedTokenSequences[i].length) {
90 maxSize = expectedTokenSequences[i].length;
92 for (int j = 0; j < expectedTokenSequences[i].length; j++) {
93 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
95 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
96 expected.append((JAVACC_CHAR_TYPE*)"...");
98 expected.append(eol).append(" ");
100 JAVACC_STRING_TYPE retval = (JAVACC_CHAR_TYPE*)"Encountered \"";
101 Token tok = currentToken.next;
102 for (int i = 0; i < maxSize; i++) {
103 if (i != 0) retval += (JAVACC_CHAR_TYPE*)" ";
105 retval += tokenImage[0];
108 retval += (JAVACC_CHAR_TYPE*)" " + tokenImage[tok.kind];
109 retval += (JAVACC_CHAR_TYPE*)" \"";
110 retval += add_escapes(tok.image);
111 retval += (JAVACC_CHAR_TYPE*)" \"";
114 retval += (JAVACC_CHAR_TYPE*)"\" at line " + currentToken.next.beginLine + (JAVACC_CHAR_TYPE*)", column " + currentToken.next.beginColumn;
115 retval += (JAVACC_CHAR_TYPE*)"." + eol;
116 if (expectedTokenSequences.length == 1) {
117 retval += (JAVACC_CHAR_TYPE*)"Was expecting:" + eol + (JAVACC_CHAR_TYPE*)" ";
119 retval += (JAVACC_CHAR_TYPE*)"Was expecting one of:" + eol + (JAVACC_CHAR_TYPE*)" ";
121 retval += expected.toString();
124 return (JAVACC_CHAR_TYPE*)"Parse exception";
128 * The end of line JAVACC_STRING_TYPE for this machine.
133 * Used to convert raw characters to their escaped version
134 * when these raw version cannot be used as part of an ASCII
137 JAVACC_STRING_TYPE ParseException::add_escapes(JAVACC_STRING_TYPE str) {
139 JAVACC_STRING_TYPE *retval = new JAVACC_STRING_TYPE();
141 for (int i = 0; i < str.length(); i++) {
142 switch (str.charAt(i))
147 retval.append("\\b");
150 retval.append("\\t");
153 retval.append("\\n");
156 retval.append("\\f");
159 retval.append("\\r");
162 retval.append("\\\"");
165 retval.append("\\\'");
168 retval.append("\\\\");
171 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
172 JAVACC_STRING_TYPE s = "0000" + Integer.toString(ch, 16);
173 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
180 return retval.toString();
186 /* JavaCC - OriginalChecksum=99d488e13335cf377284c90700f070ed (do not edit this line) */