Fix not reading hex numbers with integer only lexing for SimpleLexer

This commit is contained in:
Jan 2022-03-30 19:25:07 +02:00
parent a092f76ec9
commit 1d798647c3
2 changed files with 27 additions and 3 deletions

View File

@ -289,6 +289,28 @@ protected:
}
}
void ReadNumber(bool& hasSignPrefix, int& integerValue)
{
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] == '+'
|| currentLine.m_line[m_current_line_offset - 1] == '-');
hasSignPrefix = 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
&& currentLine.m_line[m_current_line_offset - 1] == '0'
&& currentLine.m_line[m_current_line_offset] == 'x')
{
ReadHexNumber(integerValue);
}
else
{
integerValue = ReadInteger();
}
}
public:
const TokenType& GetToken(unsigned index) override
{

View File

@ -125,12 +125,13 @@ SimpleParserValue SimpleLexer::GetNextToken()
if (m_config.m_read_integer_numbers && (isdigit(c) || (c == '+' || c == '-' || (m_config.m_read_floating_point_numbers && c == '.')) && isdigit(PeekChar())))
{
bool hasSignPrefix;
int integerValue;
if(m_config.m_read_floating_point_numbers)
{
bool isFloatingPointValue;
bool hasSignPrefix;
double floatingPointValue;
int integerValue;
ReadNumber(isFloatingPointValue, hasSignPrefix, floatingPointValue, integerValue);
@ -140,7 +141,8 @@ SimpleParserValue SimpleLexer::GetNextToken()
return SimpleParserValue::Integer(pos, integerValue, hasSignPrefix);
}
return SimpleParserValue::Integer(pos, ReadInteger(), c == '+' || c == '-');
ReadNumber(hasSignPrefix, integerValue);
return SimpleParserValue::Integer(pos, integerValue, hasSignPrefix);
}
if (isalpha(c) || c == '_')