@@ -359,6 +359,17 @@ struct token_error {
|
|||||||
* @return true if the errors are not equal.
|
* @return true if the errors are not equal.
|
||||||
*/
|
*/
|
||||||
bool operator!=(const token_error& rhs) const { return !this->operator==(rhs); }
|
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<token, token_error>; /**< Alias to a token result. */
|
using token_r = furlang::result<token, token_error>; /**< Alias to a token result. */
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define FURLANG_RESULT_HPP
|
#define FURLANG_RESULT_HPP
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <ostream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace furlang {
|
namespace furlang {
|
||||||
@@ -215,6 +216,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool operator!=(const value_type& rhs) const { return !this->operator==(rhs); }
|
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.
|
* @brief Returns a reference to value.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user