AST: Add error node

This commit is contained in:
Riyyi
2023-03-19 12:04:48 +01:00
parent 46e037e39e
commit b604d7ddb5
2 changed files with 26 additions and 0 deletions
+7
View File
@@ -10,6 +10,13 @@
namespace blaze { namespace blaze {
Error::Error(const std::string& error)
: m_error(error)
{
}
// -----------------------------------------
List::~List() List::~List()
{ {
for (auto node : m_nodes) { for (auto node : m_nodes) {
+19
View File
@@ -23,6 +23,7 @@ public:
template<typename T> template<typename T>
bool fastIs() const = delete; bool fastIs() const = delete;
virtual bool isError() const { return false; }
virtual bool isVector() const { return false; } virtual bool isVector() const { return false; }
virtual bool isHashMap() const { return false; } virtual bool isHashMap() const { return false; }
virtual bool isList() const { return false; } virtual bool isList() const { return false; }
@@ -34,6 +35,21 @@ public:
// ----------------------------------------- // -----------------------------------------
class Error final : public ASTNode {
public:
Error(const std::string& error);
virtual ~Error() = default;
virtual bool isError() const override { return true; }
const std::string& error() const { return m_error; }
private:
std::string m_error;
};
// -----------------------------------------
// [] // []
class Vector final : public ASTNode { class Vector final : public ASTNode {
public: public:
@@ -143,6 +159,9 @@ private:
// ----------------------------------------- // -----------------------------------------
// clang-format off // clang-format off
template<>
inline bool ASTNode::fastIs<Error>() const { return isError(); }
template<> template<>
inline bool ASTNode::fastIs<Vector>() const { return isVector(); } inline bool ASTNode::fastIs<Vector>() const { return isVector(); }