Fixed issue about 4+5 being made a single token, problem appeared in recent commits.

This commit is contained in:
Reijo Tomperi 2009-02-08 10:56:20 +00:00
parent c345fa6186
commit cb5974e94e
2 changed files with 13 additions and 3 deletions

View File

@ -322,9 +322,18 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
if (strchr("#+-*/%&|^?!=<>[](){};:,.~", ch))
{
if (strchr(".+-", ch) && std::isdigit(CurrentToken[0]))
if (ch == '.' &&
CurrentToken.length() > 0 &&
std::isdigit(CurrentToken[0]))
{
// Don't separate doubles
// Don't separate doubles "5.4"
}
else if (strchr("+-", ch) &&
CurrentToken.length() > 0 &&
std::isdigit(CurrentToken[0]) &&
CurrentToken[CurrentToken.length()-1] == 'e')
{
// Don't separate doubles "4.2e+10"
}
else
{

View File

@ -999,6 +999,7 @@ private:
" float b = 4.2f;\n"
" double c = 4.2e+10;\n"
" double d = 4.2e-10;\n"
" int e = 4+2;\n"
"}\n";
// tokenize..
@ -1009,7 +1010,7 @@ private:
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { double a = 4.2 ; float b = 4.2f ; double c = 4.2e+10 ; double d = 4.2e-10 ; }"), ostr.str());
ASSERT_EQUALS(std::string(" void f ( ) { double a = 4.2 ; float b = 4.2f ; double c = 4.2e+10 ; double d = 4.2e-10 ; int e = 4 + 2 ; }"), ostr.str());
}
void tokenize_strings()