Sync the `statement` grammar element.
This CL updates a few names in the statement element to match the spec. The `body_stmt` is now `compound_statement`. Bug: tint:1633 Change-Id: I23a622fc8587641d3b6c5ff2641f29a3471fa4e1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98280 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
7d8307122e
commit
1cd4706f85
|
@ -1126,8 +1126,8 @@ if (tint_build_unittests) {
|
||||||
"resolver/resolver_test_helper.cc",
|
"resolver/resolver_test_helper.cc",
|
||||||
"resolver/resolver_test_helper.h",
|
"resolver/resolver_test_helper.h",
|
||||||
"resolver/side_effects_test.cc",
|
"resolver/side_effects_test.cc",
|
||||||
"resolver/static_assert_test.cc",
|
|
||||||
"resolver/source_variable_test.cc",
|
"resolver/source_variable_test.cc",
|
||||||
|
"resolver/static_assert_test.cc",
|
||||||
"resolver/storage_class_layout_validation_test.cc",
|
"resolver/storage_class_layout_validation_test.cc",
|
||||||
"resolver/storage_class_validation_test.cc",
|
"resolver/storage_class_validation_test.cc",
|
||||||
"resolver/struct_layout_test.cc",
|
"resolver/struct_layout_test.cc",
|
||||||
|
@ -1349,11 +1349,11 @@ if (tint_build_unittests) {
|
||||||
"reader/wgsl/parser_impl_and_expression_test.cc",
|
"reader/wgsl/parser_impl_and_expression_test.cc",
|
||||||
"reader/wgsl/parser_impl_argument_expression_list_test.cc",
|
"reader/wgsl/parser_impl_argument_expression_list_test.cc",
|
||||||
"reader/wgsl/parser_impl_assignment_stmt_test.cc",
|
"reader/wgsl/parser_impl_assignment_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_body_stmt_test.cc",
|
|
||||||
"reader/wgsl/parser_impl_break_stmt_test.cc",
|
"reader/wgsl/parser_impl_break_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_bug_cases_test.cc",
|
"reader/wgsl/parser_impl_bug_cases_test.cc",
|
||||||
"reader/wgsl/parser_impl_call_stmt_test.cc",
|
"reader/wgsl/parser_impl_call_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_case_body_test.cc",
|
"reader/wgsl/parser_impl_case_body_test.cc",
|
||||||
|
"reader/wgsl/parser_impl_compound_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_const_literal_test.cc",
|
"reader/wgsl/parser_impl_const_literal_test.cc",
|
||||||
"reader/wgsl/parser_impl_continue_stmt_test.cc",
|
"reader/wgsl/parser_impl_continue_stmt_test.cc",
|
||||||
"reader/wgsl/parser_impl_continuing_stmt_test.cc",
|
"reader/wgsl/parser_impl_continuing_stmt_test.cc",
|
||||||
|
|
|
@ -944,11 +944,11 @@ if(TINT_BUILD_TESTS)
|
||||||
reader/wgsl/parser_impl_and_expression_test.cc
|
reader/wgsl/parser_impl_and_expression_test.cc
|
||||||
reader/wgsl/parser_impl_argument_expression_list_test.cc
|
reader/wgsl/parser_impl_argument_expression_list_test.cc
|
||||||
reader/wgsl/parser_impl_assignment_stmt_test.cc
|
reader/wgsl/parser_impl_assignment_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_body_stmt_test.cc
|
|
||||||
reader/wgsl/parser_impl_break_stmt_test.cc
|
reader/wgsl/parser_impl_break_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_bug_cases_test.cc
|
reader/wgsl/parser_impl_bug_cases_test.cc
|
||||||
reader/wgsl/parser_impl_call_stmt_test.cc
|
reader/wgsl/parser_impl_call_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_case_body_test.cc
|
reader/wgsl/parser_impl_case_body_test.cc
|
||||||
|
reader/wgsl/parser_impl_compound_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_const_literal_test.cc
|
reader/wgsl/parser_impl_const_literal_test.cc
|
||||||
reader/wgsl/parser_impl_continue_stmt_test.cc
|
reader/wgsl/parser_impl_continue_stmt_test.cc
|
||||||
reader/wgsl/parser_impl_continuing_stmt_test.cc
|
reader/wgsl/parser_impl_continuing_stmt_test.cc
|
||||||
|
|
|
@ -482,7 +482,7 @@ Maybe<bool> ParserImpl::global_decl() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto assertion = static_assert_stmt();
|
auto assertion = static_assert_statement();
|
||||||
if (assertion.errored) {
|
if (assertion.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1368,7 +1368,7 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member() {
|
||||||
|
|
||||||
// static_assert
|
// static_assert
|
||||||
// : STATIC_ASSERT expression
|
// : STATIC_ASSERT expression
|
||||||
Maybe<const ast::StaticAssert*> ParserImpl::static_assert_stmt() {
|
Maybe<const ast::StaticAssert*> ParserImpl::static_assert_statement() {
|
||||||
Source start;
|
Source start;
|
||||||
if (!match(Token::Type::kStaticAssert, &start)) {
|
if (!match(Token::Type::kStaticAssert, &start)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -1387,7 +1387,7 @@ Maybe<const ast::StaticAssert*> ParserImpl::static_assert_stmt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// function_decl
|
// function_decl
|
||||||
// : function_header body_stmt
|
// : function_header compound_statement
|
||||||
Maybe<const ast::Function*> ParserImpl::function_decl(AttributeList& attrs) {
|
Maybe<const ast::Function*> ParserImpl::function_decl(AttributeList& attrs) {
|
||||||
auto header = function_header();
|
auto header = function_header();
|
||||||
if (header.errored) {
|
if (header.errored) {
|
||||||
|
@ -1398,7 +1398,7 @@ Maybe<const ast::Function*> ParserImpl::function_decl(AttributeList& attrs) {
|
||||||
// function body. The AST isn't used as we've already errored, but this
|
// function body. The AST isn't used as we've already errored, but this
|
||||||
// catches any errors inside the body, and can help keep the parser in
|
// catches any errors inside the body, and can help keep the parser in
|
||||||
// sync.
|
// sync.
|
||||||
expect_body_stmt();
|
expect_compound_statement();
|
||||||
}
|
}
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1408,7 +1408,7 @@ Maybe<const ast::Function*> ParserImpl::function_decl(AttributeList& attrs) {
|
||||||
|
|
||||||
bool errored = false;
|
bool errored = false;
|
||||||
|
|
||||||
auto body = expect_body_stmt();
|
auto body = expect_compound_statement();
|
||||||
if (body.errored) {
|
if (body.errored) {
|
||||||
errored = true;
|
errored = true;
|
||||||
}
|
}
|
||||||
|
@ -1624,9 +1624,9 @@ Expect<ast::BuiltinValue> ParserImpl::expect_builtin() {
|
||||||
return {builtin, ident.source};
|
return {builtin, ident.source};
|
||||||
}
|
}
|
||||||
|
|
||||||
// body_stmt
|
// compound_statement
|
||||||
// : BRACE_LEFT statements BRACE_RIGHT
|
// : BRACE_LEFT statement* BRACE_RIGHT
|
||||||
Expect<ast::BlockStatement*> ParserImpl::expect_body_stmt() {
|
Expect<ast::BlockStatement*> ParserImpl::expect_compound_statement() {
|
||||||
return expect_brace_block("", [&]() -> Expect<ast::BlockStatement*> {
|
return expect_brace_block("", [&]() -> Expect<ast::BlockStatement*> {
|
||||||
auto stmts = expect_statements();
|
auto stmts = expect_statements();
|
||||||
if (stmts.errored) {
|
if (stmts.errored) {
|
||||||
|
@ -1678,23 +1678,13 @@ Expect<ParserImpl::StatementList> ParserImpl::expect_statements() {
|
||||||
|
|
||||||
// statement
|
// statement
|
||||||
// : SEMICOLON
|
// : SEMICOLON
|
||||||
// | body_stmt?
|
// | if_statement
|
||||||
// | if_stmt
|
// | switch_statement
|
||||||
// | switch_stmt
|
// | loop_statement
|
||||||
// | loop_stmt
|
// | for_statement
|
||||||
// | for_stmt
|
// | while_statement
|
||||||
// | while_stmt
|
// | compound_statement
|
||||||
// | non_block_statement
|
// | non_block_statement // Note, we inject an extra rule in here for simpler parsing
|
||||||
// : return_stmt SEMICOLON
|
|
||||||
// | func_call_stmt SEMICOLON
|
|
||||||
// | variable_stmt SEMICOLON
|
|
||||||
// | break_stmt SEMICOLON
|
|
||||||
// | continue_stmt SEMICOLON
|
|
||||||
// | DISCARD SEMICOLON
|
|
||||||
// | assignment_stmt SEMICOLON
|
|
||||||
// | increment_stmt SEMICOLON
|
|
||||||
// | decrement_stmt SEMICOLON
|
|
||||||
// | static_assert_stmt SEMICOLON
|
|
||||||
Maybe<const ast::Statement*> ParserImpl::statement() {
|
Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
while (match(Token::Type::kSemicolon)) {
|
while (match(Token::Type::kSemicolon)) {
|
||||||
// Skip empty statements
|
// Skip empty statements
|
||||||
|
@ -1702,7 +1692,6 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
|
|
||||||
// Non-block statements that error can resynchronize on semicolon.
|
// Non-block statements that error can resynchronize on semicolon.
|
||||||
auto stmt = sync(Token::Type::kSemicolon, [&] { return non_block_statement(); });
|
auto stmt = sync(Token::Type::kSemicolon, [&] { return non_block_statement(); });
|
||||||
|
|
||||||
if (stmt.errored) {
|
if (stmt.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1710,7 +1699,7 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
return stmt;
|
return stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stmt_if = if_stmt();
|
auto stmt_if = if_statement();
|
||||||
if (stmt_if.errored) {
|
if (stmt_if.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1718,7 +1707,7 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
return stmt_if.value;
|
return stmt_if.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sw = switch_stmt();
|
auto sw = switch_statement();
|
||||||
if (sw.errored) {
|
if (sw.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1726,7 +1715,7 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
return sw.value;
|
return sw.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto loop = loop_stmt();
|
auto loop = loop_statement();
|
||||||
if (loop.errored) {
|
if (loop.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1734,7 +1723,7 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
return loop.value;
|
return loop.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stmt_for = for_stmt();
|
auto stmt_for = for_statement();
|
||||||
if (stmt_for.errored) {
|
if (stmt_for.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1742,7 +1731,7 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
return stmt_for.value;
|
return stmt_for.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stmt_while = while_stmt();
|
auto stmt_while = while_statement();
|
||||||
if (stmt_while.errored) {
|
if (stmt_while.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1751,7 +1740,7 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peek_is(Token::Type::kBraceLeft)) {
|
if (peek_is(Token::Type::kBraceLeft)) {
|
||||||
auto body = expect_body_stmt();
|
auto body = expect_compound_statement();
|
||||||
if (body.errored) {
|
if (body.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1761,19 +1750,20 @@ Maybe<const ast::Statement*> ParserImpl::statement() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// statement (continued)
|
// non_block_statement (continued)
|
||||||
// : return_stmt SEMICOLON
|
// : return_statement SEMICOLON
|
||||||
// | func_call_stmt SEMICOLON
|
// | func_call_statement SEMICOLON
|
||||||
// | variable_stmt SEMICOLON
|
// | variable_statement SEMICOLON
|
||||||
// | break_stmt SEMICOLON
|
// | break_statement SEMICOLON
|
||||||
// | continue_stmt SEMICOLON
|
// | continue_statement SEMICOLON
|
||||||
// | DISCARD SEMICOLON
|
// | DISCARD SEMICOLON
|
||||||
// | assignment_stmt SEMICOLON
|
// | assignment_statement SEMICOLON
|
||||||
// | increment_stmt SEMICOLON
|
// | increment_statement SEMICOLON
|
||||||
// | decrement_stmt SEMICOLON
|
// | decrement_statement SEMICOLON
|
||||||
|
// | static_assert_statement SEMICOLON
|
||||||
Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
auto stmt = [&]() -> Maybe<const ast::Statement*> {
|
auto stmt = [&]() -> Maybe<const ast::Statement*> {
|
||||||
auto ret_stmt = return_stmt();
|
auto ret_stmt = return_statement();
|
||||||
if (ret_stmt.errored) {
|
if (ret_stmt.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1781,7 +1771,7 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return ret_stmt.value;
|
return ret_stmt.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto func = func_call_stmt();
|
auto func = func_call_statement();
|
||||||
if (func.errored) {
|
if (func.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1789,7 +1779,7 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return func.value;
|
return func.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto var = variable_stmt();
|
auto var = variable_statement();
|
||||||
if (var.errored) {
|
if (var.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1797,7 +1787,7 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return var.value;
|
return var.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto b = break_stmt();
|
auto b = break_statement();
|
||||||
if (b.errored) {
|
if (b.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1805,7 +1795,7 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return b.value;
|
return b.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cont = continue_stmt();
|
auto cont = continue_statement();
|
||||||
if (cont.errored) {
|
if (cont.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1813,7 +1803,13 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return cont.value;
|
return cont.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto assign = assignment_stmt();
|
Source source;
|
||||||
|
if (match(Token::Type::kDiscard, &source)) {
|
||||||
|
return create<ast::DiscardStatement>(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note, this covers assignment, increment and decrement
|
||||||
|
auto assign = assignment_statement();
|
||||||
if (assign.errored) {
|
if (assign.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1821,7 +1817,7 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return assign.value;
|
return assign.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stmt_static_assert = static_assert_stmt();
|
auto stmt_static_assert = static_assert_statement();
|
||||||
if (stmt_static_assert.errored) {
|
if (stmt_static_assert.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -1829,24 +1825,18 @@ Maybe<const ast::Statement*> ParserImpl::non_block_statement() {
|
||||||
return stmt_static_assert.value;
|
return stmt_static_assert.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Source source;
|
|
||||||
if (match(Token::Type::kDiscard, &source)) {
|
|
||||||
return create<ast::DiscardStatement>(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (stmt.matched && !expect(stmt->Name(), Token::Type::kSemicolon)) {
|
if (stmt.matched && !expect(stmt->Name(), Token::Type::kSemicolon)) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stmt;
|
return stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return_stmt
|
// return_statement
|
||||||
// : RETURN expression?
|
// : RETURN expression?
|
||||||
Maybe<const ast::ReturnStatement*> ParserImpl::return_stmt() {
|
Maybe<const ast::ReturnStatement*> ParserImpl::return_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kReturn, &source)) {
|
if (!match(Token::Type::kReturn, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -1865,11 +1855,11 @@ Maybe<const ast::ReturnStatement*> ParserImpl::return_stmt() {
|
||||||
return create<ast::ReturnStatement>(source, expr.value);
|
return create<ast::ReturnStatement>(source, expr.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// variable_stmt
|
// variable_statement
|
||||||
// : variable_decl
|
// : variable_decl
|
||||||
// | variable_decl EQUAL expression
|
// | variable_decl EQUAL expression
|
||||||
// | CONST variable_ident_decl EQUAL expression
|
// | CONST variable_ident_decl EQUAL expression
|
||||||
Maybe<const ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
|
Maybe<const ast::VariableDeclStatement*> ParserImpl::variable_statement() {
|
||||||
if (match(Token::Type::kConst)) {
|
if (match(Token::Type::kConst)) {
|
||||||
auto decl = expect_variable_ident_decl("'const' declaration",
|
auto decl = expect_variable_ident_decl("'const' declaration",
|
||||||
/*allow_inferred = */ true);
|
/*allow_inferred = */ true);
|
||||||
|
@ -1958,12 +1948,12 @@ Maybe<const ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
|
||||||
return create<ast::VariableDeclStatement>(var->source, var);
|
return create<ast::VariableDeclStatement>(var->source, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if_stmt
|
// if_statement
|
||||||
// : IF expression compound_stmt ( ELSE else_stmt ) ?
|
// : IF expression compound_stmt ( ELSE else_stmt ) ?
|
||||||
// else_stmt
|
// else_stmt
|
||||||
// : body_stmt
|
// : compound_statement
|
||||||
// | if_stmt
|
// | if_statement
|
||||||
Maybe<const ast::IfStatement*> ParserImpl::if_stmt() {
|
Maybe<const ast::IfStatement*> ParserImpl::if_statement() {
|
||||||
// Parse if-else chains iteratively instead of recursively, to avoid
|
// Parse if-else chains iteratively instead of recursively, to avoid
|
||||||
// stack-overflow for long chains of if-else statements.
|
// stack-overflow for long chains of if-else statements.
|
||||||
|
|
||||||
|
@ -1988,7 +1978,7 @@ Maybe<const ast::IfStatement*> ParserImpl::if_stmt() {
|
||||||
return add_error(peek(), "unable to parse condition expression");
|
return add_error(peek(), "unable to parse condition expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto body = expect_body_stmt();
|
auto body = expect_compound_statement();
|
||||||
if (body.errored) {
|
if (body.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2024,7 +2014,7 @@ Maybe<const ast::IfStatement*> ParserImpl::if_stmt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it wasn't an "else if", it must just be an "else".
|
// If it wasn't an "else if", it must just be an "else".
|
||||||
auto else_body = expect_body_stmt();
|
auto else_body = expect_compound_statement();
|
||||||
if (else_body.errored) {
|
if (else_body.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2040,9 +2030,9 @@ Maybe<const ast::IfStatement*> ParserImpl::if_stmt() {
|
||||||
return last_stmt->As<ast::IfStatement>();
|
return last_stmt->As<ast::IfStatement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch_stmt
|
// switch_statement
|
||||||
// : SWITCH expression BRACKET_LEFT switch_body+ BRACKET_RIGHT
|
// : SWITCH expression BRACKET_LEFT switch_body+ BRACKET_RIGHT
|
||||||
Maybe<const ast::SwitchStatement*> ParserImpl::switch_stmt() {
|
Maybe<const ast::SwitchStatement*> ParserImpl::switch_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kSwitch, &source)) {
|
if (!match(Token::Type::kSwitch, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -2179,9 +2169,9 @@ Maybe<const ast::BlockStatement*> ParserImpl::case_body() {
|
||||||
return create<ast::BlockStatement>(Source{}, stmts);
|
return create<ast::BlockStatement>(Source{}, stmts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop_stmt
|
// loop_statement
|
||||||
// : LOOP BRACKET_LEFT statements continuing_stmt? BRACKET_RIGHT
|
// : LOOP BRACKET_LEFT statements continuing_stmt? BRACKET_RIGHT
|
||||||
Maybe<const ast::LoopStatement*> ParserImpl::loop_stmt() {
|
Maybe<const ast::LoopStatement*> ParserImpl::loop_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kLoop, &source)) {
|
if (!match(Token::Type::kLoop, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -2210,10 +2200,10 @@ ForHeader::ForHeader(const ast::Statement* init,
|
||||||
|
|
||||||
ForHeader::~ForHeader() = default;
|
ForHeader::~ForHeader() = default;
|
||||||
|
|
||||||
// (variable_stmt | increment_stmt | decrement_stmt | assignment_stmt |
|
// (variable_statement | increment_statement | decrement_statement | assignment_statement |
|
||||||
// func_call_stmt)?
|
// func_call_statement)?
|
||||||
Maybe<const ast::Statement*> ParserImpl::for_header_initializer() {
|
Maybe<const ast::Statement*> ParserImpl::for_header_initializer() {
|
||||||
auto call = func_call_stmt();
|
auto call = func_call_statement();
|
||||||
if (call.errored) {
|
if (call.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2221,7 +2211,7 @@ Maybe<const ast::Statement*> ParserImpl::for_header_initializer() {
|
||||||
return call.value;
|
return call.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto var = variable_stmt();
|
auto var = variable_statement();
|
||||||
if (var.errored) {
|
if (var.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2229,7 +2219,7 @@ Maybe<const ast::Statement*> ParserImpl::for_header_initializer() {
|
||||||
return var.value;
|
return var.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto assign = assignment_stmt();
|
auto assign = assignment_statement();
|
||||||
if (assign.errored) {
|
if (assign.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2240,9 +2230,9 @@ Maybe<const ast::Statement*> ParserImpl::for_header_initializer() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (increment_stmt | decrement_stmt | assignment_stmt | func_call_stmt)?
|
// (increment_statement | decrement_statement | assignment_statement | func_call_statement)?
|
||||||
Maybe<const ast::Statement*> ParserImpl::for_header_continuing() {
|
Maybe<const ast::Statement*> ParserImpl::for_header_continuing() {
|
||||||
auto call_stmt = func_call_stmt();
|
auto call_stmt = func_call_statement();
|
||||||
if (call_stmt.errored) {
|
if (call_stmt.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2250,7 +2240,7 @@ Maybe<const ast::Statement*> ParserImpl::for_header_continuing() {
|
||||||
return call_stmt.value;
|
return call_stmt.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto assign = assignment_stmt();
|
auto assign = assignment_statement();
|
||||||
if (assign.errored) {
|
if (assign.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2262,10 +2252,10 @@ Maybe<const ast::Statement*> ParserImpl::for_header_continuing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for_header
|
// for_header
|
||||||
// : (variable_stmt | assignment_stmt | func_call_stmt)?
|
// : (variable_statement | assignment_statement | func_call_statement)?
|
||||||
// SEMICOLON
|
// SEMICOLON
|
||||||
// expression? SEMICOLON
|
// expression? SEMICOLON
|
||||||
// (assignment_stmt | func_call_stmt)?
|
// (assignment_statement | func_call_statement)?
|
||||||
Expect<std::unique_ptr<ForHeader>> ParserImpl::expect_for_header() {
|
Expect<std::unique_ptr<ForHeader>> ParserImpl::expect_for_header() {
|
||||||
auto initializer = for_header_initializer();
|
auto initializer = for_header_initializer();
|
||||||
if (initializer.errored) {
|
if (initializer.errored) {
|
||||||
|
@ -2295,7 +2285,7 @@ Expect<std::unique_ptr<ForHeader>> ParserImpl::expect_for_header() {
|
||||||
|
|
||||||
// for_statement
|
// for_statement
|
||||||
// : FOR PAREN_LEFT for_header PAREN_RIGHT BRACE_LEFT statements BRACE_RIGHT
|
// : FOR PAREN_LEFT for_header PAREN_RIGHT BRACE_LEFT statements BRACE_RIGHT
|
||||||
Maybe<const ast::ForLoopStatement*> ParserImpl::for_stmt() {
|
Maybe<const ast::ForLoopStatement*> ParserImpl::for_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kFor, &source)) {
|
if (!match(Token::Type::kFor, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -2318,7 +2308,7 @@ Maybe<const ast::ForLoopStatement*> ParserImpl::for_stmt() {
|
||||||
|
|
||||||
// while_statement
|
// while_statement
|
||||||
// : WHILE expression compound_statement
|
// : WHILE expression compound_statement
|
||||||
Maybe<const ast::WhileStatement*> ParserImpl::while_stmt() {
|
Maybe<const ast::WhileStatement*> ParserImpl::while_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kWhile, &source)) {
|
if (!match(Token::Type::kWhile, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -2332,7 +2322,7 @@ Maybe<const ast::WhileStatement*> ParserImpl::while_stmt() {
|
||||||
return add_error(peek(), "unable to parse while condition expression");
|
return add_error(peek(), "unable to parse while condition expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto body = expect_body_stmt();
|
auto body = expect_compound_statement();
|
||||||
if (body.errored) {
|
if (body.errored) {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
@ -2340,9 +2330,9 @@ Maybe<const ast::WhileStatement*> ParserImpl::while_stmt() {
|
||||||
return create<ast::WhileStatement>(source, condition.value, body.value);
|
return create<ast::WhileStatement>(source, condition.value, body.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// func_call_stmt
|
// func_call_statement
|
||||||
// : IDENT argument_expression_list
|
// : IDENT argument_expression_list
|
||||||
Maybe<const ast::CallStatement*> ParserImpl::func_call_stmt() {
|
Maybe<const ast::CallStatement*> ParserImpl::func_call_statement() {
|
||||||
auto& t = peek();
|
auto& t = peek();
|
||||||
auto& t2 = peek(1);
|
auto& t2 = peek(1);
|
||||||
if (!t.IsIdentifier() || !t2.Is(Token::Type::kParenLeft)) {
|
if (!t.IsIdentifier() || !t2.Is(Token::Type::kParenLeft)) {
|
||||||
|
@ -2364,9 +2354,9 @@ Maybe<const ast::CallStatement*> ParserImpl::func_call_stmt() {
|
||||||
std::move(params.value)));
|
std::move(params.value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// break_stmt
|
// break_statement
|
||||||
// : BREAK
|
// : BREAK
|
||||||
Maybe<const ast::BreakStatement*> ParserImpl::break_stmt() {
|
Maybe<const ast::BreakStatement*> ParserImpl::break_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kBreak, &source)) {
|
if (!match(Token::Type::kBreak, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -2375,9 +2365,9 @@ Maybe<const ast::BreakStatement*> ParserImpl::break_stmt() {
|
||||||
return create<ast::BreakStatement>(source);
|
return create<ast::BreakStatement>(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// continue_stmt
|
// continue_statement
|
||||||
// : CONTINUE
|
// : CONTINUE
|
||||||
Maybe<const ast::ContinueStatement*> ParserImpl::continue_stmt() {
|
Maybe<const ast::ContinueStatement*> ParserImpl::continue_statement() {
|
||||||
Source source;
|
Source source;
|
||||||
if (!match(Token::Type::kContinue, &source)) {
|
if (!match(Token::Type::kContinue, &source)) {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
|
@ -2387,13 +2377,13 @@ Maybe<const ast::ContinueStatement*> ParserImpl::continue_stmt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// continuing_stmt
|
// continuing_stmt
|
||||||
// : CONTINUING body_stmt
|
// : CONTINUING compound_statement
|
||||||
Maybe<const ast::BlockStatement*> ParserImpl::continuing_stmt() {
|
Maybe<const ast::BlockStatement*> ParserImpl::continuing_stmt() {
|
||||||
if (!match(Token::Type::kContinuing)) {
|
if (!match(Token::Type::kContinuing)) {
|
||||||
return create<ast::BlockStatement>(Source{}, utils::Empty);
|
return create<ast::BlockStatement>(Source{}, utils::Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
return expect_body_stmt();
|
return expect_compound_statement();
|
||||||
}
|
}
|
||||||
|
|
||||||
// primary_expression
|
// primary_expression
|
||||||
|
@ -3088,16 +3078,16 @@ Maybe<ast::BinaryOp> ParserImpl::compound_assignment_operator() {
|
||||||
return Failure::kNoMatch;
|
return Failure::kNoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// assignment_stmt
|
// assignment_statement
|
||||||
// | lhs_expression ( equal | compound_assignment_operator ) expression
|
// | lhs_expression ( equal | compound_assignment_operator ) expression
|
||||||
// | underscore equal expression
|
// | underscore equal expression
|
||||||
//
|
//
|
||||||
// increment_stmt
|
// increment_statement
|
||||||
// | lhs_expression PLUS_PLUS
|
// | lhs_expression PLUS_PLUS
|
||||||
//
|
//
|
||||||
// decrement_stmt
|
// decrement_statement
|
||||||
// | lhs_expression MINUS_MINUS
|
// | lhs_expression MINUS_MINUS
|
||||||
Maybe<const ast::Statement*> ParserImpl::assignment_stmt() {
|
Maybe<const ast::Statement*> ParserImpl::assignment_statement() {
|
||||||
auto& t = peek();
|
auto& t = peek();
|
||||||
|
|
||||||
// tint:295 - Test for `ident COLON` - this is invalid grammar, and without
|
// tint:295 - Test for `ident COLON` - this is invalid grammar, and without
|
||||||
|
|
|
@ -474,7 +474,7 @@ class ParserImpl {
|
||||||
Expect<ast::TexelFormat> expect_texel_format(std::string_view use);
|
Expect<ast::TexelFormat> expect_texel_format(std::string_view use);
|
||||||
/// Parses a `static_assert_statement` grammar element
|
/// Parses a `static_assert_statement` grammar element
|
||||||
/// @returns returns the static assert, if it matched.
|
/// @returns returns the static assert, if it matched.
|
||||||
Maybe<const ast::StaticAssert*> static_assert_stmt();
|
Maybe<const ast::StaticAssert*> static_assert_statement();
|
||||||
/// Parses a `function_header` grammar element
|
/// Parses a `function_header` grammar element
|
||||||
/// @returns the parsed function header
|
/// @returns the parsed function header
|
||||||
Maybe<FunctionHeader> function_header();
|
Maybe<FunctionHeader> function_header();
|
||||||
|
@ -505,9 +505,9 @@ class ParserImpl {
|
||||||
/// valid builtin name.
|
/// valid builtin name.
|
||||||
/// @returns the parsed builtin.
|
/// @returns the parsed builtin.
|
||||||
Expect<ast::BuiltinValue> expect_builtin();
|
Expect<ast::BuiltinValue> expect_builtin();
|
||||||
/// Parses a `body_stmt` grammar element, erroring on parse failure.
|
/// Parses a `compound_statement` grammar element, erroring on parse failure.
|
||||||
/// @returns the parsed statements
|
/// @returns the parsed statements
|
||||||
Expect<ast::BlockStatement*> expect_body_stmt();
|
Expect<ast::BlockStatement*> expect_compound_statement();
|
||||||
/// Parses a `paren_expression` grammar element, erroring on parse failure.
|
/// Parses a `paren_expression` grammar element, erroring on parse failure.
|
||||||
/// @returns the parsed element or nullptr
|
/// @returns the parsed element or nullptr
|
||||||
Expect<const ast::Expression*> expect_paren_expression();
|
Expect<const ast::Expression*> expect_paren_expression();
|
||||||
|
@ -517,24 +517,24 @@ class ParserImpl {
|
||||||
/// Parses a `statement` grammar element
|
/// Parses a `statement` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::Statement*> statement();
|
Maybe<const ast::Statement*> statement();
|
||||||
/// Parses a `break_stmt` grammar element
|
/// Parses a `break_statement` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::BreakStatement*> break_stmt();
|
Maybe<const ast::BreakStatement*> break_statement();
|
||||||
/// Parses a `return_stmt` grammar element
|
/// Parses a `return_statement` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::ReturnStatement*> return_stmt();
|
Maybe<const ast::ReturnStatement*> return_statement();
|
||||||
/// Parses a `continue_stmt` grammar element
|
/// Parses a `continue_statement` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::ContinueStatement*> continue_stmt();
|
Maybe<const ast::ContinueStatement*> continue_statement();
|
||||||
/// Parses a `variable_stmt` grammar element
|
/// Parses a `variable_statement` grammar element
|
||||||
/// @returns the parsed variable or nullptr
|
/// @returns the parsed variable or nullptr
|
||||||
Maybe<const ast::VariableDeclStatement*> variable_stmt();
|
Maybe<const ast::VariableDeclStatement*> variable_statement();
|
||||||
/// Parses a `if_stmt` grammar element
|
/// Parses a `if_statement` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::IfStatement*> if_stmt();
|
Maybe<const ast::IfStatement*> if_statement();
|
||||||
/// Parses a `switch_stmt` grammar element
|
/// Parses a `switch_statement` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::SwitchStatement*> switch_stmt();
|
Maybe<const ast::SwitchStatement*> switch_statement();
|
||||||
/// Parses a `switch_body` grammar element
|
/// Parses a `switch_body` grammar element
|
||||||
/// @returns the parsed statement or nullptr
|
/// @returns the parsed statement or nullptr
|
||||||
Maybe<const ast::CaseStatement*> switch_body();
|
Maybe<const ast::CaseStatement*> switch_body();
|
||||||
|
@ -544,21 +544,21 @@ class ParserImpl {
|
||||||
/// Parses a `case_body` grammar element
|
/// Parses a `case_body` grammar element
|
||||||
/// @returns the parsed statements
|
/// @returns the parsed statements
|
||||||
Maybe<const ast::BlockStatement*> case_body();
|
Maybe<const ast::BlockStatement*> case_body();
|
||||||
/// Parses a `func_call_stmt` grammar element
|
/// Parses a `func_call_statement` grammar element
|
||||||
/// @returns the parsed function call or nullptr
|
/// @returns the parsed function call or nullptr
|
||||||
Maybe<const ast::CallStatement*> func_call_stmt();
|
Maybe<const ast::CallStatement*> func_call_statement();
|
||||||
/// Parses a `loop_stmt` grammar element
|
/// Parses a `loop_statement` grammar element
|
||||||
/// @returns the parsed loop or nullptr
|
/// @returns the parsed loop or nullptr
|
||||||
Maybe<const ast::LoopStatement*> loop_stmt();
|
Maybe<const ast::LoopStatement*> loop_statement();
|
||||||
/// Parses a `for_header` grammar element, erroring on parse failure.
|
/// Parses a `for_header` grammar element, erroring on parse failure.
|
||||||
/// @returns the parsed for header or nullptr
|
/// @returns the parsed for header or nullptr
|
||||||
Expect<std::unique_ptr<ForHeader>> expect_for_header();
|
Expect<std::unique_ptr<ForHeader>> expect_for_header();
|
||||||
/// Parses a `for_stmt` grammar element
|
/// Parses a `for_statement` grammar element
|
||||||
/// @returns the parsed for loop or nullptr
|
/// @returns the parsed for loop or nullptr
|
||||||
Maybe<const ast::ForLoopStatement*> for_stmt();
|
Maybe<const ast::ForLoopStatement*> for_statement();
|
||||||
/// Parses a `while_stmt` grammar element
|
/// Parses a `while_statement` grammar element
|
||||||
/// @returns the parsed while loop or nullptr
|
/// @returns the parsed while loop or nullptr
|
||||||
Maybe<const ast::WhileStatement*> while_stmt();
|
Maybe<const ast::WhileStatement*> while_statement();
|
||||||
/// Parses a `continuing_stmt` grammar element
|
/// Parses a `continuing_stmt` grammar element
|
||||||
/// @returns the parsed statements
|
/// @returns the parsed statements
|
||||||
Maybe<const ast::BlockStatement*> continuing_stmt();
|
Maybe<const ast::BlockStatement*> continuing_stmt();
|
||||||
|
@ -669,9 +669,9 @@ class ParserImpl {
|
||||||
/// Parses a `compound_assignment_operator` grammar element
|
/// Parses a `compound_assignment_operator` grammar element
|
||||||
/// @returns the parsed compound assignment operator
|
/// @returns the parsed compound assignment operator
|
||||||
Maybe<ast::BinaryOp> compound_assignment_operator();
|
Maybe<ast::BinaryOp> compound_assignment_operator();
|
||||||
/// Parses a `assignment_stmt` grammar element
|
/// Parses a `assignment_statement` grammar element
|
||||||
/// @returns the parsed assignment or nullptr
|
/// @returns the parsed assignment or nullptr
|
||||||
Maybe<const ast::Statement*> assignment_stmt();
|
Maybe<const ast::Statement*> assignment_statement();
|
||||||
/// Parses one or more attribute lists.
|
/// Parses one or more attribute lists.
|
||||||
/// @return the parsed attribute list, or an empty list on error.
|
/// @return the parsed attribute list, or an empty list on error.
|
||||||
Maybe<AttributeList> attribute_list();
|
Maybe<AttributeList> attribute_list();
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
|
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
|
||||||
auto p = parser("a = 123");
|
auto p = parser("a = 123");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -42,7 +42,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
||||||
auto p = parser("a.b.c[2].d = 123");
|
auto p = parser("a.b.c[2].d = 123");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -92,7 +92,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToPhony) {
|
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToPhony) {
|
||||||
auto p = parser("_ = 123i");
|
auto p = parser("_ = 123i");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -119,7 +119,7 @@ using CompoundOpTest = ParserImplTestWithParam<CompoundData>;
|
||||||
TEST_P(CompoundOpTest, CompoundOp) {
|
TEST_P(CompoundOpTest, CompoundOp) {
|
||||||
auto params = GetParam();
|
auto params = GetParam();
|
||||||
auto p = parser("a " + params.str + " 123u");
|
auto p = parser("a " + params.str + " 123u");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -155,7 +155,7 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {
|
TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {
|
||||||
auto p = parser("a.b.c[2].d 123");
|
auto p = parser("a.b.c[2].d 123");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
|
@ -165,7 +165,7 @@ TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_Compound_MissingEqual) {
|
TEST_F(ParserImplTest, AssignmentStmt_Compound_MissingEqual) {
|
||||||
auto p = parser("a + 123");
|
auto p = parser("a + 123");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
|
@ -175,7 +175,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Compound_MissingEqual) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_InvalidLHS) {
|
TEST_F(ParserImplTest, AssignmentStmt_InvalidLHS) {
|
||||||
auto p = parser("if (true) {} = 123");
|
auto p = parser("if (true) {} = 123");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -184,7 +184,7 @@ TEST_F(ParserImplTest, AssignmentStmt_InvalidLHS) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_InvalidRHS) {
|
TEST_F(ParserImplTest, AssignmentStmt_InvalidRHS) {
|
||||||
auto p = parser("a.b.c[2].d = if (true) {}");
|
auto p = parser("a.b.c[2].d = if (true) {}");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -194,7 +194,7 @@ TEST_F(ParserImplTest, AssignmentStmt_InvalidRHS) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, AssignmentStmt_InvalidCompoundOp) {
|
TEST_F(ParserImplTest, AssignmentStmt_InvalidCompoundOp) {
|
||||||
auto p = parser("a &&= true");
|
auto p = parser("a &&= true");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, BreakStmt) {
|
TEST_F(ParserImplTest, BreakStmt) {
|
||||||
auto p = parser("break");
|
auto p = parser("break");
|
||||||
auto e = p->break_stmt();
|
auto e = p->break_statement();
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
namespace tint::reader::wgsl {
|
namespace tint::reader::wgsl {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, BodyStmt) {
|
TEST_F(ParserImplTest, CompoundStmt) {
|
||||||
auto p = parser(R"({
|
auto p = parser(R"({
|
||||||
discard;
|
discard;
|
||||||
return 1 + b / 2;
|
return 1 + b / 2;
|
||||||
})");
|
})");
|
||||||
auto e = p->expect_body_stmt();
|
auto e = p->expect_compound_statement();
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
ASSERT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
ASSERT_EQ(e->statements.Length(), 2u);
|
ASSERT_EQ(e->statements.Length(), 2u);
|
||||||
|
@ -31,25 +31,25 @@ TEST_F(ParserImplTest, BodyStmt) {
|
||||||
EXPECT_TRUE(e->statements[1]->Is<ast::ReturnStatement>());
|
EXPECT_TRUE(e->statements[1]->Is<ast::ReturnStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, BodyStmt_Empty) {
|
TEST_F(ParserImplTest, CompoundStmt_Empty) {
|
||||||
auto p = parser("{}");
|
auto p = parser("{}");
|
||||||
auto e = p->expect_body_stmt();
|
auto e = p->expect_compound_statement();
|
||||||
ASSERT_FALSE(p->has_error()) << p->error();
|
ASSERT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_FALSE(e.errored);
|
ASSERT_FALSE(e.errored);
|
||||||
EXPECT_EQ(e->statements.Length(), 0u);
|
EXPECT_EQ(e->statements.Length(), 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, BodyStmt_InvalidStmt) {
|
TEST_F(ParserImplTest, CompoundStmt_InvalidStmt) {
|
||||||
auto p = parser("{fn main() {}}");
|
auto p = parser("{fn main() {}}");
|
||||||
auto e = p->expect_body_stmt();
|
auto e = p->expect_compound_statement();
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_TRUE(e.errored);
|
ASSERT_TRUE(e.errored);
|
||||||
EXPECT_EQ(p->error(), "1:2: expected '}'");
|
EXPECT_EQ(p->error(), "1:2: expected '}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, BodyStmt_MissingRightParen) {
|
TEST_F(ParserImplTest, CompoundStmt_MissingRightParen) {
|
||||||
auto p = parser("{return;");
|
auto p = parser("{return;");
|
||||||
auto e = p->expect_body_stmt();
|
auto e = p->expect_compound_statement();
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_TRUE(e.errored);
|
ASSERT_TRUE(e.errored);
|
||||||
EXPECT_EQ(p->error(), "1:9: expected '}'");
|
EXPECT_EQ(p->error(), "1:9: expected '}'");
|
|
@ -20,7 +20,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, ContinueStmt) {
|
TEST_F(ParserImplTest, ContinueStmt) {
|
||||||
auto p = parser("continue");
|
auto p = parser("continue");
|
||||||
auto e = p->continue_stmt();
|
auto e = p->continue_statement();
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
ASSERT_NE(e.value, nullptr);
|
ASSERT_NE(e.value, nullptr);
|
||||||
|
|
|
@ -24,7 +24,7 @@ using ForStmtTest = ParserImplTest;
|
||||||
// Test an empty for loop.
|
// Test an empty for loop.
|
||||||
TEST_F(ForStmtTest, Empty) {
|
TEST_F(ForStmtTest, Empty) {
|
||||||
auto p = parser("for (;;) { }");
|
auto p = parser("for (;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -37,7 +37,7 @@ TEST_F(ForStmtTest, Empty) {
|
||||||
// Test a for loop with non-empty body.
|
// Test a for loop with non-empty body.
|
||||||
TEST_F(ForStmtTest, Body) {
|
TEST_F(ForStmtTest, Body) {
|
||||||
auto p = parser("for (;;) { discard; }");
|
auto p = parser("for (;;) { discard; }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -51,7 +51,7 @@ TEST_F(ForStmtTest, Body) {
|
||||||
// Test a for loop declaring a variable in the initializer statement.
|
// Test a for loop declaring a variable in the initializer statement.
|
||||||
TEST_F(ForStmtTest, InitializerStatementDecl) {
|
TEST_F(ForStmtTest, InitializerStatementDecl) {
|
||||||
auto p = parser("for (var i: i32 ;;) { }");
|
auto p = parser("for (var i: i32 ;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -68,7 +68,7 @@ TEST_F(ForStmtTest, InitializerStatementDecl) {
|
||||||
// statement.
|
// statement.
|
||||||
TEST_F(ForStmtTest, InitializerStatementDeclEqual) {
|
TEST_F(ForStmtTest, InitializerStatementDeclEqual) {
|
||||||
auto p = parser("for (var i: i32 = 0 ;;) { }");
|
auto p = parser("for (var i: i32 = 0 ;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -84,7 +84,7 @@ TEST_F(ForStmtTest, InitializerStatementDeclEqual) {
|
||||||
// Test a for loop declaring a const variable in the initializer statement.
|
// Test a for loop declaring a const variable in the initializer statement.
|
||||||
TEST_F(ForStmtTest, InitializerStatementConstDecl) {
|
TEST_F(ForStmtTest, InitializerStatementConstDecl) {
|
||||||
auto p = parser("for (let i: i32 = 0 ;;) { }");
|
auto p = parser("for (let i: i32 = 0 ;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -100,7 +100,7 @@ TEST_F(ForStmtTest, InitializerStatementConstDecl) {
|
||||||
// Test a for loop assigning a variable in the initializer statement.
|
// Test a for loop assigning a variable in the initializer statement.
|
||||||
TEST_F(ForStmtTest, InitializerStatementAssignment) {
|
TEST_F(ForStmtTest, InitializerStatementAssignment) {
|
||||||
auto p = parser("for (i = 0 ;;) { }");
|
auto p = parser("for (i = 0 ;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -113,7 +113,7 @@ TEST_F(ForStmtTest, InitializerStatementAssignment) {
|
||||||
// Test a for loop incrementing a variable in the initializer statement.
|
// Test a for loop incrementing a variable in the initializer statement.
|
||||||
TEST_F(ForStmtTest, InitializerStatementIncrement) {
|
TEST_F(ForStmtTest, InitializerStatementIncrement) {
|
||||||
auto p = parser("for (i++;;) { }");
|
auto p = parser("for (i++;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -126,7 +126,7 @@ TEST_F(ForStmtTest, InitializerStatementIncrement) {
|
||||||
// Test a for loop calling a function in the initializer statement.
|
// Test a for loop calling a function in the initializer statement.
|
||||||
TEST_F(ForStmtTest, InitializerStatementFuncCall) {
|
TEST_F(ForStmtTest, InitializerStatementFuncCall) {
|
||||||
auto p = parser("for (a(b,c) ;;) { }");
|
auto p = parser("for (a(b,c) ;;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -139,7 +139,7 @@ TEST_F(ForStmtTest, InitializerStatementFuncCall) {
|
||||||
// Test a for loop with a break condition
|
// Test a for loop with a break condition
|
||||||
TEST_F(ForStmtTest, BreakCondition) {
|
TEST_F(ForStmtTest, BreakCondition) {
|
||||||
auto p = parser("for (; 0 == 1;) { }");
|
auto p = parser("for (; 0 == 1;) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -152,7 +152,7 @@ TEST_F(ForStmtTest, BreakCondition) {
|
||||||
// Test a for loop assigning a variable in the continuing statement.
|
// Test a for loop assigning a variable in the continuing statement.
|
||||||
TEST_F(ForStmtTest, ContinuingAssignment) {
|
TEST_F(ForStmtTest, ContinuingAssignment) {
|
||||||
auto p = parser("for (;; x = 2) { }");
|
auto p = parser("for (;; x = 2) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -165,7 +165,7 @@ TEST_F(ForStmtTest, ContinuingAssignment) {
|
||||||
// Test a for loop with an increment statement as the continuing statement.
|
// Test a for loop with an increment statement as the continuing statement.
|
||||||
TEST_F(ForStmtTest, ContinuingIncrement) {
|
TEST_F(ForStmtTest, ContinuingIncrement) {
|
||||||
auto p = parser("for (;; x++) { }");
|
auto p = parser("for (;; x++) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -178,7 +178,7 @@ TEST_F(ForStmtTest, ContinuingIncrement) {
|
||||||
// Test a for loop calling a function in the continuing statement.
|
// Test a for loop calling a function in the continuing statement.
|
||||||
TEST_F(ForStmtTest, ContinuingFuncCall) {
|
TEST_F(ForStmtTest, ContinuingFuncCall) {
|
||||||
auto p = parser("for (;; a(b,c)) { }");
|
auto p = parser("for (;; a(b,c)) { }");
|
||||||
auto fl = p->for_stmt();
|
auto fl = p->for_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(fl.errored);
|
EXPECT_FALSE(fl.errored);
|
||||||
ASSERT_TRUE(fl.matched);
|
ASSERT_TRUE(fl.matched);
|
||||||
|
@ -192,7 +192,7 @@ class ForStmtErrorTest : public ParserImplTest {
|
||||||
public:
|
public:
|
||||||
void TestForWithError(std::string for_str, std::string error_str) {
|
void TestForWithError(std::string for_str, std::string error_str) {
|
||||||
auto p_for = parser(for_str);
|
auto p_for = parser(for_str);
|
||||||
auto e_for = p_for->for_stmt();
|
auto e_for = p_for->for_statement();
|
||||||
|
|
||||||
EXPECT_FALSE(e_for.matched);
|
EXPECT_FALSE(e_for.matched);
|
||||||
EXPECT_TRUE(e_for.errored);
|
EXPECT_TRUE(e_for.errored);
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt) {
|
TEST_F(ParserImplTest, IfStmt) {
|
||||||
auto p = parser("if a == 4 { a = b; c = d; }");
|
auto p = parser("if a == 4 { a = b; c = d; }");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -34,7 +34,7 @@ TEST_F(ParserImplTest, IfStmt) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_WithElse) {
|
TEST_F(ParserImplTest, IfStmt_WithElse) {
|
||||||
auto p = parser("if a == 4 { a = b; c = d; } else if(c) { d = 2; } else {}");
|
auto p = parser("if a == 4 { a = b; c = d; } else if(c) { d = 2; } else {}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -57,7 +57,7 @@ TEST_F(ParserImplTest, IfStmt_WithElse) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_WithElse_WithParens) {
|
TEST_F(ParserImplTest, IfStmt_WithElse_WithParens) {
|
||||||
auto p = parser("if(a==4) { a = b; c = d; } else if(c) { d = 2; } else {}");
|
auto p = parser("if(a==4) { a = b; c = d; } else if(c) { d = 2; } else {}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -80,7 +80,7 @@ TEST_F(ParserImplTest, IfStmt_WithElse_WithParens) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_InvalidCondition) {
|
TEST_F(ParserImplTest, IfStmt_InvalidCondition) {
|
||||||
auto p = parser("if a = 3 {}");
|
auto p = parser("if a = 3 {}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -90,7 +90,7 @@ TEST_F(ParserImplTest, IfStmt_InvalidCondition) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_MissingCondition) {
|
TEST_F(ParserImplTest, IfStmt_MissingCondition) {
|
||||||
auto p = parser("if {}");
|
auto p = parser("if {}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -100,7 +100,7 @@ TEST_F(ParserImplTest, IfStmt_MissingCondition) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_InvalidBody) {
|
TEST_F(ParserImplTest, IfStmt_InvalidBody) {
|
||||||
auto p = parser("if a { fn main() {}}");
|
auto p = parser("if a { fn main() {}}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -110,7 +110,7 @@ TEST_F(ParserImplTest, IfStmt_InvalidBody) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_MissingBody) {
|
TEST_F(ParserImplTest, IfStmt_MissingBody) {
|
||||||
auto p = parser("if a");
|
auto p = parser("if a");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -120,7 +120,7 @@ TEST_F(ParserImplTest, IfStmt_MissingBody) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_InvalidElseif) {
|
TEST_F(ParserImplTest, IfStmt_InvalidElseif) {
|
||||||
auto p = parser("if a {} else if a { fn main() -> a{}}");
|
auto p = parser("if a {} else if a { fn main() -> a{}}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -130,7 +130,7 @@ TEST_F(ParserImplTest, IfStmt_InvalidElseif) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IfStmt_InvalidElse) {
|
TEST_F(ParserImplTest, IfStmt_InvalidElse) {
|
||||||
auto p = parser("if a {} else { fn main() -> a{}}");
|
auto p = parser("if a {} else { fn main() -> a{}}");
|
||||||
auto e = p->if_stmt();
|
auto e = p->if_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IncrementDecrementStmt_Increment) {
|
TEST_F(ParserImplTest, IncrementDecrementStmt_Increment) {
|
||||||
auto p = parser("a++");
|
auto p = parser("a++");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, IncrementDecrementStmt_Increment) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IncrementDecrementStmt_Decrement) {
|
TEST_F(ParserImplTest, IncrementDecrementStmt_Decrement) {
|
||||||
auto p = parser("a--");
|
auto p = parser("a--");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -57,7 +57,7 @@ TEST_F(ParserImplTest, IncrementDecrementStmt_Decrement) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IncrementDecrementStmt_Parenthesized) {
|
TEST_F(ParserImplTest, IncrementDecrementStmt_Parenthesized) {
|
||||||
auto p = parser("(a)++");
|
auto p = parser("(a)++");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -76,7 +76,7 @@ TEST_F(ParserImplTest, IncrementDecrementStmt_Parenthesized) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IncrementDecrementStmt_ToMember) {
|
TEST_F(ParserImplTest, IncrementDecrementStmt_ToMember) {
|
||||||
auto p = parser("a.b.c[2].d++");
|
auto p = parser("a.b.c[2].d++");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -121,7 +121,7 @@ TEST_F(ParserImplTest, IncrementDecrementStmt_ToMember) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, IncrementDecrementStmt_InvalidLHS) {
|
TEST_F(ParserImplTest, IncrementDecrementStmt_InvalidLHS) {
|
||||||
auto p = parser("{}++");
|
auto p = parser("{}++");
|
||||||
auto e = p->assignment_stmt();
|
auto e = p->assignment_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) {
|
TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) {
|
||||||
auto p = parser("loop { discard; }");
|
auto p = parser("loop { discard; }");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -34,7 +34,7 @@ TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) {
|
TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) {
|
||||||
auto p = parser("loop { discard; continuing { discard; }}");
|
auto p = parser("loop { discard; continuing { discard; }}");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -49,7 +49,7 @@ TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) {
|
TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) {
|
||||||
auto p = parser("loop { }");
|
auto p = parser("loop { }");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -60,7 +60,7 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) {
|
TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) {
|
||||||
auto p = parser("loop { continuing { discard; }}");
|
auto p = parser("loop { continuing { discard; }}");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -72,7 +72,7 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_MissingBracketLeft) {
|
TEST_F(ParserImplTest, LoopStmt_MissingBracketLeft) {
|
||||||
auto p = parser("loop discard; }");
|
auto p = parser("loop discard; }");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -82,7 +82,7 @@ TEST_F(ParserImplTest, LoopStmt_MissingBracketLeft) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_MissingBracketRight) {
|
TEST_F(ParserImplTest, LoopStmt_MissingBracketRight) {
|
||||||
auto p = parser("loop { discard; ");
|
auto p = parser("loop { discard; ");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -92,7 +92,7 @@ TEST_F(ParserImplTest, LoopStmt_MissingBracketRight) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_InvalidStatements) {
|
TEST_F(ParserImplTest, LoopStmt_InvalidStatements) {
|
||||||
auto p = parser("loop { discard }");
|
auto p = parser("loop { discard }");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -102,7 +102,7 @@ TEST_F(ParserImplTest, LoopStmt_InvalidStatements) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, LoopStmt_InvalidContinuing) {
|
TEST_F(ParserImplTest, LoopStmt_InvalidContinuing) {
|
||||||
auto p = parser("loop { continuing { discard }}");
|
auto p = parser("loop { continuing { discard }}");
|
||||||
auto e = p->loop_stmt();
|
auto e = p->loop_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
|
|
@ -22,7 +22,7 @@ TEST_F(ParserImplTest, SwitchStmt_WithoutDefault) {
|
||||||
case 1: {}
|
case 1: {}
|
||||||
case 2: {}
|
case 2: {}
|
||||||
})");
|
})");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -35,7 +35,7 @@ TEST_F(ParserImplTest, SwitchStmt_WithoutDefault) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, SwitchStmt_Empty) {
|
TEST_F(ParserImplTest, SwitchStmt_Empty) {
|
||||||
auto p = parser("switch a { }");
|
auto p = parser("switch a { }");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -50,7 +50,7 @@ TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) {
|
||||||
default: {}
|
default: {}
|
||||||
case 2: {}
|
case 2: {}
|
||||||
})");
|
})");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -65,7 +65,7 @@ TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, SwitchStmt_WithParens) {
|
TEST_F(ParserImplTest, SwitchStmt_WithParens) {
|
||||||
auto p = parser("switch(a+b) { }");
|
auto p = parser("switch(a+b) { }");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -76,7 +76,7 @@ TEST_F(ParserImplTest, SwitchStmt_WithParens) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, SwitchStmt_InvalidExpression) {
|
TEST_F(ParserImplTest, SwitchStmt_InvalidExpression) {
|
||||||
auto p = parser("switch a=b {}");
|
auto p = parser("switch a=b {}");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -86,7 +86,7 @@ TEST_F(ParserImplTest, SwitchStmt_InvalidExpression) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, SwitchStmt_MissingExpression) {
|
TEST_F(ParserImplTest, SwitchStmt_MissingExpression) {
|
||||||
auto p = parser("switch {}");
|
auto p = parser("switch {}");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -96,7 +96,7 @@ TEST_F(ParserImplTest, SwitchStmt_MissingExpression) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, SwitchStmt_MissingBracketLeft) {
|
TEST_F(ParserImplTest, SwitchStmt_MissingBracketLeft) {
|
||||||
auto p = parser("switch a }");
|
auto p = parser("switch a }");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -106,7 +106,7 @@ TEST_F(ParserImplTest, SwitchStmt_MissingBracketLeft) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, SwitchStmt_MissingBracketRight) {
|
TEST_F(ParserImplTest, SwitchStmt_MissingBracketRight) {
|
||||||
auto p = parser("switch a {");
|
auto p = parser("switch a {");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -118,7 +118,7 @@ TEST_F(ParserImplTest, SwitchStmt_InvalidBody) {
|
||||||
auto p = parser(R"(switch a {
|
auto p = parser(R"(switch a {
|
||||||
case: {}
|
case: {}
|
||||||
})");
|
})");
|
||||||
auto e = p->switch_stmt();
|
auto e = p->switch_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
|
||||||
auto p = parser("var a : i32;");
|
auto p = parser("var a : i32;");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
|
||||||
auto p = parser("var a : i32 = 1;");
|
auto p = parser("var a : i32 = 1;");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -58,7 +58,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) {
|
||||||
auto p = parser("var a : i32 = if(a) {}");
|
auto p = parser("var a : i32 = if(a) {}");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -68,7 +68,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) {
|
||||||
auto p = parser("var a : array<i32> = array<i32>();");
|
auto p = parser("var a : array<i32> = array<i32>();");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -86,7 +86,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) {
|
||||||
auto p = parser("var a : array<i32>=array<i32>();");
|
auto p = parser("var a : array<i32>=array<i32>();");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -104,7 +104,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) {
|
||||||
auto p = parser("var a : vec2<i32> = vec2<i32>();");
|
auto p = parser("var a : vec2<i32> = vec2<i32>();");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -122,7 +122,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) {
|
TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) {
|
||||||
auto p = parser("var a : vec2<i32>=vec2<i32>();");
|
auto p = parser("var a : vec2<i32>=vec2<i32>();");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -140,7 +140,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_Let) {
|
TEST_F(ParserImplTest, VariableStmt_Let) {
|
||||||
auto p = parser("let a : i32 = 1");
|
auto p = parser("let a : i32 = 1");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_TRUE(e.matched);
|
EXPECT_TRUE(e.matched);
|
||||||
EXPECT_FALSE(e.errored);
|
EXPECT_FALSE(e.errored);
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
|
@ -155,7 +155,7 @@ TEST_F(ParserImplTest, VariableStmt_Let) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {
|
TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {
|
||||||
auto p = parser("let a : i32 1");
|
auto p = parser("let a : i32 1");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -165,7 +165,7 @@ TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_Let_MissingConstructor) {
|
TEST_F(ParserImplTest, VariableStmt_Let_MissingConstructor) {
|
||||||
auto p = parser("let a : i32 =");
|
auto p = parser("let a : i32 =");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
@ -175,7 +175,7 @@ TEST_F(ParserImplTest, VariableStmt_Let_MissingConstructor) {
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableStmt_Let_InvalidConstructor) {
|
TEST_F(ParserImplTest, VariableStmt_Let_InvalidConstructor) {
|
||||||
auto p = parser("let a : i32 = if (a) {}");
|
auto p = parser("let a : i32 = if (a) {}");
|
||||||
auto e = p->variable_stmt();
|
auto e = p->variable_statement();
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
|
|
|
@ -24,7 +24,7 @@ using WhileStmtTest = ParserImplTest;
|
||||||
// Test an empty while loop.
|
// Test an empty while loop.
|
||||||
TEST_F(WhileStmtTest, Empty) {
|
TEST_F(WhileStmtTest, Empty) {
|
||||||
auto p = parser("while (true) { }");
|
auto p = parser("while (true) { }");
|
||||||
auto wl = p->while_stmt();
|
auto wl = p->while_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(wl.errored);
|
EXPECT_FALSE(wl.errored);
|
||||||
ASSERT_TRUE(wl.matched);
|
ASSERT_TRUE(wl.matched);
|
||||||
|
@ -35,7 +35,7 @@ TEST_F(WhileStmtTest, Empty) {
|
||||||
// Test a while loop with non-empty body.
|
// Test a while loop with non-empty body.
|
||||||
TEST_F(WhileStmtTest, Body) {
|
TEST_F(WhileStmtTest, Body) {
|
||||||
auto p = parser("while (true) { discard; }");
|
auto p = parser("while (true) { discard; }");
|
||||||
auto wl = p->while_stmt();
|
auto wl = p->while_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(wl.errored);
|
EXPECT_FALSE(wl.errored);
|
||||||
ASSERT_TRUE(wl.matched);
|
ASSERT_TRUE(wl.matched);
|
||||||
|
@ -47,7 +47,7 @@ TEST_F(WhileStmtTest, Body) {
|
||||||
// Test a while loop with complex condition.
|
// Test a while loop with complex condition.
|
||||||
TEST_F(WhileStmtTest, ComplexCondition) {
|
TEST_F(WhileStmtTest, ComplexCondition) {
|
||||||
auto p = parser("while ((a + 1 - 2) == 3) { }");
|
auto p = parser("while ((a + 1 - 2) == 3) { }");
|
||||||
auto wl = p->while_stmt();
|
auto wl = p->while_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(wl.errored);
|
EXPECT_FALSE(wl.errored);
|
||||||
ASSERT_TRUE(wl.matched);
|
ASSERT_TRUE(wl.matched);
|
||||||
|
@ -58,7 +58,7 @@ TEST_F(WhileStmtTest, ComplexCondition) {
|
||||||
// Test a while loop with no brackets.
|
// Test a while loop with no brackets.
|
||||||
TEST_F(WhileStmtTest, NoBrackets) {
|
TEST_F(WhileStmtTest, NoBrackets) {
|
||||||
auto p = parser("while (a + 1 - 2) == 3 { }");
|
auto p = parser("while (a + 1 - 2) == 3 { }");
|
||||||
auto wl = p->while_stmt();
|
auto wl = p->while_statement();
|
||||||
EXPECT_FALSE(p->has_error()) << p->error();
|
EXPECT_FALSE(p->has_error()) << p->error();
|
||||||
EXPECT_FALSE(wl.errored);
|
EXPECT_FALSE(wl.errored);
|
||||||
ASSERT_TRUE(wl.matched);
|
ASSERT_TRUE(wl.matched);
|
||||||
|
@ -70,7 +70,7 @@ class WhileStmtErrorTest : public ParserImplTest {
|
||||||
public:
|
public:
|
||||||
void TestForWithError(std::string for_str, std::string error_str) {
|
void TestForWithError(std::string for_str, std::string error_str) {
|
||||||
auto p_for = parser(for_str);
|
auto p_for = parser(for_str);
|
||||||
auto e_for = p_for->while_stmt();
|
auto e_for = p_for->while_statement();
|
||||||
|
|
||||||
EXPECT_FALSE(e_for.matched);
|
EXPECT_FALSE(e_for.matched);
|
||||||
EXPECT_TRUE(e_for.errored);
|
EXPECT_TRUE(e_for.errored);
|
||||||
|
|
Loading…
Reference in New Issue