41 lines
2.0 KiB
C++
41 lines
2.0 KiB
C++
#ifndef MALACHSCRIPT_DIAGNOSTICTYPEEN_US_HPP
|
|
#define MALACHSCRIPT_DIAGNOSTICTYPEEN_US_HPP
|
|
|
|
#include "../../extern/format.hpp"
|
|
#include "Diagnostic.hpp"
|
|
|
|
namespace MalachScript::Diagnostics {
|
|
class DiagnosticTypeHelper {
|
|
public:
|
|
static std::string ToEnglishString(const Diagnostic* diag) {
|
|
switch (diag->GetType()) {
|
|
case DiagnosticType::UnknownCharacter:
|
|
return util::Format("Unknown character: '{0}'", diag->GetFormats());
|
|
case DiagnosticType::ExpectedEndOfString:
|
|
return util::Format("Expected end of string, found {0}", diag->GetFormats());
|
|
case DiagnosticType::UnexpectedToken:
|
|
if (diag->GetFormats().size() == 1) {
|
|
return util::Format("Unexpected Token: '{0}'", diag->GetFormats());
|
|
} else if (diag->GetFormats().size() == 2) {
|
|
return util::Format("Unexpected Token. Expected: '{0}', but found '{-1}'", diag->GetFormats());
|
|
} else if (diag->GetFormats().size() > 2) {
|
|
return util::Format("Unexpected Token. Expected any of: '{0..-2}', but found '{-1}'",
|
|
diag->GetFormats());
|
|
}
|
|
case DiagnosticType::DoubleProperty: return "Property block found twice.";
|
|
|
|
case DiagnosticType::UnknownType:
|
|
return util::Format("Unknown Type Encounted: '{0}'", diag->GetFormats());
|
|
case DiagnosticType::TypeAlreadyDefined:
|
|
return util::Format("Type already defined: '{0}'", diag->GetFormats());
|
|
case DiagnosticType::CircularTypeReference:
|
|
return util::Format("Type '{0}' can't hold a value type of type '{1}' due to a circular reference",
|
|
diag->GetFormats());
|
|
}
|
|
return std::to_string((uint8_t)diag->GetType());
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // MALACHSCRIPT_DIAGNOSTICTYPEEN_US_HPP
|