From 01670e5e8532bbd5e50ca9707f0545e373d55a7a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 13 Sep 2021 10:48:45 +0200 Subject: [PATCH] patterns: Ignore superfluous semicolons --- .../libimhex/source/pattern_language/parser.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/libimhex/source/pattern_language/parser.cpp b/plugins/libimhex/source/pattern_language/parser.cpp index 5c3a9c4f4..b40f401c6 100644 --- a/plugins/libimhex/source/pattern_language/parser.cpp +++ b/plugins/libimhex/source/pattern_language/parser.cpp @@ -480,6 +480,9 @@ namespace hex::pl { throwParseError("missing ';' at end of expression", -1); } + // Consume superfluous semicolons + while (needsSemicolon && MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))); + return statement; } @@ -747,6 +750,9 @@ namespace hex::pl { if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))) throwParseError("missing ';' at end of expression", -1); + // Consume superfluous semicolons + while (MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))); + return member; } @@ -847,9 +853,11 @@ namespace hex::pl { else throwParseError("invalid bitfield member", 0); - if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))) { + if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))) throwParseError("missing ';' at end of expression", -1); - } + + // Consume superfluous semicolons + while (MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))); } enumGuard.release(); @@ -966,7 +974,7 @@ namespace hex::pl { // <(parseUsingDeclaration)|(parseVariablePlacement)|(parseStruct)> std::vector Parser::parseStatements() { - ASTNode *statement; + ASTNode *statement = nullptr; if (MATCHES(sequence(KEYWORD_USING, IDENTIFIER, OPERATOR_ASSIGNMENT))) statement = parseUsingDeclaration(); @@ -1006,6 +1014,9 @@ namespace hex::pl { if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))) throwParseError("missing ';' at end of expression", -1); + // Consume superfluous semicolons + while (MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION))); + if (auto typeDecl = dynamic_cast(statement); typeDecl != nullptr) { auto typeName = getNamespacePrefixedName(typeDecl->getName().data());