bloglang/13/error.cpp

29 lines
940 B
C++
Raw Normal View History

2020-09-08 18:38:05 -07:00
#include "error.hpp"
const char* type_error::what() const noexcept {
return "an error occured while checking the types of the program";
}
2020-09-09 15:08:43 -07:00
void type_error::pretty_print(std::ostream& to, parse_driver& drv) {
to << "encountered error while typechecking program: ";
to << description << std::endl;
if(loc) {
to << "occuring on line " << loc->begin.line << ":" << std::endl;
to << std::endl << "```" << std::endl;
drv.print_highlighted_location(to, *loc);
2020-09-09 15:25:48 -07:00
to << "```" << std::endl << std::endl;
2020-09-09 15:08:43 -07:00
}
}
void unification_error::pretty_print(std::ostream& to, parse_driver& drv, type_mgr& mgr) {
type_error::pretty_print(to, drv);
to << "the expected type was:" << std::endl;
to << " \033[34m";
left->print(mgr, to);
to << std::endl << "\033[0mwhile the actual type was:" << std::endl;
to << " \033[32m";
right->print(mgr, to);
to << "\033[0m" << std::endl;
}