From dfb6bdf77ec3cc40126d37b9728160a22fd1bbe4 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 13 Oct 2021 22:44:18 +0200 Subject: [PATCH 1/3] Allow integer variable names --- components/compiler/declarationparser.cpp | 10 ++++++++++ components/compiler/declarationparser.hpp | 4 ++++ components/compiler/lineparser.cpp | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/components/compiler/declarationparser.cpp b/components/compiler/declarationparser.cpp index 1c64aaadee..f29fe820c1 100644 --- a/components/compiler/declarationparser.cpp +++ b/components/compiler/declarationparser.cpp @@ -90,6 +90,16 @@ bool Compiler::DeclarationParser::parseSpecial (int code, const TokenLoc& loc, S return Parser::parseSpecial (code, loc, scanner); } +bool Compiler::DeclarationParser::parseInt(int value, const TokenLoc& loc, Scanner& scanner) +{ + if(mState == State_Name) + { + // Allow integers to be used as variable names + return parseName(loc.mLiteral, loc, scanner); + } + return Parser::parseInt(value, loc, scanner); +} + void Compiler::DeclarationParser::reset() { mState = State_Begin; diff --git a/components/compiler/declarationparser.hpp b/components/compiler/declarationparser.hpp index c04f1dc268..d08509fe50 100644 --- a/components/compiler/declarationparser.hpp +++ b/components/compiler/declarationparser.hpp @@ -35,6 +35,10 @@ namespace Compiler ///< Handle a special character token. /// \return fetch another token? + bool parseInt (int value, const TokenLoc& loc, Scanner& scanner) override; + ///< Handle an int token. + /// \return fetch another token? + void reset() override; }; diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 77afaee8bd..943c052473 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -67,6 +67,11 @@ namespace Compiler parseExpression (scanner, loc); return true; } + else if (mState == SetState) + { + // Allow ints to be used as variable names + return parseName(loc.mLiteral, loc, scanner); + } return Parser::parseInt (value, loc, scanner); } From 31aa19574b31a9bad3efd686ffd909ad976554e6 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 21 Oct 2021 16:54:32 +0200 Subject: [PATCH 2/3] Make PositionCell take additional junk arguments --- components/compiler/extensions0.cpp | 2 +- components/compiler/stringparser.cpp | 6 ++++++ components/compiler/stringparser.hpp | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index 3dfcadab10..64133bee84 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -553,7 +553,7 @@ namespace Compiler extensions.registerFunction("getpos",'f',"c",opcodeGetPos,opcodeGetPosExplicit); extensions.registerFunction("getstartingpos",'f',"c",opcodeGetStartingPos,opcodeGetStartingPosExplicit); extensions.registerInstruction("position","ffffz",opcodePosition,opcodePositionExplicit); - extensions.registerInstruction("positioncell","ffffcX",opcodePositionCell,opcodePositionCellExplicit); + extensions.registerInstruction("positioncell","ffffczz",opcodePositionCell,opcodePositionCellExplicit); extensions.registerInstruction("placeitemcell","ccffffX",opcodePlaceItemCell); extensions.registerInstruction("placeitem","cffffX",opcodePlaceItem); extensions.registerInstruction("placeatpc","clflX",opcodePlaceAtPc); diff --git a/components/compiler/stringparser.cpp b/components/compiler/stringparser.cpp index d9c3c04947..4e0114e0a1 100644 --- a/components/compiler/stringparser.cpp +++ b/components/compiler/stringparser.cpp @@ -86,6 +86,12 @@ namespace Compiler return Parser::parseSpecial (code, loc, scanner); } + bool StringParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner) + { + reportWarning("Treating integer argument as a string", loc); + return parseName(loc.mLiteral, loc, scanner); + } + void StringParser::append (std::vector& code) { std::copy (mCode.begin(), mCode.end(), std::back_inserter (code)); diff --git a/components/compiler/stringparser.hpp b/components/compiler/stringparser.hpp index 1976628360..07b61d8fda 100644 --- a/components/compiler/stringparser.hpp +++ b/components/compiler/stringparser.hpp @@ -43,6 +43,10 @@ namespace Compiler ///< Handle a special character token. /// \return fetch another token? + bool parseInt (int value, const TokenLoc& loc, Scanner& scanner) override; + ///< Handle an int token. + /// \return fetch another token? + void append (std::vector& code); ///< Append code for parsed string. From fef902617aed7271294ab40d377f66f1cc2b224b Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 24 Oct 2021 17:23:15 +0200 Subject: [PATCH 3/3] Parse integer format arguments as variable names --- CHANGELOG.md | 1 + components/compiler/exprparser.cpp | 4 +++- components/compiler/exprparser.hpp | 2 +- components/compiler/lineparser.cpp | 2 +- components/compiler/scanner.cpp | 10 +++++++--- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b37fed31fd..81d3066dd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Bug #6323: Wyrmhaven: Alboin doesn't follower the player character out of his house Bug #6326: Detect Enchantment/Key should detect items in unresolved containers Bug #6347: PlaceItem/PlaceItemCell/PlaceAt should work with levelled creatures + Bug #6363: Some scripts in Morrowland fail to work Feature #890: OpenMW-CS: Column filtering Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record Feature #2780: A way to see current OpenMW version in the console diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 2d525e6f8c..1aedc8dc59 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -632,7 +632,7 @@ namespace Compiler } int ExprParser::parseArguments (const std::string& arguments, Scanner& scanner, - std::vector& code, int ignoreKeyword) + std::vector& code, int ignoreKeyword, bool expectNames) { bool optional = false; int optionalCount = 0; @@ -717,6 +717,8 @@ namespace Compiler if (optional) parser.setOptional (true); + if(expectNames) + scanner.enableExpectName(); scanner.scan (parser); diff --git a/components/compiler/exprparser.hpp b/components/compiler/exprparser.hpp index 2f3eaa8a9f..42739658ec 100644 --- a/components/compiler/exprparser.hpp +++ b/components/compiler/exprparser.hpp @@ -96,7 +96,7 @@ namespace Compiler /// \return Type ('l': integer, 'f': float) int parseArguments (const std::string& arguments, Scanner& scanner, - std::vector& code, int ignoreKeyword = -1); + std::vector& code, int ignoreKeyword = -1, bool expectNames = false); ///< Parse sequence of arguments specified by \a arguments. /// \param arguments Uses ScriptArgs typedef /// \see Compiler::ScriptArgs diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 943c052473..ec90812ec7 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -145,7 +145,7 @@ namespace Compiler if (!arguments.empty()) { mExprParser.reset(); - mExprParser.parseArguments (arguments, scanner, mCode); + mExprParser.parseArguments (arguments, scanner, mCode, -1, true); } mName = name; diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 1054e2e269..0e2b76cb23 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -130,7 +130,8 @@ namespace Compiler { bool cont = false; - if (scanInt (c, parser, cont)) + bool scanned = mExpectName ? scanName(c, parser, cont) : scanInt(c, parser, cont); + if (scanned) { mLoc.mLiteral.clear(); return cont; @@ -387,6 +388,8 @@ namespace Compiler bool Scanner::scanSpecial (MultiChar& c, Parser& parser, bool& cont) { + bool expectName = mExpectName; + mExpectName = false; int special = -1; if (c=='\n') @@ -541,15 +544,16 @@ namespace Compiler if (special==S_newline) mLoc.mLiteral = ""; - else if (mExpectName && (special == S_member || special == S_minus)) + else if (expectName && (special == S_member || special == S_minus)) { - mExpectName = false; bool tolerant = mTolerantNames; mTolerantNames = true; bool out = scanName(c, parser, cont); mTolerantNames = tolerant; return out; } + else if (expectName && special == S_comma) + mExpectName = true; TokenLoc loc (mLoc); mLoc.mLiteral.clear();