25#include <fmt/format.h>
29 using Value = std::variant<double, std::string>;
41 auto HasValue() const ->
bool {
return std::holds_alternative<T>(
m_data ); }
42 auto HasError() const ->
bool {
return std::holds_alternative<std::string>(
m_data ); }
47 explicit operator bool()
const {
return HasValue(); }
71 m_errors.emplace_back( std::move( aError ) );
76 m_warnings.emplace_back( std::move( aWarning ) );
81 if( aLine >= 0 && aColumn >= 0 )
82 AddError( fmt::format(
"Syntax error at line {}, column {}", aLine, aColumn ) );
84 AddError(
"Syntax error in calculation expression" );
89 AddError(
"Parser failed to parse input" );
101 result += fmt::format(
"Error: {}\n", error );
104 result += fmt::format(
"Warning: {}\n", warning );
std::vector< std::string > m_warnings
auto GetErrors() const -> const std::vector< std::string > &
auto AddError(std::string aError) -> void
auto GetWarnings() const -> const std::vector< std::string > &
auto GetAllMessages() const -> std::string
auto HasWarnings() const -> bool
auto AddParseFailure() -> void
auto AddWarning(std::string aWarning) -> void
auto AddSyntaxError(int aLine=-1, int aColumn=-1) -> void
auto HasErrors() const -> bool
std::vector< std::string > m_errors
auto GetError() const -> const std::string &
auto HasError() const -> bool
std::variant< T, std::string > m_data
Result(std::string aError)
auto HasValue() const -> bool
auto GetValue() const -> const T &
auto MakeValue(T aVal) -> Result< T >
std::variant< double, std::string > Value
auto MakeError(std::string aMsg) -> Result< T >
wxString result
Test unit parsing edge cases and error handling.