Allow unquoted string arguments to start with . and -

pull/3094/head
Evil Eye 4 years ago
parent b7886bc036
commit c1177d7ffe

@ -1,7 +1,7 @@
0.48.0
------
Bug #3846: Strings starting with "-" fail to compile if not enclosed in quotes
0.47.0
------

@ -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())

@ -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 = "<newline>";
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;
}
}

@ -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();
};
}

Loading…
Cancel
Save