1 /* Generated By:JavaCC: Do not edit this line. ParseException.cc Version 7.0 */
2 /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3 #include "ParseException.h"
4 
5 
6 namespace vhdl {
7 namespace parser {
8 /**
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
12  * parser.
13  *
14  * You can modify this class to customize your error reporting
15  * mechanisms so long as you retain the fields.
16  */
17 
18   /**
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.
23    */
ParseException(Token currentTokenVal,int ** expectedTokenSequencesVal,JJString * tokenImageVal)24   ParseException::ParseException(Token currentTokenVal,
25                         int** expectedTokenSequencesVal,
26                         JJString* tokenImageVal
27                        )
28   {
29     initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal);
30     currentToken = currentTokenVal;
31     expectedTokenSequences = expectedTokenSequencesVal;
32     tokenImage = tokenImageVal;
33   }
34 
35   /**
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
42    * these constructors.
43    */
44 
ParseException()45   ParseException::ParseException() {
46   }
47 
48   /** Constructor with message. */
ParseException(const JJString & message)49   ParseException::ParseException(const JJString& message) {
50   }
51 
52 
53   /**
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.
57    */
58   Token currentToken;
59 
60   /**
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.
64    */
65   int** expectedTokenSequences;
66 
67   /**
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.
71    */
72   JJString* tokenImage;
73 
74   /**
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
79    * gets displayed.
80    */
initialise(Token currentToken,int ** expectedTokenSequences,JJString * tokenImage)81   JJString ParseException::initialise(Token currentToken,
82                            int** expectedTokenSequences,
83                            JJString* tokenImage) {
84 #if 0
85     //JJString eol = System.getProperty("line.separator", "\n");
86      expected = new JJString();
87     int maxSize = 0;
88     for (int i = 0; i < expectedTokenSequences.length; i++) {
89       if (maxSize < expectedTokenSequences[i].length) {
90         maxSize = expectedTokenSequences[i].length;
91       }
92       for (int j = 0; j < expectedTokenSequences[i].length; j++) {
93         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
94       }
95       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
96         expected.append((JJChar*)"...");
97       }
98       expected.append(eol).append("    ");
99     }
100     JJString retval = (JJChar*)"Encountered \"";
101     Token tok = currentToken.next;
102     for (int i = 0; i < maxSize; i++) {
103       if (i != 0) retval += (JJChar*)" ";
104       if (tok.kind == 0) {
105         retval += tokenImage[0];
106         break;
107       }
108       retval += (JJChar*)" " + tokenImage[tok.kind];
109       retval += (JJChar*)" \"";
110       retval += add_escapes(tok.image);
111       retval += (JJChar*)" \"";
112       tok = tok.next;
113     }
114     retval += (JJChar*)"\" at line " + currentToken.next.beginLine + (JJChar*)", column " + currentToken.next.beginColumn;
115     retval += (JJChar*)"." + eol;
116     if (expectedTokenSequences.length == 1) {
117       retval += (JJChar*)"Was expecting:" + eol + (JJChar*)"    ";
118     } else {
119       retval += (JJChar*)"Was expecting one of:" + eol + (JJChar*)"    ";
120     }
121     retval += expected.toString();
122     return retval;
123 #endif
124     return (JJChar*)"Parse exception";
125   }
126 
127   /**
128    * The end of line JJString for this machine.
129    */
130 #define eol "\n"
131 
132   /**
133    * Used to convert raw characters to their escaped version
134    * when these raw version cannot be used as part of an ASCII
135    * string literal.
136    */
add_escapes(const JJString & str)137    JJString ParseException::add_escapes(const JJString& str) {
138 /*
139       JJString *retval = new JJString();
140       JJChar ch;
141       for (int i = 0; i < str.length(); i++) {
142         switch (str.charAt(i))
143         {
144            case '\b':
145               retval.append("\\b");
146               continue;
147            case '\t':
148               retval.append("\\t");
149               continue;
150            case '\n':
151               retval.append("\\n");
152               continue;
153            case '\f':
154               retval.append("\\f");
155               continue;
156            case '\r':
157               retval.append("\\r");
158               continue;
159            case '\"':
160               retval.append("\\\"");
161               continue;
162            case '\'':
163               retval.append("\\\'");
164               continue;
165            case '\\':
166               retval.append("\\\\");
167               continue;
168            default:
169               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
170                  JJString s = "0000" + Integer.toString(ch, 16);
171                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
172               } else {
173                  retval.append(ch);
174               }
175               continue;
176         }
177       }
178       return retval.toString();
179 */ return str;
180    }
181 
182 }
183 }
184 /* JavaCC - OriginalChecksum=7a72405661a136830ccf7f3cab0fffdc (do not edit this line) */
185