support continuation lines

This commit is contained in:
Evan Martin 2010-10-22 09:28:22 -07:00
parent 5b94928d5c
commit d379db40db
2 changed files with 30 additions and 2 deletions

View File

@ -101,8 +101,20 @@ bool Parser::ReadToken(string* out) {
bool Parser::ReadToNewline(string* text, string* err) {
token_.clear();
while (cur_ < end_ && *cur_ != '\n') {
text->push_back(*cur_);
++cur_;
if (*cur_ == '\\') {
++cur_;
if (cur_ >= end_)
return Error("unexpected eof", err);
if (!Newline(err))
return false;
SkipWhitespace();
// Collapse whitespace, but make sure we get at least one space.
if (text->size() > 0 && text->at(text->size() - 1) != ' ')
text->push_back(' ');
} else {
text->push_back(*cur_);
++cur_;
}
}
return Newline(err);
}

View File

@ -49,6 +49,22 @@ TEST(Parser, Variables) {
EXPECT_EQ("ld -pthread -o a b c", edge->EvaluateCommand());
}
TEST(Parser, Continuation) {
State state;
ASSERT_NO_FATAL_FAILURE(AssertParse(&state,
"rule link\n"
"command foo bar \\\n"
" baz\n"
"\n"
"extra = \\\n"
"xyz\n"));
ASSERT_EQ(1, state.rules_.size());
Rule* rule = state.rules_.begin()->second;
EXPECT_EQ("link", rule->name_);
EXPECT_EQ("foo bar baz", rule->command_.unparsed());
}
TEST(Parser, Errors) {
State state;