ErrorHandler.h
Go to the documentation of this file.
1 /* Generated By:JavaCC: Do not edit this line. ErrorHandler.h Version 6.2 */
2 /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true,BUILD_PARSER=true,BUILD_TOKEN_MANAGER=true */
3 #ifndef ERRORHANDLER_H
4 #define ERRORHANDLER_H
5 #include <stdio.h>
6 #include <string>
7 #include "JavaCC.h"
8 #include "Token.h"
9 
10 namespace vhdl {
11 namespace parser {
12 
14 
15  class VhdlParser;
16  class ErrorHandler {
17  friend class VhdlParserTokenManager;
18  friend class VhdlParser;
19  protected:
21  public:
22  // Called when the parser encounters a different token when expecting to
23  // consume a specific kind of token.
24  // expectedKind - token kind that the parser was trying to consume.
25  // expectedToken - the image of the token - tokenImages[expectedKind].
26  // actual - the actual token that the parser got instead.
27  virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, VhdlParser *parser) {
28  error_count++;
29  fprintf(stderr, "Expecting %s at: %d:%d but got %s\n", addUnicodeEscapes(expectedToken).c_str(), actual->beginLine, actual->beginColumn, addUnicodeEscapes(actual->image).c_str());
30  }
31  // Called when the parser cannot continue parsing.
32  // last - the last token successfully parsed.
33  // unexpected - the token at which the error occurs.
34  // production - the production in which this error occurrs.
35  virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *parser) {
36  error_count++;
37  fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", addUnicodeEscapes(unexpected->image).c_str(), unexpected->beginLine, unexpected->beginColumn, production.c_str());
38  }
39  virtual int getErrorCount() {
40  return error_count;
41  }
43  fprintf(stderr, "Error: %s\n", (char*)message.c_str());
44  }
45  virtual ~ErrorHandler() {}
46  ErrorHandler() { error_count = 0; }
47  };
48 
51  friend class VhdlParserTokenManager;
52  protected:
54  public:
55  // Returns a detailed message for the Error when it is thrown by the
56  // token manager to indicate a lexical error.
57  // Parameters :
58  // EOFSeen : indicates if EOF caused the lexical error
59  // curLexState : lexical state in which this error occurred
60  // errorLine : line number when the error occurred
61  // errorColumn : column number when the error occurred
62  // errorAfter : prefix that was seen before this error occurred
63  // curchar : the offending character
64  //
65  virtual void lexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, VhdlParserTokenManager* token_manager) {
66  // by default, we just print an error message and return.
67  fprintf(stderr, "Lexical error at: %d:%d. Encountered: %c after: %s.\n", errorLine, errorColumn, curChar, (EOFSeen? "EOF" : (const char*)errorAfter.c_str()));
68  }
69  virtual void lexicalError(JAVACC_STRING_TYPE errorMessage, VhdlParserTokenManager* token_manager) {
70  fprintf(stderr, "%s\n", (char*)errorMessage.c_str());
71  }
73  };
74 
75 }
76 }
77 
78 #endif
79 /* JavaCC - OriginalChecksum=c18f1105ba178be8e21cc9f279f94496 (do not edit this line) */
virtual void lexicalError(JAVACC_STRING_TYPE errorMessage, VhdlParserTokenManager *token_manager)
Definition: ErrorHandler.h:69
#define JAVACC_STRING_TYPE
Definition: JavaCC.h:16
JAVACC_STRING_TYPE image
Definition: Token.h:38
#define JAVACC_CHAR_TYPE
Definition: JavaCC.h:12
#define JAVACC_SIMPLE_STRING
Definition: JavaCC.h:19
virtual int getErrorCount()
Definition: ErrorHandler.h:39
virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, VhdlParser *parser)
Definition: ErrorHandler.h:27
virtual void handleOtherError(JAVACC_STRING_TYPE message, VhdlParser *parser)
Definition: ErrorHandler.h:42
JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str)
virtual void lexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, VhdlParserTokenManager *token_manager)
Definition: ErrorHandler.h:65
virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *parser)
Definition: ErrorHandler.h:35
static QCString str