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
@@ -3,10 +3,22 @@
MenuMatcherScriptInt::MenuMatcherScriptInt()
= default;
MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimpleParserValue>*lexer, const unsigned tokenOffset)
MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{
const auto& token = lexer->GetToken(tokenOffset);
if (token.m_type == SimpleParserValueType::CHARACTER)
{
if (token.CharacterValue() != '-')
return MatcherResult<SimpleParserValue>::NoMatch();
const auto& nextToken = lexer->GetToken(tokenOffset + 1);
if (nextToken.m_type != SimpleParserValueType::INTEGER)
return MatcherResult<SimpleParserValue>::NoMatch();
return MatcherResult<SimpleParserValue>::Match(2);
}
if (token.m_type == SimpleParserValueType::INTEGER)
return MatcherResult<SimpleParserValue>::Match(1);
@@ -20,7 +32,7 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimplePar
char* endPtr;
// The return result does not matter here
const auto _ = strtol(&stringValue[0], &endPtr, 10);
const auto _ = strtol(stringValue.data(), &endPtr, 10);
if (endPtr != &stringValue[stringValue.size() - 1])
return MatcherResult<SimpleParserValue>::NoMatch();
@@ -7,6 +7,18 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptNumeric::CanMatch(ILexer<Simpl
{
const auto& token = lexer->GetToken(tokenOffset);
if (token.m_type == SimpleParserValueType::CHARACTER)
{
if (token.CharacterValue() != '-')
return MatcherResult<SimpleParserValue>::NoMatch();
const auto& nextToken = lexer->GetToken(tokenOffset + 1);
if (nextToken.m_type != SimpleParserValueType::FLOATING_POINT && nextToken.m_type != SimpleParserValueType::INTEGER)
return MatcherResult<SimpleParserValue>::NoMatch();
return MatcherResult<SimpleParserValue>::Match(2);
}
if (token.m_type == SimpleParserValueType::FLOATING_POINT || token.m_type == SimpleParserValueType::INTEGER)
return MatcherResult<SimpleParserValue>::Match(1);
@@ -20,7 +32,7 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptNumeric::CanMatch(ILexer<Simpl
char* endPtr;
// The return result does not matter here
const auto _ = strtod(&stringValue[0], &endPtr);
const auto _ = strtod(stringValue.data(), &endPtr);
if(endPtr != &stringValue[stringValue.size()])
return MatcherResult<SimpleParserValue>::NoMatch();