diff options
author | Evan Martin <martine@danga.com> | 2011-02-04 00:55:25 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-02-04 00:55:25 (GMT) |
commit | fab9170ff9161d7874bf9613e581f1c910a3fead (patch) | |
tree | 5532c2f20e845de45dd5bd49a4d46a4f63dd8c7f | |
parent | aeda4872d35137bdac0b2d7a313ec6f82b993b13 (diff) | |
download | Ninja-fab9170ff9161d7874bf9613e581f1c910a3fead.zip Ninja-fab9170ff9161d7874bf9613e581f1c910a3fead.tar.gz Ninja-fab9170ff9161d7874bf9613e581f1c910a3fead.tar.bz2 |
ignore whitespace in makefiles
-rw-r--r-- | src/parsers.cc | 8 | ||||
-rw-r--r-- | src/parsers.h | 8 | ||||
-rw-r--r-- | src/parsers_test.cc | 10 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/parsers.cc b/src/parsers.cc index 532d98e..8e44a38 100644 --- a/src/parsers.cc +++ b/src/parsers.cc @@ -143,7 +143,7 @@ Token::Type Tokenizer::PeekToken() { return token_.type_; token_.pos_ = cur_; - if (cur_indent_ == -1) { + if (whitespace_significant_ && cur_indent_ == -1) { cur_indent_ = cur_ - cur_line_; if (cur_indent_ != last_indent_) { if (cur_indent_ > last_indent_) { @@ -213,9 +213,13 @@ void Tokenizer::ConsumeToken() { token_.Clear(); } +MakefileParser::MakefileParser() : tokenizer_(false) {} + bool MakefileParser::Parse(const string& input, string* err) { tokenizer_.Start(input.data(), input.data() + input.size()); + tokenizer_.SkipWhitespace(true); + if (!tokenizer_.ReadIdent(&out_)) return tokenizer_.ErrorExpected("output filename", err); if (!tokenizer_.ExpectToken(Token::COLON, err)) @@ -234,7 +238,7 @@ bool MakefileParser::Parse(const string& input, string* err) { } ManifestParser::ManifestParser(State* state, FileReader* file_reader) - : state_(state), file_reader_(file_reader) { + : state_(state), file_reader_(file_reader), tokenizer_(true) { env_ = &state->bindings_; } bool ManifestParser::Load(const string& filename, string* err) { diff --git a/src/parsers.h b/src/parsers.h index 13fdf25..01f65c0 100644 --- a/src/parsers.h +++ b/src/parsers.h @@ -37,8 +37,9 @@ struct Token { }; struct Tokenizer { - Tokenizer() - : token_(Token::NONE), line_number_(1), + Tokenizer(bool whitespace_significant) + : whitespace_significant_(whitespace_significant), + token_(Token::NONE), line_number_(1), last_indent_(0), cur_indent_(-1) {} void Start(const char* start, const char* end); @@ -57,6 +58,8 @@ struct Tokenizer { Token::Type PeekToken(); void ConsumeToken(); + bool whitespace_significant_; + const char* cur_; const char* end_; @@ -67,6 +70,7 @@ struct Tokenizer { }; struct MakefileParser { + MakefileParser(); bool Parse(const string& input, string* err); Tokenizer tokenizer_; diff --git a/src/parsers_test.cc b/src/parsers_test.cc index 18fc8bb..7810113 100644 --- a/src/parsers_test.cc +++ b/src/parsers_test.cc @@ -316,3 +316,13 @@ TEST(MakefileParser, Basic) { ASSERT_EQ("", err); } +TEST(MakefileParser, EarlyNewlineAndWhitespace) { + MakefileParser parser; + string err; + EXPECT_TRUE(parser.Parse( +" \\\n" +" out: in\n", + &err)); + ASSERT_EQ("", err); +} + |