From cf8d6ce18bde4a1b4ae169d529d6ffc0c0f3c604 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 6 Jan 2021 00:53:02 +0100 Subject: [PATCH] When an integer starts with a 0, and is followed by a non numerical symbol just lex it as a 0 literal, followed by another token. --- src/Parser/Lexer/Lexer.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Parser/Lexer/Lexer.cpp b/src/Parser/Lexer/Lexer.cpp index 6365010..0cbc19e 100644 --- a/src/Parser/Lexer/Lexer.cpp +++ b/src/Parser/Lexer/Lexer.cpp @@ -302,12 +302,7 @@ namespace MalachScript::Parser { case 'O': numericalSystem = 8; break; case 'b': case 'B': numericalSystem = 2; break; - default: - LogError(Diagnostics::DiagnosticType::InvalidNumericalBase, - TextSpan(_position - 1, _position + 1), {std::string(1, secondChar)}); - // Set to the largest numerical system, so we can prevent errors down the line. - numericalSystem = 16; - break; + default: return Create(TextSpan(_position - 1, _position), 0); } } } @@ -403,7 +398,7 @@ namespace MalachScript::Parser { value <<= 4; value += v; } - return Create(TextSpan(start, _position), value); + return Create(TextSpan(start - 1, _position), value); } IntegerLiteral* Lexer::LexOctal() { auto start = _position; @@ -417,7 +412,7 @@ namespace MalachScript::Parser { value <<= 3; value += v; } - return Create(TextSpan(start, _position), value); + return Create(TextSpan(start - 1, _position), value); } IntegerLiteral* Lexer::LexBinary() { auto start = _position; @@ -431,7 +426,7 @@ namespace MalachScript::Parser { value <<= 1; value += v; } - return Create(TextSpan(start, _position), value); + return Create(TextSpan(start - 1, _position), value); } StringLiteral* Lexer::LexString(char8_t opening, bool heredoc) { auto openingPos = _position;