From a2a60b18b5f234f67afd7cef1cd11cc75248e0cd Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 4 Mar 2025 11:05:59 -0500 Subject: [PATCH] fix issue in parser --- CMakeLists.txt | 2 +- src/blt/logging/fmt_tokenizer.cpp | 9 +++++++-- tests/logger_tests.cpp | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e89680c..434733e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 5.1.4) +set(BLT_VERSION 5.1.5) set(BLT_TARGET BLT) diff --git a/src/blt/logging/fmt_tokenizer.cpp b/src/blt/logging/fmt_tokenizer.cpp index a57f553..3bdf7e4 100644 --- a/src/blt/logging/fmt_tokenizer.cpp +++ b/src/blt/logging/fmt_tokenizer.cpp @@ -186,10 +186,11 @@ namespace blt::logging auto [type, value] = peek(); switch (type) { + case fmt_token_type::STRING: + return; case fmt_token_type::SPACE: case fmt_token_type::MINUS: case fmt_token_type::PLUS: - case fmt_token_type::STRING: case fmt_token_type::COLON: { std::stringstream ss; @@ -217,6 +218,7 @@ namespace blt::logging switch (type) { case fmt_token_type::STRING: + return; case fmt_token_type::SPACE: case fmt_token_type::COLON: case fmt_token_type::MINUS: @@ -246,6 +248,7 @@ namespace blt::logging switch (type) { case fmt_token_type::STRING: + return; case fmt_token_type::COLON: case fmt_token_type::MINUS: case fmt_token_type::PLUS: @@ -317,7 +320,9 @@ namespace blt::logging { if (!has_next()) throw std::runtime_error("Missing token when parsing precision"); - auto [_, value] = next(); + auto [type, value] = next(); + if (type != fmt_token_type::NUMBER) + throw std::runtime_error("Expected number when parsing precision"); m_spec.precision = std::stoll(std::string(value)); } diff --git a/tests/logger_tests.cpp b/tests/logger_tests.cpp index d28a4e9..d7729e7 100644 --- a/tests/logger_tests.cpp +++ b/tests/logger_tests.cpp @@ -38,5 +38,7 @@ int main() blt::logging::println("This is a println with a precision {:.10f}", 42.232342349); blt::logging::println("This is a println with hex {:.10x}", 4250); blt::logging::println("This is a println with hex with leading {:#.10x}", 4250); + blt::logging::println("This is a println with binary {:#b}", 6969420); + blt::logging::println("This is a println with binary with space {: #b}", 6969421); // blt::logging::println("This is println {}\twith a std::endl in the middle of it"); }