tint/reader/wgsl: Lex 'const'

The parser doesn't consume this yet.

Bug: tint:1580
Change-Id: I3e78a7fdd1bd6b2a4fb4b52379a8ccc9a05869a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94325
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2022-06-21 18:38:23 +00:00 committed by Dawn LUCI CQ
parent 194c1776d3
commit e021566617
6 changed files with 12 additions and 5 deletions

View File

@ -1088,6 +1088,9 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
if (str == "case") { if (str == "case") {
return {Token::Type::kCase, source, "case"}; return {Token::Type::kCase, source, "case"};
} }
if (str == "const") {
return {Token::Type::kConst, source, "const"};
}
if (str == "continue") { if (str == "continue") {
return {Token::Type::kContinue, source, "continue"}; return {Token::Type::kContinue, source, "continue"};
} }

View File

@ -930,6 +930,7 @@ INSTANTIATE_TEST_SUITE_P(
TokenData{"bool", Token::Type::kBool}, TokenData{"bool", Token::Type::kBool},
TokenData{"break", Token::Type::kBreak}, TokenData{"break", Token::Type::kBreak},
TokenData{"case", Token::Type::kCase}, TokenData{"case", Token::Type::kCase},
TokenData{"const", Token::Type::kConst},
TokenData{"continue", Token::Type::kContinue}, TokenData{"continue", Token::Type::kContinue},
TokenData{"continuing", Token::Type::kContinuing}, TokenData{"continuing", Token::Type::kContinuing},
TokenData{"default", Token::Type::kDefault}, TokenData{"default", Token::Type::kDefault},

View File

@ -124,10 +124,10 @@ const char kWorkgroupSizeAttribute[] = "workgroup_size";
// https://gpuweb.github.io/gpuweb/wgsl.html#reserved-keywords // https://gpuweb.github.io/gpuweb/wgsl.html#reserved-keywords
bool is_reserved(Token t) { bool is_reserved(Token t) {
return t == "asm" || t == "bf16" || t == "const" || t == "do" || t == "enum" || t == "f64" || return t == "asm" || t == "bf16" || t == "do" || t == "enum" || t == "f64" || t == "handle" ||
t == "handle" || t == "i8" || t == "i16" || t == "i64" || t == "mat" || t == "i8" || t == "i16" || t == "i64" || t == "mat" || t == "premerge" ||
t == "premerge" || t == "regardless" || t == "typedef" || t == "u8" || t == "u16" || t == "regardless" || t == "typedef" || t == "u8" || t == "u16" || t == "u64" ||
t == "u64" || t == "unless" || t == "using" || t == "vec" || t == "void" || t == "while"; t == "unless" || t == "using" || t == "vec" || t == "void" || t == "while";
} }
/// Enter-exit counters for block token types. /// Enter-exit counters for block token types.

View File

@ -85,7 +85,6 @@ INSTANTIATE_TEST_SUITE_P(ParserImplReservedKeywordTest,
ParserImplReservedKeywordTest, ParserImplReservedKeywordTest,
testing::Values("asm", testing::Values("asm",
"bf16", "bf16",
"const",
"do", "do",
"enum", "enum",
"f64", "f64",

View File

@ -141,6 +141,8 @@ std::string_view Token::TypeToName(Type type) {
return "break"; return "break";
case Token::Type::kCase: case Token::Type::kCase:
return "case"; return "case";
case Token::Type::kConst:
return "const";
case Token::Type::kContinue: case Token::Type::kContinue:
return "continue"; return "continue";
case Token::Type::kContinuing: case Token::Type::kContinuing:

View File

@ -151,6 +151,8 @@ class Token {
kBreak, kBreak,
/// A 'case' /// A 'case'
kCase, kCase,
/// A 'const'
kConst,
/// A 'continue' /// A 'continue'
kContinue, kContinue,
/// A 'continuing' /// A 'continuing'