Skip to content

Commit

Permalink
[wgsl] Make colon in case optional (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon-F authored Mar 30, 2022
1 parent 6bbba0d commit 43cd0ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3722,7 +3722,7 @@ impl Parser {
break value;
}
} else {
lexer.expect(Token::Separator(':'))?;
lexer.skip(Token::Separator(':'));
break value;
}
cases.push(crate::SwitchCase {
Expand All @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions src/front/wgsl/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 43cd0ec

Please sign in to comment.