31 lines
753 B
C++
31 lines
753 B
C++
#ifndef ERROR_HANDLER_HH
|
|
#define ERROR_HANDLER_HH
|
|
|
|
#include "tokenizer.hh"
|
|
#include <exception>
|
|
#include <string>
|
|
|
|
struct RuntimeException : public std::exception {
|
|
RuntimeException(Token token, const std::string& message) : token{token}, message{message} {}
|
|
const char* what() const noexcept override {
|
|
return message.c_str();
|
|
}
|
|
|
|
Token token;
|
|
private:
|
|
std::string message;
|
|
};
|
|
|
|
struct ErrorHandler {
|
|
ErrorHandler() : had_error{false} {};
|
|
void error(int line, const std::string &message);
|
|
void error(Token token, const std::string &message);
|
|
void runtime_error(const RuntimeException &exception);
|
|
void report(int line, const std::string &where, const std::string &message);
|
|
|
|
bool had_error;
|
|
bool had_runtime_error;
|
|
};
|
|
|
|
#endif
|