diff --git a/plugins/libimhex/include/hex/lang/ast_node.hpp b/plugins/libimhex/include/hex/lang/ast_node.hpp index 8a6782424..d236b6333 100644 --- a/plugins/libimhex/include/hex/lang/ast_node.hpp +++ b/plugins/libimhex/include/hex/lang/ast_node.hpp @@ -569,7 +569,7 @@ namespace hex::lang { class ASTNodeAttribute : public ASTNode { public: - explicit ASTNodeAttribute(std::string_view attribute, std::string_view value = { }) + explicit ASTNodeAttribute(std::string_view attribute, std::optional value = { }) : ASTNode(), m_attribute(attribute), m_value(value) { } ~ASTNodeAttribute() override = default; diff --git a/plugins/libimhex/source/lang/evaluator.cpp b/plugins/libimhex/source/lang/evaluator.cpp index a86f77be5..080dfa399 100644 --- a/plugins/libimhex/source/lang/evaluator.cpp +++ b/plugins/libimhex/source/lang/evaluator.cpp @@ -113,7 +113,8 @@ namespace hex::lang { PatternData *currPattern = nullptr; // Local variable access - currPattern = this->findPattern(*this->m_localVariables.back(), path); + if (!this->m_localVariables.empty()) + currPattern = this->findPattern(*this->m_localVariables.back(), path); // If no local variable was found try local structure members if (this->m_currMembers.size() > 1) { diff --git a/plugins/libimhex/source/lang/parser.cpp b/plugins/libimhex/source/lang/parser.cpp index f25534554..85c01a5fe 100644 --- a/plugins/libimhex/source/lang/parser.cpp +++ b/plugins/libimhex/source/lang/parser.cpp @@ -365,7 +365,8 @@ namespace hex::lang { std::vector params; // Parse parameter list - while (MATCHES(sequence(IDENTIFIER))) { + bool hasParams = MATCHES(sequence(IDENTIFIER)); + while (hasParams) { params.push_back(getValue(-1)); if (!MATCHES(sequence(SEPARATOR_COMMA))) { @@ -375,6 +376,10 @@ namespace hex::lang { throwParseError("expected closing ')' after parameter list"); } } + if (!hasParams) { + if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE))) + throwParseError("expected closing ')' after parameter list"); + } if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN))) throwParseError("expected opening '{' after function definition");