mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
wgsl-reader: reject identifiers starting with underscrore
Update one test to avoid this error. Fixed: tint:1179 Change-Id: Id41b0eb0f404648de4e86a835fe43f1729cb4696 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/64464 Auto-Submit: David Neto <dneto@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: David Neto <dneto@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
@@ -119,15 +119,15 @@ bool Lexer::is_eof() const {
|
||||
}
|
||||
|
||||
bool Lexer::is_alpha(char ch) const {
|
||||
return std::isalpha(ch) || ch == '_';
|
||||
return std::isalpha(ch);
|
||||
}
|
||||
|
||||
bool Lexer::is_digit(char ch) const {
|
||||
return std::isdigit(ch);
|
||||
}
|
||||
|
||||
bool Lexer::is_alphanum(char ch) const {
|
||||
return is_alpha(ch) || is_digit(ch);
|
||||
bool Lexer::is_alphanum_underscore(char ch) const {
|
||||
return is_alpha(ch) || is_digit(ch) || ch == '_';
|
||||
}
|
||||
|
||||
bool Lexer::is_hex(char ch) const {
|
||||
@@ -660,7 +660,7 @@ Token Lexer::try_integer() {
|
||||
}
|
||||
|
||||
Token Lexer::try_ident() {
|
||||
// Must begin with an a-zA-Z_
|
||||
// Must begin with an a-zA-Z
|
||||
if (!is_alpha(content_->data[pos_])) {
|
||||
return {};
|
||||
}
|
||||
@@ -668,7 +668,7 @@ Token Lexer::try_ident() {
|
||||
auto source = begin_source();
|
||||
|
||||
auto s = pos_;
|
||||
while (!is_eof() && is_alphanum(content_->data[pos_])) {
|
||||
while (!is_eof() && is_alphanum_underscore(content_->data[pos_])) {
|
||||
pos_++;
|
||||
location_.column++;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,19 @@ class Lexer {
|
||||
void end_source(Source&) const;
|
||||
|
||||
bool is_eof() const;
|
||||
/// @param ch a character
|
||||
/// @returns true if 'ch' is an alphabetic character
|
||||
bool is_alpha(char ch) const;
|
||||
/// @param ch a character
|
||||
/// @returns true if 'ch' is a decimal digit
|
||||
bool is_digit(char ch) const;
|
||||
/// @param ch a character
|
||||
/// @returns true if 'ch' is a hexadecimal digit
|
||||
bool is_hex(char ch) const;
|
||||
bool is_alphanum(char ch) const;
|
||||
/// @param ch a character
|
||||
/// @returns true if 'ch' is a digit, an alphabetic character,
|
||||
/// or an underscore.
|
||||
bool is_alphanum_underscore(char ch) const;
|
||||
bool matches(size_t pos, const std::string& substr);
|
||||
|
||||
/// The source file path
|
||||
|
||||
@@ -186,10 +186,26 @@ TEST_P(IdentifierTest, Parse) {
|
||||
EXPECT_EQ(t.source().range.end.column, 1u + strlen(GetParam()));
|
||||
EXPECT_EQ(t.to_str(), GetParam());
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
LexerTest,
|
||||
IdentifierTest,
|
||||
testing::Values("test01", "_test_", "test_", "_test", "_01", "_test01"));
|
||||
INSTANTIATE_TEST_SUITE_P(LexerTest,
|
||||
IdentifierTest,
|
||||
testing::Values("a",
|
||||
"test",
|
||||
"test01",
|
||||
"test_",
|
||||
"test_01",
|
||||
"ALLCAPS",
|
||||
"MiXeD_CaSe",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"alldigits_0123456789"));
|
||||
|
||||
TEST_F(LexerTest, IdentifierTest_DoesNotStartWithUnderscore) {
|
||||
Source::FileContent content("_test");
|
||||
Lexer l("test.wgsl", &content);
|
||||
|
||||
auto t = l.next();
|
||||
EXPECT_FALSE(t.IsIdentifier());
|
||||
}
|
||||
|
||||
TEST_F(LexerTest, IdentifierTest_DoesNotStartWithNumber) {
|
||||
Source::FileContent content("01test");
|
||||
|
||||
Reference in New Issue
Block a user