From 443039a58f35a84bde67eed29e611fb6546cd137 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 4 Nov 2020 15:48:20 +0000 Subject: [PATCH] wsgl parser: Use expect() for call r-parenthesis Keeps error message consistent. Reduces code. Bug: tint:282 Change-Id: Ibbbb98bb6f080dd338af7de415c6e86298d910e3 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31730 Commit-Queue: Ben Clayton Commit-Queue: dan sinclair Reviewed-by: dan sinclair --- src/reader/wgsl/parser_impl.cc | 11 +++-------- src/reader/wgsl/parser_impl_call_stmt_test.cc | 4 ++-- src/reader/wgsl/parser_impl_error_msg_test.cc | 4 ++-- .../wgsl/parser_impl_postfix_expression_test.cc | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 2a63c4ac5b..0176c83ba0 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -2587,11 +2587,8 @@ std::unique_ptr ParserImpl::func_call_stmt() { return nullptr; } - t = next(); - if (!t.IsParenRight()) { - add_error(t, "missing ) for call statement"); + if (!expect("call statement", Token::Type::kParenRight)) return nullptr; - } return std::make_unique( std::make_unique( @@ -2763,11 +2760,9 @@ std::unique_ptr ParserImpl::postfix_expr( return nullptr; } - t = next(); - if (!t.IsParenRight()) { - add_error(t, "missing ) for call expression"); + if (!expect("call expression", Token::Type::kParenRight)) return nullptr; - } + expr = std::make_unique(source, std::move(prefix), std::move(params)); } else if (t.IsPeriod()) { diff --git a/src/reader/wgsl/parser_impl_call_stmt_test.cc b/src/reader/wgsl/parser_impl_call_stmt_test.cc index 9f567e98eb..2ab8b19550 100644 --- a/src/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_call_stmt_test.cc @@ -63,7 +63,7 @@ TEST_F(ParserImplTest, Statement_Call_Missing_RightParen) { auto* p = parser("a("); auto e = p->statement(); ASSERT_TRUE(p->has_error()); - EXPECT_EQ(p->error(), "1:3: missing ) for call statement"); + EXPECT_EQ(p->error(), "1:3: expected ')' for call statement"); } TEST_F(ParserImplTest, Statement_Call_Missing_Semi) { @@ -77,7 +77,7 @@ TEST_F(ParserImplTest, Statement_Call_Bad_ArgList) { auto* p = parser("a(b c);"); auto e = p->statement(); ASSERT_TRUE(p->has_error()); - EXPECT_EQ(p->error(), "1:5: missing ) for call statement"); + EXPECT_EQ(p->error(), "1:5: expected ')' for call statement"); } } // namespace diff --git a/src/reader/wgsl/parser_impl_error_msg_test.cc b/src/reader/wgsl/parser_impl_error_msg_test.cc index 73b61d7597..e035f9fb9e 100644 --- a/src/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/reader/wgsl/parser_impl_error_msg_test.cc @@ -119,14 +119,14 @@ TEST_F(ParserImplErrorTest, BreakStmtMissingSemicolon) { TEST_F(ParserImplErrorTest, CallExprMissingRParen) { EXPECT("fn f() -> void { x = f(1.; }", - "test.wgsl:1:26 error: missing ) for call expression\n" + "test.wgsl:1:26 error: expected ')' for call expression\n" "fn f() -> void { x = f(1.; }\n" " ^\n"); } TEST_F(ParserImplErrorTest, CallStmtMissingRParen) { EXPECT("fn f() -> void { f(1.; }", - "test.wgsl:1:22 error: missing ) for call statement\n" + "test.wgsl:1:22 error: expected ')' for call statement\n" "fn f() -> void { f(1.; }\n" " ^\n"); } diff --git a/src/reader/wgsl/parser_impl_postfix_expression_test.cc b/src/reader/wgsl/parser_impl_postfix_expression_test.cc index 4ec04b2adb..ab16e53c22 100644 --- a/src/reader/wgsl/parser_impl_postfix_expression_test.cc +++ b/src/reader/wgsl/parser_impl_postfix_expression_test.cc @@ -144,7 +144,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_MissingRightParen) { auto e = p->postfix_expression(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(e, nullptr); - EXPECT_EQ(p->error(), "1:3: missing ) for call expression"); + EXPECT_EQ(p->error(), "1:3: expected ')' for call expression"); } TEST_F(ParserImplTest, PostfixExpression_MemberAccessor) {