From ebb8eb9e5b59db4f381c5866a49461eb30d1a922 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 14 Nov 2021 20:04:00 +0100 Subject: [PATCH] Fix SimpleLexer not recognizing negative numbers --- src/Parser/Parsing/Impl/AbstractLexer.h | 4 +++- src/Parser/Parsing/Impl/AbstractParser.h | 2 +- src/Parser/Parsing/Simple/SimpleLexer.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Parser/Parsing/Impl/AbstractLexer.h b/src/Parser/Parsing/Impl/AbstractLexer.h index 27ab1298..abd830b6 100644 --- a/src/Parser/Parsing/Impl/AbstractLexer.h +++ b/src/Parser/Parsing/Impl/AbstractLexer.h @@ -263,7 +263,9 @@ protected: { const auto& currentLine = CurrentLine(); assert(m_current_line_offset >= 1); - assert(isdigit(currentLine.m_line[m_current_line_offset - 1]) || currentLine.m_line[m_current_line_offset - 1] == '.'); + assert(isdigit(currentLine.m_line[m_current_line_offset - 1]) + || currentLine.m_line[m_current_line_offset - 1] == '.' + || currentLine.m_line[m_current_line_offset - 1] == '-'); const auto lineLength = currentLine.m_line.size(); if (lineLength - m_current_line_offset >= 1 diff --git a/src/Parser/Parsing/Impl/AbstractParser.h b/src/Parser/Parsing/Impl/AbstractParser.h index 37430bcf..4fde10ce 100644 --- a/src/Parser/Parsing/Impl/AbstractParser.h +++ b/src/Parser/Parsing/Impl/AbstractParser.h @@ -30,7 +30,7 @@ protected: virtual const std::vector& GetTestsForState() = 0; public: - virtual ~AbstractParser() override = default; + ~AbstractParser() override = default; AbstractParser(const AbstractParser& other) = default; AbstractParser(AbstractParser&& other) noexcept = default; AbstractParser& operator=(const AbstractParser& other) = default; diff --git a/src/Parser/Parsing/Simple/SimpleLexer.cpp b/src/Parser/Parsing/Simple/SimpleLexer.cpp index f643b55c..e95b098b 100644 --- a/src/Parser/Parsing/Simple/SimpleLexer.cpp +++ b/src/Parser/Parsing/Simple/SimpleLexer.cpp @@ -120,7 +120,7 @@ SimpleParserValue SimpleLexer::GetNextToken() if (m_config.m_read_strings && c == '\"') return SimpleParserValue::String(pos, new std::string(ReadString())); - if (m_config.m_read_numbers && (isdigit(c) || c == '.' && isdigit(PeekChar()))) + if (m_config.m_read_numbers && (isdigit(c) || (c == '-' || c == '.') && isdigit(PeekChar()))) { bool isFloatingPointValue; double doubleValue;