From 82e7aa3d5b8181943956f26a371282c9f2c6a302 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 4 Nov 2024 16:56:26 -0500 Subject: [PATCH] refactor(naga): hoist `Attribute`'s `name{,_span}` bindings --- naga/src/front/wgsl/parse/mod.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index eb69c5fe4..72f32f19a 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -2327,33 +2327,34 @@ impl Parser { self.push_rule_span(Rule::Attribute, lexer); while lexer.skip(Token::Attribute) { - match lexer.next_ident_with_span()? { - ("binding", name_span) => { + let (name, name_span) = lexer.next_ident_with_span()?; + match name { + "binding" => { lexer.expect(Token::Paren('('))?; bind_index.set(self.general_expression(lexer, &mut ctx)?, name_span)?; lexer.expect(Token::Paren(')'))?; } - ("group", name_span) => { + "group" => { lexer.expect(Token::Paren('('))?; bind_group.set(self.general_expression(lexer, &mut ctx)?, name_span)?; lexer.expect(Token::Paren(')'))?; } - ("id", name_span) => { + "id" => { lexer.expect(Token::Paren('('))?; id.set(self.general_expression(lexer, &mut ctx)?, name_span)?; lexer.expect(Token::Paren(')'))?; } - ("vertex", name_span) => { + "vertex" => { stage.set(ShaderStage::Vertex, name_span)?; } - ("fragment", name_span) => { + "fragment" => { stage.set(ShaderStage::Fragment, name_span)?; } - ("compute", name_span) => { + "compute" => { stage.set(ShaderStage::Compute, name_span)?; compute_span = name_span; } - ("workgroup_size", name_span) => { + "workgroup_size" => { lexer.expect(Token::Paren('('))?; let mut new_workgroup_size = [None; 3]; for (i, size) in new_workgroup_size.iter_mut().enumerate() { @@ -2371,7 +2372,7 @@ impl Parser { } workgroup_size.set(new_workgroup_size, name_span)?; } - ("early_depth_test", name_span) => { + "early_depth_test" => { let conservative = if lexer.skip(Token::Paren('(')) { let (ident, ident_span) = lexer.next_ident_with_span()?; let value = conv::map_conservative_depth(ident, ident_span)?; @@ -2382,7 +2383,7 @@ impl Parser { }; early_depth_test.set(crate::EarlyDepthTest { conservative }, name_span)?; } - (_, word_span) => return Err(Error::UnknownAttribute(word_span)), + _ => return Err(Error::UnknownAttribute(name_span)), } }