Support for diagnostics system.
This commit is contained in:
23
src/Diagnostics/Diagnostic.hpp
Normal file
23
src/Diagnostics/Diagnostic.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ELOHIMSCRIPT_DIAGNOSTIC_HPP
|
||||
#define ELOHIMSCRIPT_DIAGNOSTIC_HPP
|
||||
|
||||
#include "../Parser/TextSpan.hpp"
|
||||
#include "DiagnosticLevel.hpp"
|
||||
#include "DiagnosticType.hpp"
|
||||
namespace ElohimScript::Diagnostics {
|
||||
class Diagnostic {
|
||||
DiagnosticLevel _level;
|
||||
DiagnosticType _type;
|
||||
TextSpan _span;
|
||||
|
||||
public:
|
||||
inline Diagnostic(DiagnosticLevel level, DiagnosticType type, TextSpan span)
|
||||
: _level(level), _type(type), _span(span) {}
|
||||
|
||||
[[nodiscard]] inline DiagnosticLevel GetLevel() const noexcept { return _level; }
|
||||
[[nodiscard]] inline DiagnosticType GetType() const noexcept { return _type; }
|
||||
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ELOHIMSCRIPT_DIAGNOSTIC_HPP
|
||||
15
src/Diagnostics/DiagnosticLevel.hpp
Normal file
15
src/Diagnostics/DiagnosticLevel.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef ELOHIMSCRIPT_DIAGNOSTICLEVEL_HPP
|
||||
#define ELOHIMSCRIPT_DIAGNOSTICLEVEL_HPP
|
||||
|
||||
#include <cstdint>
|
||||
namespace ElohimScript::Diagnostics {
|
||||
enum class DiagnosticLevel : uint8_t {
|
||||
Trace,
|
||||
Information,
|
||||
Warning,
|
||||
Error,
|
||||
Critical,
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ELOHIMSCRIPT_DIAGNOSTICLEVEL_HPP
|
||||
20
src/Diagnostics/DiagnosticType.hpp
Normal file
20
src/Diagnostics/DiagnosticType.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef ELOHIMSCRIPT_DIAGNOSTICTYPE_HPP
|
||||
#define ELOHIMSCRIPT_DIAGNOSTICTYPE_HPP
|
||||
#include <string>
|
||||
|
||||
namespace ElohimScript::Diagnostics {
|
||||
enum class DiagnosticType : uint8_t { UnknownToken, InvalidNumericalBase, ExpectedEndOfString };
|
||||
|
||||
class DiagnosticTypeHelper {
|
||||
static std::string ToEnglishString(DiagnosticType type) {
|
||||
switch (type) {
|
||||
case DiagnosticType::UnknownToken: return "Unknown token";
|
||||
case DiagnosticType::InvalidNumericalBase: return "Invalid numerical base";
|
||||
case DiagnosticType::ExpectedEndOfString: return "Expected end of string";
|
||||
}
|
||||
return std::to_string((uint8_t)type);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ELOHIMSCRIPT_DIAGNOSTICTYPE_HPP
|
||||
1
src/Diagnostics/Diagnostics.cpp
Normal file
1
src/Diagnostics/Diagnostics.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "Diagnostics.hpp"
|
||||
25
src/Diagnostics/Diagnostics.hpp
Normal file
25
src/Diagnostics/Diagnostics.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef ELOHIMSCRIPT_DIAGNOSTICS_HPP
|
||||
#define ELOHIMSCRIPT_DIAGNOSTICS_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "Diagnostic.hpp"
|
||||
|
||||
namespace ElohimScript::Diagnostics {
|
||||
class Diagnostics {
|
||||
std::vector<Diagnostic> _messages;
|
||||
|
||||
public:
|
||||
inline void Log(DiagnosticLevel level, DiagnosticType type, TextSpan span) {
|
||||
_messages.emplace_back(level, type, span);
|
||||
}
|
||||
inline void LogTrace(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Trace, type, span); }
|
||||
inline void LogInfo(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Information, type, span); }
|
||||
inline void LogWarning(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Warning, type, span); }
|
||||
inline void LogError(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Error, type, span); }
|
||||
inline void LogCritical(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Critical, type, span); }
|
||||
|
||||
[[nodiscard]] const std::vector<Diagnostic>& GetMessages() const noexcept { return _messages; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ELOHIMSCRIPT_DIAGNOSTICS_HPP
|
||||
Reference in New Issue
Block a user