From 6a724352b051743bb0143e48233b5f4ad3ea201b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 30 Jan 2022 17:48:20 +0100 Subject: [PATCH] pattern: Fixed sizeof and addressof operator parsing --- lib/libimhex/source/pattern_language/lexer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libimhex/source/pattern_language/lexer.cpp b/lib/libimhex/source/pattern_language/lexer.cpp index db62fbdf2..39ca698de 100644 --- a/lib/libimhex/source/pattern_language/lexer.cpp +++ b/lib/libimhex/source/pattern_language/lexer.cpp @@ -28,6 +28,10 @@ namespace hex::pl { return string.find_first_not_of("0123456789ABCDEFabcdef.xUL"); } + bool isIdentifierCharacter(char c) { + return std::isalnum(c) || c == '_'; + } + std::optional parseIntegerLiteral(const std::string &string) { Token::ValueType type = Token::ValueType::Any; Token::Literal result; @@ -392,10 +396,10 @@ namespace hex::pl { } else if (c == '$') { tokens.emplace_back(TOKEN(Operator, Dollar)); offset += 1; - } else if (code.substr(offset, 9) == "addressof") { + } else if (code.substr(offset, 9) == "addressof" && !isIdentifierCharacter(code[offset + 9])) { tokens.emplace_back(TOKEN(Operator, AddressOf)); offset += 9; - } else if (code.substr(offset, 6) == "sizeof") { + } else if (code.substr(offset, 6) == "sizeof" && !isIdentifierCharacter(code[offset + 6])) { tokens.emplace_back(TOKEN(Operator, SizeOf)); offset += 6; } else if (c == '\'') { @@ -418,8 +422,8 @@ namespace hex::pl { tokens.emplace_back(VALUE_TOKEN(String, Token::Literal(s))); offset += stringSize; - } else if (std::isalpha(c) || c == '_') { - std::string identifier = matchTillInvalid(&code[offset], [](char c) -> bool { return std::isalnum(c) || c == '_'; }); + } else if (isIdentifierCharacter(c) && !std::isdigit(c)) { + std::string identifier = matchTillInvalid(&code[offset], isIdentifierCharacter); // Check for reserved keywords