From 1975be8e88b3181629dce9ceceed4accf60e4728 Mon Sep 17 00:00:00 2001 From: Justus Garbe Date: Wed, 1 Nov 2023 16:51:42 +0100 Subject: [PATCH] error: support printing compile errors --- lib/source/pl/core/error.cpp | 14 +++----------- lib/source/pl/core/resolvers.cpp | 2 ++ lib/source/pl/pattern_language.cpp | 2 ++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/source/pl/core/error.cpp b/lib/source/pl/core/error.cpp index 3b2df916..4f8bcc1c 100644 --- a/lib/source/pl/core/error.cpp +++ b/lib/source/pl/core/error.cpp @@ -86,19 +86,11 @@ namespace pl::core::err { auto lines = wolv::util::splitString(location.source->content, "\n"); - std::cout << "location.line: " << location.line << std::endl; - std::cout << "location.column: " << location.column << std::endl; - std::cout << "location.source->source: " << location.source->source << std::endl; - std::cout << "location.source->content: " << std::endl; - - for (const auto &item: lines) { - std::cout << item << std::endl; - } - if ((location.line - 1) < lines.size()) { - const auto &errorLine = lines[location.line - 1]; const auto lineNumberPrefix = fmt::format("{} | ", location.line); - errorMessage += fmt::format("{}{}", lineNumberPrefix, errorLine); + const auto &errorLine = wolv::util::replaceStrings(lines[location.line - 1], "\r", ""); + + errorMessage += fmt::format("{}{}\n", lineNumberPrefix, errorLine); { const auto descriptionSpacing = std::string(lineNumberPrefix.length() + location.column - 1, ' '); diff --git a/lib/source/pl/core/resolvers.cpp b/lib/source/pl/core/resolvers.cpp index add644ba..7b4d0ec5 100644 --- a/lib/source/pl/core/resolvers.cpp +++ b/lib/source/pl/core/resolvers.cpp @@ -1,6 +1,8 @@ #include #include +#include + using namespace pl::core; using namespace pl::api; using namespace pl::hlp; diff --git a/lib/source/pl/pattern_language.cpp b/lib/source/pl/pattern_language.cpp index 9dd9cb35..cb694a3e 100644 --- a/lib/source/pl/pattern_language.cpp +++ b/lib/source/pl/pattern_language.cpp @@ -15,6 +15,8 @@ #include #include +#include + namespace pl { PatternLanguage::PatternLanguage(bool addLibStd) : m_internals() {