ParseException.cc
Go to the documentation of this file.
1 /* Generated By:JavaCC: Do not edit this line. ParseException.cc Version 6.2 */
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  */
25  int** expectedTokenSequencesVal,
26  JAVACC_STRING_TYPE* 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 
46  }
47 
48  /** Constructor with 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  */
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  */
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  */
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  */
82  int** expectedTokenSequences,
83  JAVACC_STRING_TYPE* tokenImage) {
84 #if 0
85  //JAVACC_STRING_TYPE eol = System.getProperty("line.separator", "\n");
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((JAVACC_CHAR_TYPE*)"...");
97  }
98  expected.append(eol).append(" ");
99  }
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*)" ";
104  if (tok.kind == 0) {
105  retval += tokenImage[0];
106  break;
107  }
108  retval += (JAVACC_CHAR_TYPE*)" " + tokenImage[tok.kind];
109  retval += (JAVACC_CHAR_TYPE*)" \"";
110  retval += add_escapes(tok.image);
111  retval += (JAVACC_CHAR_TYPE*)" \"";
112  tok = tok.next;
113  }
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*)" ";
118  } else {
119  retval += (JAVACC_CHAR_TYPE*)"Was expecting one of:" + eol + (JAVACC_CHAR_TYPE*)" ";
120  }
121  retval += expected.toString();
122  return retval;
123 #endif
124  return (JAVACC_CHAR_TYPE*)"Parse exception";
125  }
126 
127  /**
128  * The end of line JAVACC_STRING_TYPE 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  */
138 /*
139  JAVACC_STRING_TYPE *retval = new JAVACC_STRING_TYPE();
140  JAVACC_CHAR_TYPE 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  JAVACC_STRING_TYPE 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=9f6af8fd72f5fe3e4210cf02acbd8387 (do not edit this line) */
JAVACC_STRING_TYPE * tokenImage
Token * next
Definition: Token.h:48
#define JAVACC_STRING_TYPE
Definition: JavaCC.h:16
const char expected[]
Definition: Exception_t.cc:22
JAVACC_STRING_TYPE image
Definition: Token.h:38
JAVACC_STRING_TYPE add_escapes(JAVACC_STRING_TYPE str)
#define eol
#define JAVACC_CHAR_TYPE
Definition: JavaCC.h:12
JAVACC_STRING_TYPE initialise(Token currentToken, int **expectedTokenSequences, JAVACC_STRING_TYPE *tokenImage)
static QCString str