4#include <unordered_map>
13namespace circus::error {
24#define ERROR_TYPE(NAME) NAME
28enum CIRCUS_ERROR_TYPES : std::uint64_t {
35#define ERROR_TYPE(NAME) #NAME
36inline const char* REFLECTED_ERROR_MAP[]{
61class parser_reporter {
63 using underlying_type = std::underlying_type_t<flag_type::enum_type>;
64 std::stack<std::string> error_log_stack;
65 std::stack<std::string> temp;
73 static std::string match_and_ret(
const underlying_type& from,
const underlying_type& to) {
74 return ((from & to) == to) ? REFLECTED_ERROR_MAP[from] :
"";
81 static std::string to_stringized_types(
const underlying_type& type) {
83 ret += match_and_ret(type, error::SYNTAX);
84 return ret.empty() ?
"UNKNOWN" : ret;
88 parser_reporter() =
default;
94 [[nodiscard]]
bool empty() const noexcept {
95 return error_log_stack.empty();
103 void report(
const flag_type& type,
const std::string& message, std::pair<std::size_t, std::size_t> location)
noexcept {
104 std::string out =
"[CIRCUS][PARSER_ERROR][" + to_stringized_types(type.flags) +
"] " + message +
" at (" + std::to_string(location.first) +
" : " + std::to_string(location.second) +
")";
105 error_log_stack.push(out);
111 while (!error_log_stack.empty()) {
112 auto top = error_log_stack.top();
113 std::clog << top << std::endl;
115 error_log_stack.pop();
118 while (!temp.empty()) {
119 auto top = temp.top();
120 error_log_stack.push(top);
129 while (!error_log_stack.empty()) {
130 error_log_stack.pop();
144 requires std::is_enum_v<E>
146 using U = std::underlying_type_t<E>;
147 return static_cast<E
>(
static_cast<U
>(lhs) |
static_cast<U
>(rhs));
157 requires std::is_enum_v<E>
159 using U = std::underlying_type_t<E>;
160 return static_cast<E
>(
static_cast<U
>(lhs) &
static_cast<U
>(rhs));
169 requires std::is_enum_v<E>
171 using U = std::underlying_type_t<E>;
172 return static_cast<E
>(~static_cast<U>(val));
Provides compile-time traits and C++20 concepts for type introspection used throughout the Circus lib...
Aggregates and manages parser error messages with support for logging and flushing.
Definition circus_error.hpp:61
A utility class for strongly typed enum flags with bitwise operations.
Definition enum_flag.hpp:25
CIRCUS_ERROR_TYPES enum_type
Definition enum_flag.hpp:30
Provides a type-safe wrapper for enum flags with bitwise operations.
parser_error(flag_type E, const std::string &what)
Constructs a parser error with a flag type and descriptive message.
Definition circus_error.hpp:55
void report(const flag_type &type, const std::string &message, std::pair< std::size_t, std::size_t > location) noexcept
Reports an error by adding a formatted message to the error log stack.
Definition circus_error.hpp:103
constexpr E operator|(E lhs, E rhs)
Bitwise OR operator for enum error types.
Definition circus_error.hpp:145
void flush_errors() noexcept
Clears all errors from the error log stack.
Definition circus_error.hpp:128
constexpr E operator~(E val)
Bitwise NOT operator for enum error types.
Definition circus_error.hpp:170
bool empty() const noexcept
Checks if there are any errors logged.
Definition circus_error.hpp:94
flag_type type_of
The type of parser error that occurred.
Definition circus_error.hpp:49
void log_errors() noexcept
Logs all errors to std::clog and preserves the error stack.
Definition circus_error.hpp:110
constexpr E operator&(E lhs, E rhs)
Bitwise AND operator for enum error types.
Definition circus_error.hpp:158