diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index dc70410986..bb18f368d3 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -351,21 +351,21 @@ Token Lexer::try_punctuation() { pos_ += 1; column_ += 1; } else if (matches(pos_, "[")) { - type = Token::Type::kBraceLeft; - pos_ += 1; - column_ += 1; - } else if (matches(pos_, "]")) { - type = Token::Type::kBraceRight; - pos_ += 1; - column_ += 1; - } else if (matches(pos_, "{")) { type = Token::Type::kBracketLeft; pos_ += 1; column_ += 1; - } else if (matches(pos_, "}")) { + } else if (matches(pos_, "]")) { type = Token::Type::kBracketRight; pos_ += 1; column_ += 1; + } else if (matches(pos_, "{")) { + type = Token::Type::kBraceLeft; + pos_ += 1; + column_ += 1; + } else if (matches(pos_, "}")) { + type = Token::Type::kBraceRight; + pos_ += 1; + column_ += 1; } else if (matches(pos_, "&&")) { type = Token::Type::kAndAnd; pos_ += 2; diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc index aba0eb6d55..c59e4fbb9b 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -366,10 +366,10 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"]]", Token::Type::kAttrRight}, TokenData{"/", Token::Type::kForwardSlash}, TokenData{"!", Token::Type::kBang}, - TokenData{"[", Token::Type::kBraceLeft}, - TokenData{"]", Token::Type::kBraceRight}, - TokenData{"{", Token::Type::kBracketLeft}, - TokenData{"}", Token::Type::kBracketRight}, + TokenData{"[", Token::Type::kBracketLeft}, + TokenData{"]", Token::Type::kBracketRight}, + TokenData{"{", Token::Type::kBraceLeft}, + TokenData{"}", Token::Type::kBraceRight}, TokenData{":", Token::Type::kColon}, TokenData{",", Token::Type::kComma}, TokenData{"=", Token::Type::kEqual}, diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index be74cec65f..cf282296f9 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -987,7 +987,7 @@ std::unique_ptr ParserImpl::struct_decl() { } t = peek(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing { for struct declaration"); return nullptr; } @@ -1042,13 +1042,13 @@ ast::StructDecoration ParserImpl::struct_decoration() { // : BRACKET_LEFT struct_member* BRACKET_RIGHT ast::StructMemberList ParserImpl::struct_body_decl() { auto t = peek(); - if (!t.IsBracketLeft()) + if (!t.IsBraceLeft()) return {}; next(); // Consume the peek t = peek(); - if (t.IsBracketRight()) + if (t.IsBraceRight()) return {}; ast::StructMemberList members; @@ -1064,12 +1064,12 @@ ast::StructMemberList ParserImpl::struct_body_decl() { members.push_back(std::move(mem)); t = peek(); - if (t.IsBracketRight() || t.IsEof()) + if (t.IsBraceRight() || t.IsEof()) break; } t = next(); - if (!t.IsBracketRight()) { + if (!t.IsBraceRight()) { set_error(t, "missing } for struct declaration"); return {}; } @@ -1376,7 +1376,7 @@ ast::PipelineStage ParserImpl::pipeline_stage() { // : BRACKET_LEFT statements BRACKET_RIGHT ast::StatementList ParserImpl::body_stmt() { auto t = peek(); - if (!t.IsBracketLeft()) + if (!t.IsBraceLeft()) return {}; next(); // Consume the peek @@ -1386,7 +1386,7 @@ ast::StatementList ParserImpl::body_stmt() { return {}; t = next(); - if (!t.IsBracketRight()) { + if (!t.IsBraceRight()) { set_error(t, "missing }"); return {}; } @@ -1733,7 +1733,7 @@ std::unique_ptr ParserImpl::if_stmt() { } t = peek(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing {"); return nullptr; } @@ -1781,7 +1781,7 @@ ast::ElseStatementList ParserImpl::elseif_stmt() { } t = peek(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing {"); return {}; } @@ -1812,7 +1812,7 @@ std::unique_ptr ParserImpl::else_stmt() { next(); // Consume the peek t = peek(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing {"); return nullptr; } @@ -1869,7 +1869,7 @@ std::unique_ptr ParserImpl::switch_stmt() { } t = next(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing { for switch statement"); return nullptr; } @@ -1886,7 +1886,7 @@ std::unique_ptr ParserImpl::switch_stmt() { } t = next(); - if (!t.IsBracketRight()) { + if (!t.IsBraceRight()) { set_error(t, "missing } for switch statement"); return nullptr; } @@ -1925,7 +1925,7 @@ std::unique_ptr ParserImpl::switch_body() { } t = next(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing { for case statement"); return nullptr; } @@ -1937,7 +1937,7 @@ std::unique_ptr ParserImpl::switch_body() { stmt->set_body(std::move(body)); t = next(); - if (!t.IsBracketRight()) { + if (!t.IsBraceRight()) { set_error(t, "missing } for case statement"); return nullptr; } @@ -1990,7 +1990,7 @@ std::unique_ptr ParserImpl::loop_stmt() { next(); // Consume the peek t = next(); - if (!t.IsBracketLeft()) { + if (!t.IsBraceLeft()) { set_error(t, "missing { for loop"); return nullptr; } @@ -2004,7 +2004,7 @@ std::unique_ptr ParserImpl::loop_stmt() { return nullptr; t = next(); - if (!t.IsBracketRight()) { + if (!t.IsBraceRight()) { set_error(t, "missing } for loop"); return nullptr; } @@ -2298,7 +2298,7 @@ std::unique_ptr ParserImpl::postfix_expr( auto t = peek(); auto source = t.source(); - if (t.IsBraceLeft()) { + if (t.IsBracketLeft()) { next(); // Consume the peek auto param = logical_or_expression(); @@ -2310,7 +2310,7 @@ std::unique_ptr ParserImpl::postfix_expr( } t = next(); - if (!t.IsBraceRight()) { + if (!t.IsBracketRight()) { set_error(t, "missing ] for array accessor"); return nullptr; } diff --git a/src/reader/wgsl/token.cc b/src/reader/wgsl/token.cc index 16b85e74d4..1481018e9d 100644 --- a/src/reader/wgsl/token.cc +++ b/src/reader/wgsl/token.cc @@ -54,13 +54,13 @@ std::string Token::TypeToName(Type type) { return "/"; case Token::Type::kBang: return "!"; - case Token::Type::kBraceLeft: - return "["; - case Token::Type::kBraceRight: - return "]"; case Token::Type::kBracketLeft: - return "{"; + return "["; case Token::Type::kBracketRight: + return "]"; + case Token::Type::kBraceLeft: + return "{"; + case Token::Type::kBraceRight: return "}"; case Token::Type::kColon: return ":"; diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h index 3784986c2f..b2cf05dc47 100644 --- a/src/reader/wgsl/token.h +++ b/src/reader/wgsl/token.h @@ -66,13 +66,13 @@ class Token { /// A '!' kBang, /// A '[' - kBraceLeft, - /// A ']' - kBraceRight, - /// A '{' kBracketLeft, - /// A '}' + /// A ']' kBracketRight, + /// A '{' + kBraceLeft, + /// A '}' + kBraceRight, /// A ':' kColon, /// A ',' @@ -375,13 +375,13 @@ class Token { /// @returns true if token is a '!' bool IsBang() const { return type_ == Type::kBang; } /// @returns true if token is a '[' - bool IsBraceLeft() const { return type_ == Type::kBraceLeft; } - /// @returns true if token is a ']' - bool IsBraceRight() const { return type_ == Type::kBraceRight; } - /// @returns true if token is a '{' bool IsBracketLeft() const { return type_ == Type::kBracketLeft; } - /// @returns true if token is a '}' + /// @returns true if token is a ']' bool IsBracketRight() const { return type_ == Type::kBracketRight; } + /// @returns true if token is a '{' + bool IsBraceLeft() const { return type_ == Type::kBraceLeft; } + /// @returns true if token is a '}' + bool IsBraceRight() const { return type_ == Type::kBraceRight; } /// @returns true if token is a ':' bool IsColon() const { return type_ == Type::kColon; } /// @returns true if token is a ','