diff --git a/furc/include/furc/front/token.hpp b/furc/include/furc/front/token.hpp index f9483c7..7f5193f 100644 --- a/furc/include/furc/front/token.hpp +++ b/furc/include/furc/front/token.hpp @@ -359,6 +359,17 @@ struct token_error { * @return true if the errors are not equal. */ bool operator!=(const token_error& rhs) const { return !this->operator==(rhs); } + + /** + * @brief Prints a token error to an output stream. + * + * @param os Output stream. + * @param error Token error to print. + * @return The output stream. + */ + friend std::ostream& operator<<(std::ostream& os, const token_error& error) { + return os << error.location << ": error: unknown"; + } }; using token_r = furlang::result; /**< Alias to a token result. */ diff --git a/furlang/include/furlang/result.hpp b/furlang/include/furlang/result.hpp index e45ccac..9dcdf76 100644 --- a/furlang/include/furlang/result.hpp +++ b/furlang/include/furlang/result.hpp @@ -2,6 +2,7 @@ #define FURLANG_RESULT_HPP #include +#include #include namespace furlang { @@ -215,6 +216,17 @@ public: */ bool operator!=(const value_type& rhs) const { return !this->operator==(rhs); } + /** + * @brief Prints a result to an output stream. + * + * @param os Output stream. + * @param result Result to print. + * @return The output stream. + */ + friend std::ostream& operator<<(std::ostream& os, const result& result) { + return result.has_value() ? os << result.value() : os << result.error(); + } + /** * @brief Returns a reference to value. *