From a4528fb0d9482fb63392ddefd4b2f860a1754539 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Thu, 26 Nov 2020 06:09:58 -0500 Subject: [PATCH] Add support for opening .pory scripts to the selected event script --- include/core/parseutil.h | 9 +++-- src/core/parseutil.cpp | 75 ++++++++++++++++++++++++++++++++-------- src/editor.cpp | 14 ++++---- 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/include/core/parseutil.h b/include/core/parseutil.h index 4bc5301e..b65dbf76 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -41,7 +41,7 @@ public: ParseUtil(); void set_root(QString); static QString readTextFile(QString); - static void strip_comment(QString*); + void strip_comment(QString*); QList* parseAsm(QString); int evaluateDefine(QString, QMap*); QStringList readCArray(QString text, QString label); @@ -56,7 +56,12 @@ public: // Returns the 1-indexed line number for the definition of scriptLabel in the scripts file at filePath. // Returns 0 if a definition for scriptLabel cannot be found. - static int getScriptLineNumber(const QString &scriptLabel, const QString &filePath); + static int getScriptLineNumber(const QString &filePath, const QString &scriptLabel); + static int getRawScriptLineNumber(QString text, const QString &scriptLabel); + static int getPoryScriptLineNumber(QString text, const QString &scriptLabel); + static QString &removeStringLiterals(QString &text); + static QString &removeLineComments(QString &text, const QString &commentSymbol); + static QString &removeLineComments(QString &text, const QStringList &commentSymbols); private: QString root; diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index 431d7ba3..5dc4f176 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -421,21 +421,66 @@ bool ParseUtil::ensureFieldsExist(QJsonObject obj, QList fields) { return true; } -int ParseUtil::getScriptLineNumber(const QString &scriptLabel, const QString &filePath) { - if (filePath.endsWith(".inc")) { - const QString text = readTextFile(filePath); - const QStringList lines = text.split('\n'); - for (int lineNumber = 0; lineNumber < lines.count(); ++lineNumber) { - QString line = lines.at(lineNumber); - strip_comment(&line); - if (line.contains(':')) { - const QString parsedLabel = line.left(line.indexOf(':')).trimmed(); - if (parsedLabel == scriptLabel) - return lineNumber + 1; - } - } - } else if (filePath.endsWith(".pory")) { +int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) { + if (filePath.endsWith(".inc")) + return getRawScriptLineNumber(readTextFile(filePath), scriptLabel); + else if (filePath.endsWith(".pory")) + return getPoryScriptLineNumber(readTextFile(filePath), scriptLabel); - } return 0; } + +int ParseUtil::getRawScriptLineNumber(QString text, const QString &scriptLabel) { + removeStringLiterals(text); + removeLineComments(text, "@"); + + static const QRegularExpression re_incScriptLabel("(?