javacc-6.1.2.classes.templates.cpp.ErrorHandler.h.template Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javacc Show documentation
Show all versions of javacc Show documentation
JavaCC is a parser/scanner generator for Java.
\#ifndef ERRORHANDLER_H
\#define ERRORHANDLER_H
\#include
\#include "JavaCC.h"
\#include "Token.h"
#if NAMESPACE
namespace ${NAMESPACE_OPEN}
#fi
JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str);
#if BUILD_PARSER
class ${PARSER_NAME};
class ErrorHandler {
friend class ${PARSER_NAME}TokenManager;
friend class ${PARSER_NAME};
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.
virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, ${PARSER_NAME} *parser) {
error_count++;
fprintf(stderr, "Expecting %s at: %d:%d but got %s\n", addUnicodeEscapes(expectedToken).c_str(), actual->beginLine, actual->beginColumn, addUnicodeEscapes(actual->image).c_str());
}
// 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.
virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, ${PARSER_NAME} *parser) {
error_count++;
fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", addUnicodeEscapes(unexpected->image).c_str(), unexpected->beginLine, unexpected->beginColumn, production.c_str());
}
virtual int getErrorCount() {
return error_count;
}
virtual void handleOtherError(JAVACC_STRING_TYPE message, ${PARSER_NAME} *parser) {
fprintf(stderr, "Error: %s\n", (char*)message.c_str());
}
virtual ~ErrorHandler() {}
ErrorHandler() { error_count = 0; }
};
#fi
#if BUILD_TOKEN_MANAGER
class ${PARSER_NAME}TokenManager;
class TokenManagerErrorHandler {
friend class ${PARSER_NAME}TokenManager;
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, ${PARSER_NAME}TokenManager* token_manager) {
// 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, ${PARSER_NAME}TokenManager* token_manager) {
fprintf(stderr, "%s\n", (char*)errorMessage.c_str());
}
virtual ~TokenManagerErrorHandler() {}
};
#fi
#if NAMESPACE
${NAMESPACE_CLOSE}
#fi
\#endif