diff --git a/include/toml11/fwd/error_info_fwd.hpp b/include/toml11/fwd/error_info_fwd.hpp index 5b8600c..1382dd6 100644 --- a/include/toml11/fwd/error_info_fwd.hpp +++ b/include/toml11/fwd/error_info_fwd.hpp @@ -7,17 +7,41 @@ namespace toml { +enum class error_kind : std::uint8_t +{ + runtime_error, + out_of_range, + type_error, + syntax_error, + file_io_error +}; + // error info returned from parser. struct error_info { error_info(std::string t, source_location l, std::string m, std::string s = "") - : title_(std::move(t)), locations_{std::make_pair(std::move(l), std::move(m))}, + : kind_(error_kind::runtime_error), title_(std::move(t)), + locations_{std::make_pair(std::move(l), std::move(m))}, suffix_(std::move(s)) {} error_info(std::string t, std::vector> l, std::string s = "") - : title_(std::move(t)), locations_(std::move(l)), suffix_(std::move(s)) + : kind_(error_kind::runtime_error), title_(std::move(t)), + locations_(std::move(l)), suffix_(std::move(s)) + {} + + error_info(error_kind k, std::string t, source_location l, std::string m, std::string s = "") + : kind_(k), title_(std::move(t)), + locations_{std::make_pair(std::move(l), std::move(m))}, + suffix_(std::move(s)) + {} + + error_info(error_kind k, std::string t, + std::vector> l, + std::string s = "") + : kind_(k), title_(std::move(t)), + locations_(std::move(l)), suffix_(std::move(s)) {} std::string const& title() const noexcept {return title_;} @@ -36,6 +60,7 @@ struct error_info private: + error_kind kind_; std::string title_; std::vector> locations_; std::string suffix_; // hint or something like that @@ -78,6 +103,13 @@ error_info make_error_info( error_info ei(std::move(title), std::move(loc), std::move(msg)); return detail::make_error_info_rec(ei, std::forward(tail) ... ); } +template +error_info make_error_info(error_kind k, + std::string title, source_location loc, std::string msg, Ts&& ... tail) +{ + error_info ei(k, std::move(title), std::move(loc), std::move(msg)); + return detail::make_error_info_rec(ei, std::forward(tail) ... ); +} std::string format_error(const std::string& errkind, const error_info& err); std::string format_error(const error_info& err); diff --git a/include/toml11/value.hpp b/include/toml11/value.hpp index 721a77e..cfe39d4 100644 --- a/include/toml11/value.hpp +++ b/include/toml11/value.hpp @@ -2120,6 +2120,13 @@ error_info make_error_info( v.location(), std::move(msg), std::forward(tail)...); } template +error_info make_error_info(error_kind k, + std::string title, const basic_value& v, std::string msg, Ts&& ... tail) +{ + return make_error_info(k, std::move(title), + v.location(), std::move(msg), std::forward(tail)...); +} +template std::string format_error(std::string title, const basic_value& v, std::string msg, Ts&& ... tail) {