From 9a186053a690f2216b43355549c8aa7e2959583c Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Fri, 18 Apr 2025 20:53:59 +0000
Subject: [PATCH] better error reporting
---
src/Parser/Parser.hpp | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/Parser/Parser.hpp b/src/Parser/Parser.hpp
index ed08bde..0acedf7 100644
--- a/src/Parser/Parser.hpp
+++ b/src/Parser/Parser.hpp
@@ -22,11 +22,13 @@
class Exception : public BaseException {
public:
using BaseException::BaseException;
+ // Filename for error reporting
+ static std::string current_filename_;
Exception(const std::string & msg, const std::string & expected, const Lexer::Tokens::Token & token) {
rawMessage_ = msg + ": " + token.dump();
- context_ =
- " at line: " + std::to_string(token.line_number) + ", column: " + std::to_string(token.column_number);
+ context_ = " in file \"" + current_filename_ + "\" at line: " + std::to_string(token.line_number)
+ + ", column: " + std::to_string(token.column_number);
if (expected.empty() == false) {
rawMessage_ += " (expected: " + expected + ")";
}
@@ -38,7 +40,8 @@
if (expected.empty() == false) {
rawMessage_ += " (expected: " + expected + ")";
}
- context_ = " at line: " + std::to_string(line) + ", column: " + std::to_string(col);
+ context_ = " in file \"" + current_filename_ + "\" at line: " + std::to_string(line)
+ + ", column: " + std::to_string(col);
formattedMessage_ = formatMessage();
}
--
Gitblit v1.9.3