Debian Codegraph @

Source/Parser/FunctionalJAVACC/ParseException.cpp

raw
1 /* Generated By:JavaCC: Do not edit this line. ParseException.cc Version 6.0 */
2 /* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3 #include "ParseException.h"
4
5
6 namespace Konclude {
7 namespace Parser {
8 namespace FunctionalJAVACC {
9 /**
10 * This exception is thrown when parse errors are encountered.
11 * You can explicitly create objects of this exception type by
12 * calling the method generate_ParseException in the generated
13 * parser.
14 *
15 * You can modify this class to customize your error reporting
16 * mechanisms so long as you retain the fields.
17 */
18
19 /**
20 * This constructor is used by the method "generate_ParseException"
21 * in the generated parser. Calling this constructor generates
22 * a new object of this type with the fields "currentToken",
23 * "expectedTokenSequences", and "tokenImage" set.
24 */
25 ParseException::ParseException(Token currentTokenVal,
26 int** expectedTokenSequencesVal,
27 JAVACC_STRING_TYPE* tokenImageVal
28 )
29 {
30 initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal);
31 currentToken = currentTokenVal;
32 expectedTokenSequences = expectedTokenSequencesVal;
33 tokenImage = tokenImageVal;
34 }
35
36 /**
37 * The following constructors are for use by you for whatever
38 * purpose you can think of. Constructing the exception in this
39 * manner makes the exception behave in the normal way - i.e., as
40 * documented in the class "Throwable". The fields "errorToken",
41 * "expectedTokenSequences", and "tokenImage" do not contain
42 * relevant information. The JavaCC generated code does not use
43 * these constructors.
44 */
45
46 ParseException::ParseException() {
47 }
48
49 /** Constructor with message. */
50 ParseException::ParseException(JAVACC_STRING_TYPE message) {
51 }
52
53
54 /**
55 * This is the last token that has been consumed successfully. If
56 * this object has been created due to a parse error, the token
57 * followng this token will (therefore) be the first error token.
58 */
59 Token currentToken;
60
61 /**
62 * Each entry in this array is an array of integers. Each array
63 * of integers represents a sequence of tokens (by their ordinal
64 * values) that is expected at this point of the parse.
65 */
66 int** expectedTokenSequences;
67
68 /**
69 * This is a reference to the "tokenImage" array of the generated
70 * parser within which the parse error occurred. This array is
71 * defined in the generated ...Constants class.
72 */
73 JAVACC_STRING_TYPE* tokenImage;
74
75 /**
76 * It uses "currentToken" and "expectedTokenSequences" to generate a parse
77 * error message and returns it. If this object has been created
78 * due to a parse error, and you do not catch it (it gets thrown
79 * from the parser) the correct error message
80 * gets displayed.
81 */
82 JAVACC_STRING_TYPE ParseException::initialise(Token currentToken,
83 int** expectedTokenSequences,
84 JAVACC_STRING_TYPE* tokenImage) {
85 #if 0
86 //JAVACC_STRING_TYPE eol = System.getProperty("line.separator", "\n");
87 expected = new JAVACC_STRING_TYPE();
88 int maxSize = 0;
89 for (int i = 0; i < expectedTokenSequences.length; i++) {
90 if (maxSize < expectedTokenSequences[i].length) {
91 maxSize = expectedTokenSequences[i].length;
92 }
93 for (int j = 0; j < expectedTokenSequences[i].length; j++) {
94 expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
95 }
96 if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
97 expected.append((JAVACC_CHAR_TYPE*)"...");
98 }
99 expected.append(eol).append(" ");
100 }
101 JAVACC_STRING_TYPE retval = (JAVACC_CHAR_TYPE*)"Encountered \"";
102 Token tok = currentToken.next;
103 for (int i = 0; i < maxSize; i++) {
104 if (i != 0) retval += (JAVACC_CHAR_TYPE*)" ";
105 if (tok.kind == 0) {
106 retval += tokenImage[0];
107 break;
108 }
109 retval += (JAVACC_CHAR_TYPE*)" " + tokenImage[tok.kind];
110 retval += (JAVACC_CHAR_TYPE*)" \"";
111 retval += add_escapes(tok.image);
112 retval += (JAVACC_CHAR_TYPE*)" \"";
113 tok = tok.next;
114 }
115 retval += (JAVACC_CHAR_TYPE*)"\" at line " + currentToken.next.beginLine + (JAVACC_CHAR_TYPE*)", column " + currentToken.next.beginColumn;
116 retval += (JAVACC_CHAR_TYPE*)"." + eol;
117 if (expectedTokenSequences.length == 1) {
118 retval += (JAVACC_CHAR_TYPE*)"Was expecting:" + eol + (JAVACC_CHAR_TYPE*)" ";
119 } else {
120 retval += (JAVACC_CHAR_TYPE*)"Was expecting one of:" + eol + (JAVACC_CHAR_TYPE*)" ";
121 }
122 retval += expected.toString();
123 return retval;
124 #endif
125 return (JAVACC_CHAR_TYPE*)"Parse exception";
126 }
127
128 /**
129 * The end of line JAVACC_STRING_TYPE for this machine.
130 */
131 #define eol "\n"
132
133 /**
134 * Used to convert raw characters to their escaped version
135 * when these raw version cannot be used as part of an ASCII
136 * string literal.
137 */
138 JAVACC_STRING_TYPE ParseException::add_escapes(JAVACC_STRING_TYPE str) {
139 /*
140 JAVACC_STRING_TYPE *retval = new JAVACC_STRING_TYPE();
141 JAVACC_CHAR_TYPE ch;
142 for (int i = 0; i < str.length(); i++) {
143 switch (str.charAt(i))
144 {
145 case 0 :
146 continue;
147 case '\b':
148 retval.append("\\b");
149 continue;
150 case '\t':
151 retval.append("\\t");
152 continue;
153 case '\n':
154 retval.append("\\n");
155 continue;
156 case '\f':
157 retval.append("\\f");
158 continue;
159 case '\r':
160 retval.append("\\r");
161 continue;
162 case '\"':
163 retval.append("\\\"");
164 continue;
165 case '\'':
166 retval.append("\\\'");
167 continue;
168 case '\\':
169 retval.append("\\\\");
170 continue;
171 default:
172 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
173 JAVACC_STRING_TYPE s = "0000" + Integer.toString(ch, 16);
174 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
175 } else {
176 retval.append(ch);
177 }
178 continue;
179 }
180 }
181 return retval.toString();
182 */ return str;
183 }
184
185 }
186 }
187 }
188 /* JavaCC - OriginalChecksum=c2708e5cd23969135595565754679579 (do not edit this line) */