Tokenizer: Fixed bug in tokenizer that removed '\' from preprocessor lines

Ticket: #106
This commit is contained in:
Daniel Marjamäki 2009-02-15 11:42:04 +00:00
parent cc63506b03
commit 265ef0f4a5
2 changed files with 21 additions and 0 deletions

View File

@ -255,6 +255,8 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
ch = (char)code.get(); ch = (char)code.get();
if (chPrev != '\\' && ch == '\n') if (chPrev != '\\' && ch == '\n')
break; break;
if (chPrev == '\\')
line += chPrev;
if (chPrev == '#' && ch == '#') if (chPrev == '#' && ch == '#')
{ {
addtoken("##", lineno, FileIndex); addtoken("##", lineno, FileIndex);

View File

@ -98,6 +98,7 @@ private:
TEST_CASE(file1); TEST_CASE(file1);
TEST_CASE(file2); TEST_CASE(file2);
TEST_CASE(file3);
TEST_CASE(doublesharp); TEST_CASE(doublesharp);
@ -840,6 +841,24 @@ private:
void file3()
{
const char code[] = "#file \"c:\\a.h\"\n"
"123\n"
"#endfile\n";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "a.cpp");
ASSERT_EQUALS("[c:\\a.h:1]", tokenizer.fileLine(tokenizer.tokens()));
}
void doublesharp() void doublesharp()
{ {
const char code[] = "TEST(var,val) var##_##val = val\n"; const char code[] = "TEST(var,val) var##_##val = val\n";