Run clang-format on project

This commit is contained in:
apio 2022-08-03 14:56:15 +00:00
parent 3eea369072
commit e0661f9f8f
3 changed files with 50 additions and 38 deletions

View File

@ -1,40 +1,52 @@
#pragma once
#include "Token.h"
#include "Error.h"
#include "Token.h"
// Kinda copying Rust here, but it's a great idea.
template<typename T>
class Result
template<typename T> class Result
{
public:
Result() = default;
bool is_error() const { return m_is_error; }
void ethrow() { Error::throw_error(m_token->loc,m_token->line(),m_error); }
bool is_error() const
{
return m_is_error;
}
void ethrow()
{
Error::throw_error(m_token->loc, m_token->line(), m_error);
}
std::shared_ptr<T> get()
{
return m_result;
}
protected:
Token* m_token;
std::shared_ptr<T> m_result;
bool m_is_error;
std::string m_error;
Result(T* result, Token* token) : m_result(result), m_token(token), m_is_error(false) {}
Result(const std::string& error, Token* token) : m_error(std::move(error)), m_token(token), m_is_error(true) {}
Result(T* result, Token* token) : m_result(result), m_token(token), m_is_error(false)
{
}
Result(const std::string& error, Token* token) : m_error(std::move(error)), m_token(token), m_is_error(true)
{
}
};
template<typename T>
class Ok final : public Result<T>
template<typename T> class Ok final : public Result<T>
{
public:
Ok(T* result, Token* token) : Result<T>(result,token) {}
Ok(T* result, Token* token) : Result<T>(result, token)
{
}
};
template<typename T>
class Err final : public Result<T>
template<typename T> class Err final : public Result<T>
{
public:
Err(const std::string& error, Token* token) : Result<T>(std::move(error),token) {}
Err(const std::string& error, Token* token) : Result<T>(std::move(error), token)
{
}
};