mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-08 22:26:06 +00:00
reader/spirv: Allow leading underscore in identifiers
Bug: tint:1292 Change-Id: I738c981f503545075115101a3ead30941a19d95a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/72320 Reviewed-by: David Neto <dneto@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
01e4b54497
commit
4e6e113816
@ -750,7 +750,14 @@ bool ParserImpl::IsValidIdentifier(const std::string& str) {
|
||||
return false;
|
||||
}
|
||||
std::locale c_locale("C");
|
||||
if (!std::isalpha(str[0], c_locale)) {
|
||||
if (str[0] == '_') {
|
||||
if (str.length() == 1u || str[1] == '_') {
|
||||
// https://www.w3.org/TR/WGSL/#identifiers
|
||||
// must not be '_' (a single underscore)
|
||||
// must not start with two underscores
|
||||
return false;
|
||||
}
|
||||
} else if (!std::isalpha(str[0], c_locale)) {
|
||||
return false;
|
||||
}
|
||||
for (const char& ch : str) {
|
||||
|
@ -202,8 +202,9 @@ TEST_F(SpvParserTest, Impl_Source_InvalidId) {
|
||||
|
||||
TEST_F(SpvParserTest, Impl_IsValidIdentifier) {
|
||||
EXPECT_FALSE(ParserImpl::IsValidIdentifier("")); // empty
|
||||
EXPECT_FALSE(
|
||||
ParserImpl::IsValidIdentifier("_")); // leading underscore, but ok later
|
||||
EXPECT_FALSE(ParserImpl::IsValidIdentifier("_"));
|
||||
EXPECT_FALSE(ParserImpl::IsValidIdentifier("__"));
|
||||
EXPECT_TRUE(ParserImpl::IsValidIdentifier("_x"));
|
||||
EXPECT_FALSE(
|
||||
ParserImpl::IsValidIdentifier("9")); // leading digit, but ok later
|
||||
EXPECT_FALSE(ParserImpl::IsValidIdentifier(" ")); // leading space
|
||||
|
Loading…
x
Reference in New Issue
Block a user