From a0dbb40c8e0e7f045d2aff10ce919d171a7984eb Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 11 Oct 2014 14:48:52 +0200 Subject: [PATCH] Allow script names starting with digits (Fixes #1730) --- components/compiler/fileparser.cpp | 1 + components/compiler/scanner.cpp | 20 +++++++++++++++----- components/compiler/scanner.hpp | 4 ++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/components/compiler/fileparser.cpp b/components/compiler/fileparser.cpp index e90e9a8f6..37ad1f258 100644 --- a/components/compiler/fileparser.cpp +++ b/components/compiler/fileparser.cpp @@ -65,6 +65,7 @@ namespace Compiler if (mState==BeginState && keyword==Scanner::K_begin) { mState = NameState; + scanner.allowNameStartingwithDigit(); return true; } diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index dd8fb431b..e73477ee7 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -48,6 +48,9 @@ namespace Compiler bool Scanner::scanToken (Parser& parser) { + bool allowDigit = mNameStartingWithDigit; + mNameStartingWithDigit = false; + switch (mPutback) { case Putback_Special: @@ -112,6 +115,7 @@ namespace Compiler else if (isWhitespace (c)) { mLoc.mLiteral.clear(); + mNameStartingWithDigit = allowDigit; return true; } else if (c==':') @@ -120,21 +124,21 @@ namespace Compiler mLoc.mLiteral.clear(); return true; } - else if (std::isdigit (c)) + else if (std::isalpha (c) || c=='_' || c=='"' || (allowDigit && std::isdigit (c))) { bool cont = false; - if (scanInt (c, parser, cont)) + if (scanName (c, parser, cont)) { mLoc.mLiteral.clear(); return cont; } } - else if (std::isalpha (c) || c=='_' || c=='"') + else if (std::isdigit (c)) { bool cont = false; - if (scanName (c, parser, cont)) + if (scanInt (c, parser, cont)) { mLoc.mLiteral.clear(); return cont; @@ -516,7 +520,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), + mNameStartingWithDigit (false) { } @@ -568,4 +573,9 @@ namespace Compiler if (mExtensions) mExtensions->listKeywords (keywords); } + + void Scanner::allowNameStartingwithDigit() + { + mNameStartingWithDigit = true; + } } diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index 7f6609f76..349a8afb6 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 mNameStartingWithDigit; public: @@ -122,6 +123,9 @@ namespace Compiler void listKeywords (std::vector& keywords); ///< Append all known keywords to \a kaywords. + + /// For the next token allow names to start with a digit. + void allowNameStartingwithDigit(); }; }