Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion example/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <pl.hpp>

#include <format>

const static std::map<pl::core::LogConsole::Level, std::string> LogLevels = {
{ pl::core::LogConsole::Level::Debug, "Debug" },
{ pl::core::LogConsole::Level::Info, "Info" },
Expand Down Expand Up @@ -36,7 +38,7 @@ int main() {

// Create a normal builtin function called `test::normal_function` that takes a single parameter
patternLanguage.addFunction({ "test" }, "normal_function", pl::api::FunctionParameterCount::exactly(1), [](pl::core::Evaluator *ctx, const std::vector<pl::core::Token::Literal> &params) -> std::optional<pl::core::Token::Literal>{
fmt::print("normal_function {}\n", std::get<pl::i128>(params[0]));
printf("%s", std::format("normal_function {}\n", std::get<pl::i128>(params[0])).c_str());
return std::nullopt;
});

Expand Down
17 changes: 0 additions & 17 deletions lib/include/pl/core/errors/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <pl/helpers/types.hpp>
#include <pl/core/location.hpp>

#include <fmt/core.h>

#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -137,11 +135,6 @@ namespace pl::core::err {

virtual Location location() = 0;

template <typename... Args>
void error(const fmt::format_string<Args...>& fmt, Args&&... args) {
this->m_errors.emplace_back(fmt::format(fmt, std::forward<Args>(args)...), location());
}

void error(const std::string &message) {
this->m_errors.emplace_back(message, location());
}
Expand All @@ -150,11 +143,6 @@ namespace pl::core::err {
this->m_errors.emplace_back(message, description, location());
}

template<typename... Args>
void errorDesc(const fmt::format_string<Args...>& message, const std::string &description, Args&&... args) {
this->m_errors.emplace_back(fmt::format(message, std::forward<Args>(args)...), description, location());
}

void error(CompileError& error) {
error.getTrace().push_back(location());
this->m_errors.push_back(std::move(error));
Expand All @@ -168,11 +156,6 @@ namespace pl::core::err {
this->m_errors.emplace_back(message, description, location);
}

template<typename... Args>
void errorAt(const Location& location, const fmt::format_string<Args...>& message, Args&&... args) {
this->m_errors.emplace_back(fmt::format(message, std::forward<Args>(args)...), location);
}

[[nodiscard]] bool hasErrors() const {
return !this->m_errors.empty();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/include/pl/core/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace pl::core {

if (value == nullptr) {
std::visit([&](auto &&) {
errorDesc("Expected {}, got {}.", "This is a serious parsing bug. Please open an issue on GitHub!", typeid(T).name(), typeid(value).name());
errorDesc(fmt::format("Expected {}, got {}.", "This is a serious parsing bug. Please open an issue on GitHub!", typeid(T).name()), typeid(value).name());
throw UnrecoverableParserException();
}, token.value);
}
Expand Down
1 change: 1 addition & 0 deletions lib/source/pl/core/error.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <pl/core/errors/error.hpp>
#include <pl/api.hpp>

#include <fmt/core.h>
#include <wolv/utils/string.hpp>

namespace pl::core::err::impl {
Expand Down
14 changes: 7 additions & 7 deletions lib/source/pl/core/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace pl::core {
return static_cast<char>(std::stoul(hex, nullptr, 16));
} catch (const std::invalid_argument&) {
m_errorLength = 2;
error("Invalid hex escape sequence: {}", hex);
error(fmt::format("Invalid hex escape sequence: {}", hex));
return std::nullopt;
}
}
Expand All @@ -95,13 +95,13 @@ namespace pl::core {
return static_cast<char>(std::stoul(hex, nullptr, 16));
} catch (const std::invalid_argument&) {
m_errorLength = 4;
error("Invalid unicode escape sequence: {}", hex);
error(fmt::format("Invalid unicode escape sequence: {}", hex));
return std::nullopt;
}
}
default:
m_errorLength = 1;
error("Unknown escape sequence: {}", m_sourceCode[m_cursor-1]);
error(fmt::format("Unknown escape sequence: {}", m_sourceCode[m_cursor-1]));
return std::nullopt;
}
}
Expand All @@ -114,7 +114,7 @@ namespace pl::core {
return makeToken(directiveToken->second, identifier.length());
}
m_errorLength = identifier.length();
error("Unknown directive: {}", identifier);
error(fmt::format("Unknown directive: {}", identifier));
return std::nullopt;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ namespace pl::core {

if (!isIntegerCharacter(c, base)) {
m_errorLength = literal.size();
error("Invalid integer literal: {}", literal);
error(fmt::format("Invalid integer literal: {}", literal));
return std::nullopt;
}
value = value * base + characterValue(c);
Expand All @@ -248,7 +248,7 @@ namespace pl::core {

if(end != literal.data() + literal.size()) {
m_errorLength = literal.size();
error("Invalid float literal: {}", literal);
error(fmt::format("Invalid float literal: {}", literal));
return std::nullopt;
}

Expand Down Expand Up @@ -639,7 +639,7 @@ namespace pl::core {
}
} else {
m_errorLength = 1;
error("Unexpected character: {}", c);
error(fmt::format("Unexpected character: {}", c));
m_cursor++;

break;
Expand Down
Loading