[wgsl] Make colon in case optional (#1801)

This commit is contained in:
Igor Shaposhnik
2022-03-30 21:32:01 +03:00
committed by GitHub
parent 6bbba0d0d5
commit 43cd0ecedd
2 changed files with 20 additions and 2 deletions

View File

@@ -3722,7 +3722,7 @@ impl Parser {
break value;
}
} else {
lexer.expect(Token::Separator(':'))?;
lexer.skip(Token::Separator(':'));
break value;
}
cases.push(crate::SwitchCase {
@@ -3742,7 +3742,7 @@ impl Parser {
});
}
(Token::Word("default"), _) => {
lexer.expect(Token::Separator(':'))?;
lexer.skip(Token::Separator(':'));
let (fall_through, body) =
self.parse_switch_case_body(lexer, context.reborrow())?;
cases.push(crate::SwitchCase {

View File

@@ -329,6 +329,24 @@ fn parse_switch() {
.unwrap();
}
#[test]
fn parse_switch_optional_colon_in_case() {
parse_str(
"
fn main() {
var pos: f32;
switch (3) {
case 0, 1 { pos = 0.0; }
case 2 { pos = 1.0; fallthrough; }
case 3 {}
default { pos = 3.0; }
}
}
",
)
.unwrap();
}
#[test]
fn parse_parentheses_switch() {
parse_str(