From 5c9a1d41409dcf80e9bf082eebd75675da5f816b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 28 Aug 2024 16:13:10 -0400 Subject: [PATCH] Fix enum comma parsing --- include/core/parseutil.h | 4 ++-- src/core/parseutil.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/core/parseutil.h b/include/core/parseutil.h index a69ed2f4..bc167a30 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -99,8 +99,8 @@ private: QString createErrorMessage(const QString &message, const QString &expression); struct ParsedDefines { - QMap expressions; // Map of all define names->expressions encountered - QStringList filteredNames; // Define names matching the search text in the order they were encountered in the file + QMap expressions; // Map of all define names encountered to their expressions + QStringList filteredNames; // List of define names that matched the search text, in the order that they were encountered }; ParsedDefines readCDefines(const QString &filename, const QStringList &filterList, bool useRegex); QMap evaluateCDefines(const QString &filename, const QStringList &filterList, bool useRegex); diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index c9b02275..5448229c 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -416,7 +416,11 @@ ParseUtil::ParsedDefines ParseUtil::readCDefines(const QString &filename, const // Encountered an enum, extract the elements of the enum and give each an appropriate expression int baseNum = 0; QString baseExpression = "0"; - static const QRegularExpression re_enumElement("\\b(?\\w+)\\b\\s*=?\\s*(?.+)?[,\\$]"); // TODO: Ignores terminal element lacking comma + + // Note: We lazily consider an enum's expression to be any characters after the assignment up until the first comma or EOL. + // This would be a problem for e.g. NAME = MACRO(a, b), but we're currently unable to parse function-like macros anyway. + // If this changes then the regex below needs to be updated. + static const QRegularExpression re_enumElement("\\b(?\\w+)\\b\\s*=?\\s*(?[^,]*)"); QRegularExpressionMatchIterator elementIter = re_enumElement.globalMatch(enumBody); while (elementIter.hasNext()) { QRegularExpressionMatch elementMatch = elementIter.next(); @@ -462,6 +466,7 @@ QMap ParseUtil::evaluateCDefines(const QString &filename, const QS filteredValues.insert(name, evaluateDefine(name, expression, &allValues, &defines.expressions)); logRecordedErrors(); // Only log errors for defines that Porymap is looking for } + return filteredValues; }