From 064553e7463d2646e6e0a9b2642c399d899ca1c4 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 12 Mar 2024 17:40:18 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20add=20failing=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- test/unittests/test_qasm3_parser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittests/test_qasm3_parser.cpp b/test/unittests/test_qasm3_parser.cpp index 79093d083..be3c9b775 100644 --- a/test/unittests/test_qasm3_parser.cpp +++ b/test/unittests/test_qasm3_parser.cpp @@ -743,7 +743,7 @@ TEST_F(Qasm3ParserTest, ImportQasm3CPrefix) { TEST_F(Qasm3ParserTest, ImportQasmScanner) { std::stringstream ss{}; const std::string testfile = - "$1 : . .5 -1. -= += ++ *= **= ** /= % %= |= || | &= " + "$1 : . .5 -1. 1.25e-3 1e3 -= += ++ *= **= ** /= % %= |= || | &= " "&& & ^= ^ ~= ~ ! <= <<= << < >= >>= >> >"; const auto tokens = std::vector{ qasm3::Token::Kind::HardwareQubit, @@ -751,6 +751,8 @@ TEST_F(Qasm3ParserTest, ImportQasmScanner) { qasm3::Token::Kind::Dot, qasm3::Token::Kind::FloatLiteral, qasm3::Token::Kind::FloatLiteral, + qasm3::Token::Kind::FloatLiteral, + qasm3::Token::Kind::FloatLiteral, qasm3::Token::Kind::MinusEquals, qasm3::Token::Kind::PlusEquals, qasm3::Token::Kind::DoublePlus, From 76c6a04439cdd4687d80f5dcd199d118da2adf88 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Tue, 12 Mar 2024 17:42:50 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix=20handling=20of=20scient?= =?UTF-8?q?ific=20notation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/parsers/qasm3_parser/Scanner.cpp | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/parsers/qasm3_parser/Scanner.cpp b/src/parsers/qasm3_parser/Scanner.cpp index 2f2b8f8ba..c0946a0d2 100644 --- a/src/parsers/qasm3_parser/Scanner.cpp +++ b/src/parsers/qasm3_parser/Scanner.cpp @@ -1,6 +1,12 @@ #include "parsers/qasm3_parser/Scanner.hpp" +#include +#include +#include #include +#include +#include +#include namespace qasm3 { char Scanner::readUtf8Codepoint(std::istream* in) { @@ -186,12 +192,26 @@ Token Scanner::consumeNumberLiteral() { error("Float literals are only allowed in base 10"); } - char const sep = ch; - nextCh(); - auto valAfterDecimalSeparator = consumeNumberLiteral(base); + std::stringstream ss{}; + ss << valBeforeDecimalSeparator; + + if (ch == '.') { + ss << ch; + nextCh(); + const auto valAfterDecimalSeparator = consumeNumberLiteral(base); + ss << valAfterDecimalSeparator; + } - std::stringstream ss; - ss << valBeforeDecimalSeparator << sep << valAfterDecimalSeparator; + if (ch == 'e' || ch == 'E') { + ss << ch; + nextCh(); + if (ch == '+' || ch == '-') { + ss << ch; + nextCh(); + } + const auto valAfterExponent = consumeNumberLiteral(base); + ss << valAfterExponent; + } try { t.valReal = std::stod(ss.str());