From 06efd72a89117658351870c3d01b5b32b6f62f73 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 3 Dec 2015 11:14:58 +0100 Subject: [PATCH] allow keywords as strings in messagebox instruction (Fixes #2991) --- components/compiler/lineparser.cpp | 7 ++++++- components/compiler/scanner.cpp | 16 +++++++++++++--- components/compiler/scanner.hpp | 10 ++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index c1622c3e0..ce1e1e463 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -411,7 +411,12 @@ namespace Compiler } case Scanner::K_set: mState = SetState; return true; - case Scanner::K_messagebox: mState = MessageState; return true; + + case Scanner::K_messagebox: + + mState = MessageState; + scanner.enableStrictKeywords(); + return true; case Scanner::K_return: diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 3c5bb7747..b370f74a1 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -26,6 +26,7 @@ namespace Compiler if (c=='\n') { + mStrictKeywords = false; mLoc.mColumn = 0; ++mLoc.mLine; mLoc.mLiteral.clear(); @@ -294,8 +295,11 @@ namespace Compiler name = name.substr (1, name.size()-2); // allow keywords enclosed in "" /// \todo optionally disable -// cont = parser.parseName (name, loc, *this); -// return true; + if (mStrictKeywords) + { + cont = parser.parseName (name, loc, *this); + return true; + } } int i = 0; @@ -567,7 +571,8 @@ namespace Compiler Scanner::Scanner (ErrorHandler& errorHandler, std::istream& inputStream, const Extensions *extensions) : mErrorHandler (errorHandler), mStream (inputStream), mExtensions (extensions), - mPutback (Putback_None), mPutbackCode(0), mPutbackInteger(0), mPutbackFloat(0) + mPutback (Putback_None), mPutbackCode(0), mPutbackInteger(0), mPutbackFloat(0), + mStrictKeywords (false) { } @@ -619,4 +624,9 @@ namespace Compiler if (mExtensions) mExtensions->listKeywords (keywords); } + + void Scanner::enableStrictKeywords() + { + mStrictKeywords = true; + } } diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index fe867feba..270782c74 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -37,6 +37,7 @@ namespace Compiler float mPutbackFloat; std::string mPutbackName; TokenLoc mPutbackLoc; + bool mStrictKeywords; public: @@ -116,13 +117,18 @@ namespace Compiler ///< put back a float token void putbackName (const std::string& name, const TokenLoc& loc); - ///< put back a name toekn + ///< put back a name token void putbackKeyword (int keyword, const TokenLoc& loc); ///< put back a keyword token void listKeywords (std::vector& keywords); - ///< Append all known keywords to \a kaywords. + ///< Append all known keywords to \a keywords. + + /// Do not accept keywords in quotation marks anymore. + /// + /// \attention This mode lasts only until the next newline is reached. + void enableStrictKeywords(); }; }