summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-05-22 17:11:15 (GMT)
committerEvan Martin <martine@danga.com>2011-05-22 17:11:15 (GMT)
commit096d2895be6c8101653a109ef96e3b3f9a685f8d (patch)
treea1ec67376d105443f83badf4b6459b28b39cf10b
parente69d8bfda4b369717e67ff1d9bfa458b402c0e73 (diff)
downloadNinja-096d2895be6c8101653a109ef96e3b3f9a685f8d.zip
Ninja-096d2895be6c8101653a109ef96e3b3f9a685f8d.tar.gz
Ninja-096d2895be6c8101653a109ef96e3b3f9a685f8d.tar.bz2
merge two line continuation codepaths
-rw-r--r--src/parsers.cc25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/parsers.cc b/src/parsers.cc
index e4402af..bbcc56b 100644
--- a/src/parsers.cc
+++ b/src/parsers.cc
@@ -133,24 +133,21 @@ bool Tokenizer::ReadToNewline(string *text, string* err, size_t max_length) {
// XXX token_.clear();
while (cur_ < end_ && *cur_ != '\n') {
if (*cur_ == '\\') {
- ++cur_;
- if (cur_ >= end_)
+ // Might be a line continuation; peek ahead to check.
+ if (cur_ + 1 >= end_)
return Error("unexpected eof", err);
- if (*cur_ != '\n') {
- // XXX we just let other backslashes through verbatim now.
- // This may not be wise.
- text->push_back('\\');
- text->push_back(*cur_);
- ++cur_;
+ if (*(cur_ + 1) == '\n') {
+ // Let SkipWhitespace handle the continuation logic.
+ SkipWhitespace();
continue;
}
+
+ // XXX we just let other backslashes through verbatim now.
+ // This may not be wise.
+ text->push_back(*cur_);
+ ++cur_;
+ text->push_back(*cur_);
++cur_;
- cur_line_ = cur_;
- ++line_number_;
- 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_;