21 lines
600 B
C++
21 lines
600 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::report(int line, const std::string &where, const std::string &message) {
|
|
std::cout << "[line " << line << "] Error" << where << ": " << message << '\n';
|
|
had_error = true;
|
|
}
|