From dff1eac47f1ba69e390484f1a5fce1db37c076a2 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 22 Feb 2022 19:47:41 +0100 Subject: [PATCH] PARSING: Add more options to throw with unexpected tokens (add a message) --- src/Lib/Script/Ast/IrElement.cc | 13 +++++++++++++ src/Lib/Script/Ast/IrElement.hh | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Lib/Script/Ast/IrElement.cc b/src/Lib/Script/Ast/IrElement.cc index 155957c2..e71ba4cd 100644 --- a/src/Lib/Script/Ast/IrElement.cc +++ b/src/Lib/Script/Ast/IrElement.cc @@ -13,6 +13,19 @@ IrElement::throwUnexpectedToken(const Token &tok) const tok.toString()); } +void +IrElement::throwUnexpectedToken(const Token &tok, const std::string &msg) const +{ + throw std::runtime_error("Unexpected token in location " + tok.location().toString() + ": " + + tok.toString() + " with message: " + msg); +} + +void +IrElement::throwUnexpectedToken(const Token &tok, const char *msg) const +{ + throwUnexpectedToken(tok, std::string(msg)); +} + IrElement::~IrElement() noexcept { std::erase_if(childElements, [this](IrElement *child) noexcept -> bool { diff --git a/src/Lib/Script/Ast/IrElement.hh b/src/Lib/Script/Ast/IrElement.hh index 4e0e13fc..53dcd663 100644 --- a/src/Lib/Script/Ast/IrElement.hh +++ b/src/Lib/Script/Ast/IrElement.hh @@ -116,7 +116,9 @@ protected: void detachElementFromParent() noexcept; void addChild(IrElement *) noexcept; - void throwUnexpectedToken(const Token &tok) const; + [[noreturn]] void throwUnexpectedToken(const Token &) const; + [[noreturn]] void throwUnexpectedToken(const Token &, const std::string &) const; + [[noreturn]] void throwUnexpectedToken(const Token &, const char *) const; public: virtual ~IrElement() noexcept; -- GitLab