diff --git a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp index b5ac7d5b3..e21362241 100644 --- a/plugins/libimhex/include/hex/pattern_language/ast_node.hpp +++ b/plugins/libimhex/include/hex/pattern_language/ast_node.hpp @@ -2048,4 +2048,65 @@ namespace hex::pl { std::vector m_body; }; -} \ No newline at end of file + class ASTNodeCompoundStatement : public ASTNode { + public: + + ASTNodeCompoundStatement(std::vector statements) : m_statements(std::move(statements)) { + + } + + ASTNodeCompoundStatement(const ASTNodeCompoundStatement &other) : ASTNode(other) { + for (const auto &statement : other.m_statements) { + this->m_statements.push_back(statement->clone()); + } + } + + [[nodiscard]] ASTNode* clone() const override { + return new ASTNodeCompoundStatement(*this); + } + + ~ASTNodeCompoundStatement() override { + for (const auto &statement : this->m_statements) { + delete statement; + } + } + + [[nodiscard]] ASTNode* evaluate(Evaluator *evaluator) const override { + ASTNode *result = nullptr; + + for (const auto &statement : this->m_statements) { + delete result; + result = statement->evaluate(evaluator); + } + + return result; + } + + [[nodiscard]] std::vector createPatterns(Evaluator *evaluator) const override { + std::vector result; + + for (const auto &statement : this->m_statements) { + auto patterns = statement->createPatterns(evaluator); + std::copy(patterns.begin(), patterns.end(), std::back_inserter(result)); + } + + return result; + } + + FunctionResult execute(Evaluator *evaluator) override { + FunctionResult result; + + for (const auto &statement : this->m_statements) { + result = statement->execute(evaluator); + if (result.first) + return result; + } + + return result; + } + + public: + std::vector m_statements; + }; + +}; \ No newline at end of file diff --git a/plugins/libimhex/source/pattern_language/parser.cpp b/plugins/libimhex/source/pattern_language/parser.cpp index 774466cfd..d2e0ba477 100644 --- a/plugins/libimhex/source/pattern_language/parser.cpp +++ b/plugins/libimhex/source/pattern_language/parser.cpp @@ -493,14 +493,23 @@ namespace hex::pl { if (isFunction) { statement = parseFunctionCall(); } - else + else { statement = parseMemberVariable(parseType(true)); + } } else if (peek(KEYWORD_BE) || peek(KEYWORD_LE) || peek(VALUETYPE_ANY)) { auto type = parseType(true); - if (MATCHES(sequence(IDENTIFIER))) + if (MATCHES(sequence(IDENTIFIER))) { + auto identifier = getValue(-1).get(); statement = parseMemberVariable(type); + + if (MATCHES(sequence(OPERATOR_ASSIGNMENT))) { + auto expression = parseMathematicalExpression(); + + statement = new ASTNodeCompoundStatement({ statement, new ASTNodeAssignment(identifier, expression) }); + } + } else throwParseError("invalid variable declaration"); }