Skip to content

Commit 1c5f717

Browse files
committed
Add helper function is_start_of_compound_statement
1 parent 0066809 commit 1c5f717

File tree

1 file changed

+9
-8
lines changed
  • naga/src/front/wgsl/parse

1 file changed

+9
-8
lines changed

naga/src/front/wgsl/parse/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ impl Parser {
21212121
let _ = lexer.next();
21222122
this.pop_rule_span(lexer);
21232123
}
2124-
(Token::Paren('{') | Token::Attribute, _) => {
2124+
(token, _) if is_start_of_compound_statement(token) => {
21252125
let (inner, span) = this.block(lexer, ctx, brace_nesting_level)?;
21262126
block.stmts.push(ast::Statement {
21272127
kind: ast::StatementKind::Block(inner),
@@ -2288,13 +2288,10 @@ impl Parser {
22882288
let value = this.switch_value(lexer, ctx)?;
22892289
if lexer.skip(Token::Separator(',')) {
22902290
// list of values ends with ':' or a compound statement
2291-
// indicated by an attribute or '{'
2292-
if matches!(
2293-
lexer.peek().0,
2294-
Token::Separator(':')
2295-
| Token::Attribute
2296-
| Token::Paren('{')
2297-
) {
2291+
let next_token = lexer.peek().0;
2292+
if next_token == Token::Separator(':')
2293+
|| is_start_of_compound_statement(next_token)
2294+
{
22982295
break value;
22992296
}
23002297
} else {
@@ -3252,3 +3249,7 @@ impl Parser {
32523249
})
32533250
}
32543251
}
3252+
3253+
const fn is_start_of_compound_statement<'a>(token: Token<'a>) -> bool {
3254+
matches!(token, Token::Attribute | Token::Paren('{'))
3255+
}

0 commit comments

Comments
 (0)