From c1177d7ffe7f916cc5f65b35219d4bfab14aeb55 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 19 Jun 2021 11:21:37 +0200 Subject: [PATCH] Allow unquoted string arguments to start with . and - --- CHANGELOG.md | 2 +- components/compiler/exprparser.cpp | 1 + components/compiler/scanner.cpp | 32 +++++++++++++++++++++++------- components/compiler/scanner.hpp | 6 ++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76191effd4..110eaf21d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ 0.48.0 ------ - + Bug #3846: Strings starting with "-" fail to compile if not enclosed in quotes 0.47.0 ------ diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 0afe3de6d0..fb7ca7aac4 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -669,6 +669,7 @@ namespace Compiler if (argument=='c') stringParser.smashCase(); if (argument=='x') stringParser.discard(); + scanner.enableExpectName(); scanner.scan (stringParser); if ((optional || argument=='x') && stringParser.isEmpty()) diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 573c8cc93a..829df35be5 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -22,6 +22,7 @@ namespace Compiler { mStrictKeywords = false; mTolerantNames = false; + mExpectName = false; mLoc.mColumn = 0; ++mLoc.mLine; mLoc.mLiteral.clear(); @@ -416,12 +417,13 @@ namespace Compiler special = S_close; else if (c=='.') { + MultiChar next; // check, if this starts a float literal - if (get (c)) + if (get (next)) { - putback (c); + putback (next); - if (c.isDigit()) + if (next.isDigit()) return scanFloat ("", parser, cont); } @@ -476,13 +478,14 @@ namespace Compiler } else if (c.isMinusSign()) { - if (get (c)) + MultiChar next; + if (get (next)) { - if (c=='>') + if (next=='>') special = S_ref; else { - putback (c); + putback (next); special = S_minus; } } @@ -558,6 +561,15 @@ namespace Compiler if (special==S_newline) mLoc.mLiteral = ""; + else if (mExpectName && (special == S_member || special == S_minus)) + { + mExpectName = false; + bool tolerant = mTolerantNames; + mTolerantNames = true; + bool out = scanName(c, parser, cont); + mTolerantNames = tolerant; + return out; + } TokenLoc loc (mLoc); mLoc.mLiteral.clear(); @@ -590,13 +602,14 @@ namespace Compiler const Extensions *extensions) : mErrorHandler (errorHandler), mStream (inputStream), mExtensions (extensions), mPutback (Putback_None), mPutbackCode(0), mPutbackInteger(0), mPutbackFloat(0), - mStrictKeywords (false), mTolerantNames (false), mIgnoreNewline(false) + mStrictKeywords (false), mTolerantNames (false), mIgnoreNewline(false), mExpectName(false) { } void Scanner::scan (Parser& parser) { while (scanToken (parser)); + mExpectName = false; } void Scanner::putbackSpecial (int code, const TokenLoc& loc) @@ -657,4 +670,9 @@ namespace Compiler { mTolerantNames = true; } + + void Scanner::enableExpectName() + { + mExpectName = true; + } } diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index fd7de5b6b6..15781f9240 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -193,6 +193,7 @@ namespace Compiler bool mStrictKeywords; bool mTolerantNames; bool mIgnoreNewline; + bool mExpectName; public: @@ -286,6 +287,11 @@ namespace Compiler /// /// \attention This mode lasts only until the next newline is reached. void enableTolerantNames(); + + /// Treat '.' and '-' as the start of a name. + /// + /// \attention This mode lasts only until the next newline is reached or the call to scan ends. + void enableExpectName(); }; }