Fixes issue in lexing numerical base consuming character after it, removes test for invalid numerical base.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
cf8d6ce18b
commit
034dcb118b
|
@ -5,7 +5,6 @@
|
||||||
namespace MalachScript::Diagnostics {
|
namespace MalachScript::Diagnostics {
|
||||||
enum class DiagnosticType : uint8_t {
|
enum class DiagnosticType : uint8_t {
|
||||||
UnknownCharacter,
|
UnknownCharacter,
|
||||||
InvalidNumericalBase,
|
|
||||||
ExpectedEndOfString,
|
ExpectedEndOfString,
|
||||||
UnexpectedToken,
|
UnexpectedToken,
|
||||||
DoubleProperty,
|
DoubleProperty,
|
||||||
|
|
|
@ -11,8 +11,6 @@ namespace MalachScript::Diagnostics {
|
||||||
switch (diag->GetType()) {
|
switch (diag->GetType()) {
|
||||||
case DiagnosticType::UnknownCharacter:
|
case DiagnosticType::UnknownCharacter:
|
||||||
return util::Format("Unknown character: '{0}'", diag->GetFormats());
|
return util::Format("Unknown character: '{0}'", diag->GetFormats());
|
||||||
case DiagnosticType::InvalidNumericalBase:
|
|
||||||
return util::Format("Invalid numerical base: '0{0}'", diag->GetFormats());
|
|
||||||
case DiagnosticType::ExpectedEndOfString:
|
case DiagnosticType::ExpectedEndOfString:
|
||||||
return util::Format("Expected end of string, found {0}", diag->GetFormats());
|
return util::Format("Expected end of string, found {0}", diag->GetFormats());
|
||||||
case DiagnosticType::UnexpectedToken:
|
case DiagnosticType::UnexpectedToken:
|
||||||
|
|
|
@ -292,16 +292,27 @@ namespace MalachScript::Parser {
|
||||||
auto secondChar = Peek();
|
auto secondChar = Peek();
|
||||||
auto secondValue = LexDecimalValue(secondChar);
|
auto secondValue = LexDecimalValue(secondChar);
|
||||||
if (secondChar != '.' && secondValue == 255) {
|
if (secondChar != '.' && secondValue == 255) {
|
||||||
Progress();
|
|
||||||
switch (secondChar) {
|
switch (secondChar) {
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X': numericalSystem = 16; break;
|
case 'X':
|
||||||
|
Progress();
|
||||||
|
numericalSystem = 16;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'D': numericalSystem = 10; break;
|
case 'D':
|
||||||
|
Progress();
|
||||||
|
numericalSystem = 10;
|
||||||
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
case 'O': numericalSystem = 8; break;
|
case 'O':
|
||||||
|
Progress();
|
||||||
|
numericalSystem = 8;
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'B': numericalSystem = 2; break;
|
case 'B':
|
||||||
|
Progress();
|
||||||
|
numericalSystem = 2;
|
||||||
|
break;
|
||||||
default: return Create<IntegerLiteral>(TextSpan(_position - 1, _position), 0);
|
default: return Create<IntegerLiteral>(TextSpan(_position - 1, _position), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,16 +69,4 @@ INTEGER_TEST("0b110011", 51);
|
||||||
INTEGER_TEST("0B110011", 51);
|
INTEGER_TEST("0B110011", 51);
|
||||||
|
|
||||||
#undef INTEGER_TEST
|
#undef INTEGER_TEST
|
||||||
#undef FLOAT_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");
|
|
||||||
}
|
|
Loading…
Reference in New Issue