ErrorHandler.h 3.43 KB
Newer Older
1
/* Generated By:JavaCC: Do not edit this line. ErrorHandler.h Version 6.0 */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
2
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true,BUILD_PARSER=true,BUILD_TOKEN_MANAGER=true */
3 4
#ifndef ERRORHANDLER_H
#define ERRORHANDLER_H
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5
//#include <string>
6 7 8 9 10
#include "JavaCC.h"
#include "Token.h"

namespace vhdl {
namespace parser {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
11 12 13 14

//JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str);

  class VhdlParser;
15
  class ErrorHandler {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
16 17
    friend class VhdlParserTokenManager;
    friend class VhdlParser;
18 19 20 21 22 23 24 25
    protected:
      int error_count;
    public:
      // Called when the parser encounters a different token when expecting to
      // consume a specific kind of token.
      // expectedKind - token kind that the parser was trying to consume.
      // expectedToken - the image of the token - tokenImages[expectedKind].
      // actual - the actual token that the parser got instead.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
26
      virtual void handleUnexpectedToken(int , JAVACC_STRING_TYPE , Token *, VhdlParser *) {
27
        error_count++;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
28
    //    fprintf(stderr, "Expecting %s at: %d:%d but got %s\n", addUnicodeEscapes(expectedToken).c_str(), actual->beginLine, actual->beginColumn, addUnicodeEscapes(actual->image).c_str());
29 30 31 32 33
      }
      // Called when the parser cannot continue parsing.
      // last - the last token successfully parsed.
      // unexpected - the token at which the error occurs.
      // production - the production in which this error occurrs.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
34
      virtual void handleParseError(Token *, Token *, JAVACC_SIMPLE_STRING , VhdlParser *) {
35
        error_count++;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
36
  //     fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", addUnicodeEscapes(unexpected->image).c_str(), unexpected->beginLine, unexpected->beginColumn, production.c_str());
37 38 39 40
      }
      virtual int getErrorCount() {
        return error_count;
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
41 42 43
      virtual void handleOtherError(JAVACC_STRING_TYPE message, VhdlParser *) {
        fprintf(stderr, "Error: %s\n", (char*)message.c_str());
      }
44 45 46
      virtual ~ErrorHandler() {}
      ErrorHandler() { error_count = 0; }
  };
Dimitri van Heesch's avatar
Dimitri van Heesch committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

  class VhdlParserTokenManager;
  class TokenManagerErrorHandler {
    friend class VhdlParserTokenManager;
    protected:
      int error_count;
    public:
       // Returns a detailed message for the Error when it is thrown by the
       // token manager to indicate a lexical error.
       // Parameters :
       //    EOFSeen     : indicates if EOF caused the lexical error
       //    curLexState : lexical state in which this error occurred
       //    errorLine   : line number when the error occurred
       //    errorColumn : column number when the error occurred
       //    errorAfter  : prefix that was seen before this error occurred
       //    curchar     : the offending character
       //
       virtual void lexicalError(bool EOFSeen, int /*lexState*/, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, VhdlParserTokenManager*) {
        // by default, we just print an error message and return.
        fprintf(stderr, "Lexical error at: %d:%d. Encountered: %c after: %s.\n", errorLine, errorColumn, curChar, (EOFSeen? "EOF" : (const char*)errorAfter.c_str()));
      }
       virtual void lexicalError(JAVACC_STRING_TYPE errorMessage, VhdlParserTokenManager* ) {
        fprintf(stderr, "%s\n", (char*)errorMessage.c_str());
      }
      virtual ~TokenManagerErrorHandler() {}
  };

74 75 76 77
}
}

#endif
Dimitri van Heesch's avatar
Dimitri van Heesch committed
78
/* JavaCC - OriginalChecksum=685d19cb4cd943b60089f599e45f23ad (do not edit this line) */