From 9bbf8252a93d114aea038297d1c81f5b29949fcc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 6 Jan 2021 19:54:01 +0000 Subject: [PATCH] wgsl: Treat // as comment Also support # as comments for now while we migrate. See: https: //github.com/gpuweb/gpuweb/issues/1262 https: //github.com/gpuweb/gpuweb/pull/1326 Change-Id: I3547f575c35f4fd46b95f0f2d8b79f4015364c83 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36680 Commit-Queue: Ben Clayton Commit-Queue: dan sinclair Reviewed-by: dan sinclair Auto-Submit: Ben Clayton --- src/reader/wgsl/lexer.cc | 3 ++- src/reader/wgsl/lexer_test.cc | 6 +++--- src/reader/wgsl/parser_impl_for_stmt_test.cc | 2 +- src/reader/wgsl/parser_impl_test.cc | 2 +- src/reader/wgsl/parser_test.cc | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index af8ab7ec34..9b8f5840bf 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -143,7 +143,8 @@ void Lexer::skip_whitespace() { } void Lexer::skip_comments() { - if (!matches(pos_, "#")) { + // TODO(bclayton): Remove support for # comments + if (!matches(pos_, "#") && !matches(pos_, "//")) { return; } diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc index 3a9d7bbece..86689605b1 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -49,9 +49,9 @@ TEST_F(LexerTest, Skips_Whitespace) { } TEST_F(LexerTest, Skips_Comments) { - Source::File file("test.wgsl", R"(#starts with comment -ident1 #ends with comment -# blank line + Source::File file("test.wgsl", R"(//starts with comment +ident1 //ends with comment +// blank line ident2)"); Lexer l(&file); diff --git a/src/reader/wgsl/parser_impl_for_stmt_test.cc b/src/reader/wgsl/parser_impl_for_stmt_test.cc index b112779509..42af07d128 100644 --- a/src/reader/wgsl/parser_impl_for_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_for_stmt_test.cc @@ -135,7 +135,7 @@ TEST_F(ForStmtTest, All) { })"; std::string loop_str = - R"({ # Introduce new scope for loop variable i + R"({ // Introduce new scope for loop variable i var i : i32 = 0; loop { if (!(i < 4)) { diff --git a/src/reader/wgsl/parser_impl_test.cc b/src/reader/wgsl/parser_impl_test.cc index 54dde10d57..95d28cfaae 100644 --- a/src/reader/wgsl/parser_impl_test.cc +++ b/src/reader/wgsl/parser_impl_test.cc @@ -46,7 +46,7 @@ fn main() -> void { TEST_F(ParserImplTest, HandlesError) { auto p = parser(R"( -fn main() -> { # missing return type +fn main() -> { // missing return type return; })"); diff --git a/src/reader/wgsl/parser_test.cc b/src/reader/wgsl/parser_test.cc index 0ee28ab2a0..1bb967e434 100644 --- a/src/reader/wgsl/parser_test.cc +++ b/src/reader/wgsl/parser_test.cc @@ -48,7 +48,7 @@ fn main() -> void { TEST_F(ParserTest, HandlesError) { Source::File file("test.wgsl", R"( -fn main() -> { # missing return type +fn main() -> { // missing return type return; })"); Parser p(&file);