From 5b94928d5c57d4bf54453953d19fbfc25e9936ba Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Thu, 21 Oct 2010 20:17:49 -0700 Subject: [PATCH] drop let from syntax; rely on = instead --- manifest_parser.h | 12 ++++-------- ninja.cc | 2 +- ninja_test.cc | 18 +++++++++--------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/manifest_parser.h b/manifest_parser.h index 0dc0c8e..05bf67e 100644 --- a/manifest_parser.h +++ b/manifest_parser.h @@ -111,10 +111,11 @@ bool Parser::PeekToken() { if (!token_.empty()) return true; + err_start_ = cur_; + if (cur_ >= end_) return false; - err_start_ = cur_; if (IsIdentChar(*cur_)) { while (cur_ < end_ && IsIdentChar(*cur_)) { token_.push_back(*cur_); @@ -179,14 +180,12 @@ bool ManifestParser::Parse(const string& input, string* err) { if (parser_.token() == "rule") { if (!ParseRule(err)) return false; - } else if (parser_.token() == "let") { - if (!ParseLet(err)) - return false; } else if (parser_.token() == "build") { if (!ParseEdge(err)) return false; } else { - return parser_.Error("unknown token: " + parser_.token(), err); + if (!ParseLet(err)) + return false; } parser_.SkipWhitespace(true); } @@ -218,9 +217,6 @@ bool ManifestParser::ParseRule(string* err) { } bool ManifestParser::ParseLet(string* err) { - if (!parser_.Token("let", err)) - return false; - string name; if (!parser_.ReadToken(&name)) return parser_.Error("expected variable name", err); diff --git a/ninja.cc b/ninja.cc index 396d102..18166b9 100644 --- a/ninja.cc +++ b/ninja.cc @@ -41,7 +41,7 @@ int main(int argc, char** argv) { ManifestParser parser(&state); string err; if (!parser.Load(input_file, &err)) { - fprintf(stderr, "error loading: %s\n", err.c_str()); + fprintf(stderr, "error loading '%s': %s\n", input_file, err.c_str()); return 1; } Shell shell; diff --git a/ninja_test.cc b/ninja_test.cc index b5b1168..87236f4 100644 --- a/ninja_test.cc +++ b/ninja_test.cc @@ -7,7 +7,7 @@ namespace { void AssertParse(State* state, const char* input) { ManifestParser parser(state); string err; - ASSERT_TRUE(parser.Parse(input, &err)); + ASSERT_TRUE(parser.Parse(input, &err)) << err; ASSERT_EQ("", err); } @@ -41,7 +41,7 @@ TEST(Parser, Variables) { "rule link\n" "command ld $extra -o $out @in\n" "\n" -"let extra = -pthread\n" +"extra = -pthread\n" "build a: link b c\n")); ASSERT_EQ(1, state.edges_.size()); @@ -56,28 +56,28 @@ TEST(Parser, Errors) { ManifestParser parser(NULL); string err; EXPECT_FALSE(parser.Parse("foobar", &err)); - EXPECT_EQ("line 1, col 1: unknown token: foobar", err); + EXPECT_EQ("line 1, col 7: expected '=', got ''", err); } { ManifestParser parser(NULL); string err; - EXPECT_FALSE(parser.Parse("let x 3", &err)); - EXPECT_EQ("line 1, col 7: expected '=', got '3'", err); + EXPECT_FALSE(parser.Parse("x 3", &err)); + EXPECT_EQ("line 1, col 3: expected '=', got '3'", err); } { ManifestParser parser(NULL); string err; - EXPECT_FALSE(parser.Parse("let x = 3", &err)); - EXPECT_EQ("line 1, col 10: expected newline, got eof", err); + EXPECT_FALSE(parser.Parse("x = 3", &err)); + EXPECT_EQ("line 1, col 6: expected newline, got eof", err); } { ManifestParser parser(&state); string err; - EXPECT_FALSE(parser.Parse("let x = 3\nlet y 2", &err)); - EXPECT_EQ("line 2, col 7: expected '=', got '2'", err); + EXPECT_FALSE(parser.Parse("x = 3\ny 2", &err)); + EXPECT_EQ("line 2, col 3: expected '=', got '2'", err); } } -- 2.34.1