Make script numeric matchers match negative numbers as well

This commit is contained in:
Jan
2023-09-25 21:45:06 +02:00
parent 870fa44b02
commit d071dc1bfd
3 changed files with 41 additions and 3 deletions

View File

@ -38,6 +38,17 @@ namespace menu
{
const auto& firstToken = tokens[0].get();
if (firstToken.m_type == SimpleParserValueType::CHARACTER)
{
const auto& secondToken = tokens[1].get();
if (secondToken.m_type == SimpleParserValueType::INTEGER)
return SimpleParserValue::String(firstToken.GetPos(), new std::string(std::to_string(-secondToken.IntegerValue())));
std::ostringstream ss;
ss << std::noshowpoint << -firstToken.FloatingPointValue();
return SimpleParserValue::String(firstToken.GetPos(), new std::string(ss.str()));
}
if (firstToken.m_type == SimpleParserValueType::INTEGER)
return SimpleParserValue::String(firstToken.GetPos(), new std::string(std::to_string(firstToken.IntegerValue())));
if (firstToken.m_type == SimpleParserValueType::FLOATING_POINT)
@ -73,6 +84,9 @@ namespace menu
{
const auto& firstToken = tokens[0].get();
if (firstToken.m_type == SimpleParserValueType::CHARACTER)
return SimpleParserValue::String(firstToken.GetPos(), new std::string(std::to_string(-tokens[1].get().IntegerValue())));
if (firstToken.m_type == SimpleParserValueType::INTEGER)
return SimpleParserValue::String(firstToken.GetPos(), new std::string(std::to_string(firstToken.IntegerValue())));
return SimpleParserValue::String(firstToken.GetPos(), new std::string(firstToken.StringValue()));