From 034dcb118b713dcce0ae7a8a6bdcfec027ff3936 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 6 Jan 2021 11:48:24 +0100 Subject: [PATCH] Fixes issue in lexing numerical base consuming character after it, removes test for invalid numerical base. --- src/Diagnostics/DiagnosticType.hpp | 1 - src/Diagnostics/DiagnosticTypeEN_US.hpp | 2 -- src/Parser/Lexer/Lexer.cpp | 21 ++++++++++++++++----- tests/LexerTests/NumericalLexTests.cpp | 14 +------------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/Diagnostics/DiagnosticType.hpp b/src/Diagnostics/DiagnosticType.hpp index aaf3843..666b42c 100644 --- a/src/Diagnostics/DiagnosticType.hpp +++ b/src/Diagnostics/DiagnosticType.hpp @@ -5,7 +5,6 @@ namespace MalachScript::Diagnostics { enum class DiagnosticType : uint8_t { UnknownCharacter, - InvalidNumericalBase, ExpectedEndOfString, UnexpectedToken, DoubleProperty, diff --git a/src/Diagnostics/DiagnosticTypeEN_US.hpp b/src/Diagnostics/DiagnosticTypeEN_US.hpp index 84ef84f..bf7e95f 100644 --- a/src/Diagnostics/DiagnosticTypeEN_US.hpp +++ b/src/Diagnostics/DiagnosticTypeEN_US.hpp @@ -11,8 +11,6 @@ namespace MalachScript::Diagnostics { switch (diag->GetType()) { case DiagnosticType::UnknownCharacter: return util::Format("Unknown character: '{0}'", diag->GetFormats()); - case DiagnosticType::InvalidNumericalBase: - return util::Format("Invalid numerical base: '0{0}'", diag->GetFormats()); case DiagnosticType::ExpectedEndOfString: return util::Format("Expected end of string, found {0}", diag->GetFormats()); case DiagnosticType::UnexpectedToken: diff --git a/src/Parser/Lexer/Lexer.cpp b/src/Parser/Lexer/Lexer.cpp index 0cbc19e..690b9a9 100644 --- a/src/Parser/Lexer/Lexer.cpp +++ b/src/Parser/Lexer/Lexer.cpp @@ -292,16 +292,27 @@ namespace MalachScript::Parser { auto secondChar = Peek(); auto secondValue = LexDecimalValue(secondChar); if (secondChar != '.' && secondValue == 255) { - Progress(); switch (secondChar) { case 'x': - case 'X': numericalSystem = 16; break; + case 'X': + Progress(); + numericalSystem = 16; + break; case 'd': - case 'D': numericalSystem = 10; break; + case 'D': + Progress(); + numericalSystem = 10; + break; case 'o': - case 'O': numericalSystem = 8; break; + case 'O': + Progress(); + numericalSystem = 8; + break; case 'b': - case 'B': numericalSystem = 2; break; + case 'B': + Progress(); + numericalSystem = 2; + break; default: return Create(TextSpan(_position - 1, _position), 0); } } diff --git a/tests/LexerTests/NumericalLexTests.cpp b/tests/LexerTests/NumericalLexTests.cpp index 7c895c6..482794a 100644 --- a/tests/LexerTests/NumericalLexTests.cpp +++ b/tests/LexerTests/NumericalLexTests.cpp @@ -69,16 +69,4 @@ INTEGER_TEST("0b110011", 51); INTEGER_TEST("0B110011", 51); #undef INTEGER_TEST -#undef FLOAT_TEST - -TEST_CASE("Lex invalid numerical base") { - MalachScript::Diagnostics::Logger diag; - auto lexer = Lexer(u8"bad base", u8"0f553", &diag); - lexer.Lex(); - const auto& messages = diag.GetMessages(); - REQUIRE(messages.size() == 1); - CHECK(messages[0].GetType() == MalachScript::Diagnostics::DiagnosticType::InvalidNumericalBase); - CHECK(messages[0].GetLevel() == MalachScript::Diagnostics::DiagnosticLevel::Error); - CHECK(messages[0].GetSpan() == MalachScript::TextSpan(0, 2)); - CHECK(messages[0].GetScriptName() == u8"bad base"); -} +#undef FLOAT_TEST \ No newline at end of file