[wgsl-reader] Adding body_statement to statement grammar
Block statements will now be parsed in ParserImpl::statement() Change-Id: I28f63d4a53c85c0306c57df545f78b4562c6ea7b Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27262 Reviewed-by: dan sinclair <dsinclair@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
04f5166ac1
commit
43c2a6c7d4
|
@ -1479,6 +1479,7 @@ std::unique_ptr<ast::BlockStatement> ParserImpl::statements() {
|
||||||
// | continue_stmt SEMICOLON
|
// | continue_stmt SEMICOLON
|
||||||
// | DISCARD SEMICOLON
|
// | DISCARD SEMICOLON
|
||||||
// | assignment_stmt SEMICOLON
|
// | assignment_stmt SEMICOLON
|
||||||
|
// | body_stmt
|
||||||
std::unique_ptr<ast::Statement> ParserImpl::statement() {
|
std::unique_ptr<ast::Statement> ParserImpl::statement() {
|
||||||
auto t = peek();
|
auto t = peek();
|
||||||
if (t.IsSemicolon()) {
|
if (t.IsSemicolon()) {
|
||||||
|
@ -1588,6 +1589,12 @@ std::unique_ptr<ast::Statement> ParserImpl::statement() {
|
||||||
return assign;
|
return assign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto body = body_stmt();
|
||||||
|
if (has_error())
|
||||||
|
return nullptr;
|
||||||
|
if (body != nullptr)
|
||||||
|
return body;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,6 +221,23 @@ TEST_F(ParserImplTest, Statement_Discard_MissingSemicolon) {
|
||||||
EXPECT_EQ(p->error(), "1:8: missing ;");
|
EXPECT_EQ(p->error(), "1:8: missing ;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserImplTest, Statement_Body) {
|
||||||
|
auto* p = parser("{ var i: i32; }");
|
||||||
|
auto e = p->statement();
|
||||||
|
ASSERT_FALSE(p->has_error()) << p->error();
|
||||||
|
ASSERT_NE(e, nullptr);
|
||||||
|
ASSERT_TRUE(e->IsBlock());
|
||||||
|
EXPECT_TRUE(e->AsBlock()->get(0)->IsVariableDecl());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserImplTest, Statement_Body_Invalid) {
|
||||||
|
auto* p = parser("{ fn main() -> {}}");
|
||||||
|
auto e = p->statement();
|
||||||
|
ASSERT_TRUE(p->has_error());
|
||||||
|
ASSERT_EQ(e, nullptr);
|
||||||
|
EXPECT_EQ(p->error(), "1:3: missing }");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
} // namespace reader
|
} // namespace reader
|
||||||
|
|
Loading…
Reference in New Issue