Fixes issue in lexing numerical base consuming character after it, removes test for invalid numerical base.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-01-06 11:48:24 +01:00
parent cf8d6ce18b
commit 034dcb118b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 17 additions and 21 deletions

View File

@ -5,7 +5,6 @@
namespace MalachScript::Diagnostics {
enum class DiagnosticType : uint8_t {
UnknownCharacter,
InvalidNumericalBase,
ExpectedEndOfString,
UnexpectedToken,
DoubleProperty,

View File

@ -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:

View File

@ -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<IntegerLiteral>(TextSpan(_position - 1, _position), 0);
}
}

View File

@ -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