Refactor errors and update post draft.

This commit is contained in:
2020-09-11 21:29:49 -07:00
parent 725958137a
commit 6b8d3b0f8a
8 changed files with 431 additions and 42 deletions

View File

@@ -7,12 +7,26 @@
using maybe_location = std::optional<yy::location>;
struct type_error : std::exception {
struct compiler_error : std::exception {
std::string description;
maybe_location loc;
compiler_error(std::string d, maybe_location l = std::nullopt)
: description(std::move(d)), loc(std::move(l)) {}
const char* what() const noexcept override;
void print_about(std::ostream& to);
void print_location(std::ostream& to, parse_driver& drv, bool highlight = false);
void pretty_print(std::ostream& to, parse_driver& drv);
};
struct type_error : compiler_error {
std::optional<yy::location> loc;
type_error(std::string d, maybe_location l = std::nullopt)
: description(std::move(d)), loc(std::move(l)) {}
: compiler_error(std::move(d), std::move(l)) {}
const char* what() const noexcept override;
void pretty_print(std::ostream& to, parse_driver& drv);