tokenizer: tokenize ## better

This commit is contained in:
Daniel Marjamäki 2009-01-20 17:26:16 +00:00
parent 45661fed21
commit fad65663e5
2 changed files with 30 additions and 0 deletions

View File

@ -243,6 +243,13 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
if (ch == '#' && CurrentToken.empty()) if (ch == '#' && CurrentToken.empty())
{ {
// If previous token was "#" then append this to create a "##" token
if (Token::simpleMatch(_tokensBack, "#"))
{
_tokensBack->str("##");
continue;
}
std::string line("#"); std::string line("#");
{ {
char chPrev = '#'; char chPrev = '#';
@ -254,7 +261,9 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
if (ch != ' ') if (ch != ' ')
chPrev = ch; chPrev = ch;
if (ch != '\\' && ch != '\n') if (ch != '\\' && ch != '\n')
{
line += ch; line += ch;
}
if (ch == '\n') if (ch == '\n')
++lineno; ++lineno;
} }

View File

@ -69,6 +69,8 @@ private:
TEST_CASE(file1); TEST_CASE(file1);
// TODO TEST_CASE(file2); // TODO TEST_CASE(file2);
TEST_CASE(doublesharp);
} }
@ -687,6 +689,25 @@ private:
ASSERT_EQUALS(tok->str(), ostr.str()); ASSERT_EQUALS(tok->str(), ostr.str());
} }
} }
void doublesharp()
{
const char code[] = "TEST(var,val) var##_##val = val\n";
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "");
// Stringify the tokens..
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << tok->str() << " ";
ASSERT_EQUALS("TEST ( var , val ) var ## _ ## val = val ", ostr.str());
}
}; };
REGISTER_TEST(TestTokenizer) REGISTER_TEST(TestTokenizer)