Allow script names starting with digits (Fixes #1730)

deque
Marc Zinnschlag 10 years ago
parent 82b4148a62
commit a0dbb40c8e

@ -65,6 +65,7 @@ namespace Compiler
if (mState==BeginState && keyword==Scanner::K_begin) if (mState==BeginState && keyword==Scanner::K_begin)
{ {
mState = NameState; mState = NameState;
scanner.allowNameStartingwithDigit();
return true; return true;
} }

@ -48,6 +48,9 @@ namespace Compiler
bool Scanner::scanToken (Parser& parser) bool Scanner::scanToken (Parser& parser)
{ {
bool allowDigit = mNameStartingWithDigit;
mNameStartingWithDigit = false;
switch (mPutback) switch (mPutback)
{ {
case Putback_Special: case Putback_Special:
@ -112,6 +115,7 @@ namespace Compiler
else if (isWhitespace (c)) else if (isWhitespace (c))
{ {
mLoc.mLiteral.clear(); mLoc.mLiteral.clear();
mNameStartingWithDigit = allowDigit;
return true; return true;
} }
else if (c==':') else if (c==':')
@ -120,21 +124,21 @@ namespace Compiler
mLoc.mLiteral.clear(); mLoc.mLiteral.clear();
return true; return true;
} }
else if (std::isdigit (c)) else if (std::isalpha (c) || c=='_' || c=='"' || (allowDigit && std::isdigit (c)))
{ {
bool cont = false; bool cont = false;
if (scanInt (c, parser, cont)) if (scanName (c, parser, cont))
{ {
mLoc.mLiteral.clear(); mLoc.mLiteral.clear();
return cont; return cont;
} }
} }
else if (std::isalpha (c) || c=='_' || c=='"') else if (std::isdigit (c))
{ {
bool cont = false; bool cont = false;
if (scanName (c, parser, cont)) if (scanInt (c, parser, cont))
{ {
mLoc.mLiteral.clear(); mLoc.mLiteral.clear();
return cont; return cont;
@ -516,7 +520,8 @@ namespace Compiler
Scanner::Scanner (ErrorHandler& errorHandler, std::istream& inputStream, Scanner::Scanner (ErrorHandler& errorHandler, std::istream& inputStream,
const Extensions *extensions) const Extensions *extensions)
: mErrorHandler (errorHandler), mStream (inputStream), mExtensions (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) if (mExtensions)
mExtensions->listKeywords (keywords); mExtensions->listKeywords (keywords);
} }
void Scanner::allowNameStartingwithDigit()
{
mNameStartingWithDigit = true;
}
} }

@ -37,6 +37,7 @@ namespace Compiler
float mPutbackFloat; float mPutbackFloat;
std::string mPutbackName; std::string mPutbackName;
TokenLoc mPutbackLoc; TokenLoc mPutbackLoc;
bool mNameStartingWithDigit;
public: public:
@ -122,6 +123,9 @@ namespace Compiler
void listKeywords (std::vector<std::string>& keywords); void listKeywords (std::vector<std::string>& keywords);
///< Append all known keywords to \a kaywords. ///< Append all known keywords to \a kaywords.
/// For the next token allow names to start with a digit.
void allowNameStartingwithDigit();
}; };
} }

Loading…
Cancel
Save