26 lines
799 B
C++
26 lines
799 B
C++
#include "error_handler.hh"
|
|
#include "tokenizer.hh"
|
|
#include <iostream>
|
|
|
|
void ErrorHandler::error(int line, const std::string &message) {
|
|
report(line, "", message);
|
|
}
|
|
|
|
void ErrorHandler::error(Token token, const std::string &message) {
|
|
if (token.type == TokenType::EOFILE) {
|
|
report(token.line, " at end", message);
|
|
} else {
|
|
report(token.line, " at '" + token.lexeme + "'", message);
|
|
}
|
|
}
|
|
|
|
void ErrorHandler::runtime_error(const RuntimeException &exception) {
|
|
std::cout << "RuntimeException [" << exception.token.line << "]: " << exception.what() << '\n';
|
|
had_runtime_error = true;
|
|
}
|
|
|
|
void ErrorHandler::report(int line, const std::string &where, const std::string &message) {
|
|
std::cout << "[line " << line << "] Error" << where << ": " << message << '\n';
|
|
had_error = true;
|
|
}
|