diff --git a/src/tint/reader/wgsl/lexer.cc b/src/tint/reader/wgsl/lexer.cc index 716075eacc..a3eaa6d1e3 100644 --- a/src/tint/reader/wgsl/lexer.cc +++ b/src/tint/reader/wgsl/lexer.cc @@ -1088,6 +1088,9 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) { if (str == "case") { return {Token::Type::kCase, source, "case"}; } + if (str == "const") { + return {Token::Type::kConst, source, "const"}; + } if (str == "continue") { return {Token::Type::kContinue, source, "continue"}; } diff --git a/src/tint/reader/wgsl/lexer_test.cc b/src/tint/reader/wgsl/lexer_test.cc index ab4ec7ea27..712474f0d4 100644 --- a/src/tint/reader/wgsl/lexer_test.cc +++ b/src/tint/reader/wgsl/lexer_test.cc @@ -930,6 +930,7 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"bool", Token::Type::kBool}, TokenData{"break", Token::Type::kBreak}, TokenData{"case", Token::Type::kCase}, + TokenData{"const", Token::Type::kConst}, TokenData{"continue", Token::Type::kContinue}, TokenData{"continuing", Token::Type::kContinuing}, TokenData{"default", Token::Type::kDefault}, diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 854b276bb2..3f1fad4371 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -124,10 +124,10 @@ const char kWorkgroupSizeAttribute[] = "workgroup_size"; // https://gpuweb.github.io/gpuweb/wgsl.html#reserved-keywords bool is_reserved(Token t) { - return t == "asm" || t == "bf16" || t == "const" || t == "do" || t == "enum" || t == "f64" || - t == "handle" || t == "i8" || t == "i16" || t == "i64" || t == "mat" || - t == "premerge" || t == "regardless" || t == "typedef" || t == "u8" || t == "u16" || - t == "u64" || t == "unless" || t == "using" || t == "vec" || t == "void" || t == "while"; + return t == "asm" || t == "bf16" || t == "do" || t == "enum" || t == "f64" || t == "handle" || + t == "i8" || t == "i16" || t == "i64" || t == "mat" || t == "premerge" || + t == "regardless" || t == "typedef" || t == "u8" || t == "u16" || t == "u64" || + t == "unless" || t == "using" || t == "vec" || t == "void" || t == "while"; } /// Enter-exit counters for block token types. diff --git a/src/tint/reader/wgsl/parser_impl_reserved_keyword_test.cc b/src/tint/reader/wgsl/parser_impl_reserved_keyword_test.cc index 8da2771d55..8f2d470090 100644 --- a/src/tint/reader/wgsl/parser_impl_reserved_keyword_test.cc +++ b/src/tint/reader/wgsl/parser_impl_reserved_keyword_test.cc @@ -85,7 +85,6 @@ INSTANTIATE_TEST_SUITE_P(ParserImplReservedKeywordTest, ParserImplReservedKeywordTest, testing::Values("asm", "bf16", - "const", "do", "enum", "f64", diff --git a/src/tint/reader/wgsl/token.cc b/src/tint/reader/wgsl/token.cc index aec1c9add8..c6a06c9c13 100644 --- a/src/tint/reader/wgsl/token.cc +++ b/src/tint/reader/wgsl/token.cc @@ -141,6 +141,8 @@ std::string_view Token::TypeToName(Type type) { return "break"; case Token::Type::kCase: return "case"; + case Token::Type::kConst: + return "const"; case Token::Type::kContinue: return "continue"; case Token::Type::kContinuing: diff --git a/src/tint/reader/wgsl/token.h b/src/tint/reader/wgsl/token.h index 2fcf7425e2..e291f8e9a4 100644 --- a/src/tint/reader/wgsl/token.h +++ b/src/tint/reader/wgsl/token.h @@ -151,6 +151,8 @@ class Token { kBreak, /// A 'case' kCase, + /// A 'const' + kConst, /// A 'continue' kContinue, /// A 'continuing'