2021-01-22 18:01:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-10-31 15:06:48 +01:00
|
|
|
#include <optional>
|
2021-01-22 18:01:39 +01:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
#include <hex/helpers/concepts.hpp>
|
|
|
|
|
2022-01-31 14:37:12 +01:00
|
|
|
#include <hex/pattern_language/error.hpp>
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
namespace hex::pl {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-09-21 21:29:18 +02:00
|
|
|
class ASTNode;
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
class LogConsole {
|
|
|
|
public:
|
2022-02-11 16:53:01 +01:00
|
|
|
enum Level
|
|
|
|
{
|
2021-01-22 18:01:39 +01:00
|
|
|
Debug,
|
|
|
|
Info,
|
|
|
|
Warning,
|
|
|
|
Error
|
|
|
|
};
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const auto &getLog() const { return this->m_consoleLog; }
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
void log(Level level, const std::string &message) {
|
|
|
|
this->m_consoleLog.emplace_back(level, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[noreturn]] static void abortEvaluation(const std::string &message) {
|
|
|
|
abortEvaluation(message, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T = ASTNode>
|
|
|
|
[[noreturn]] static void abortEvaluation(const std::string &message, const std::unique_ptr<T> &node) {
|
|
|
|
abortEvaluation(message, node.get());
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
[[noreturn]] static void abortEvaluation(const std::string &message, const ASTNode *node);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
void clear() {
|
|
|
|
this->m_consoleLog.clear();
|
|
|
|
this->m_lastHardError.reset();
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-01-31 14:37:12 +01:00
|
|
|
void setHardError(const PatternLanguageError &error) { this->m_lastHardError = error; }
|
2021-09-21 21:29:18 +02:00
|
|
|
|
2022-01-31 14:37:12 +01:00
|
|
|
[[nodiscard]] const std::optional<PatternLanguageError> &getLastHardError() { return this->m_lastHardError; };
|
2021-09-21 21:29:18 +02:00
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
private:
|
|
|
|
std::vector<std::pair<Level, std::string>> m_consoleLog;
|
2022-01-31 14:37:12 +01:00
|
|
|
std::optional<PatternLanguageError> m_lastHardError;
|
2021-01-22 18:01:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|