refactor(naga): hoist Attribute's name{,_span} bindings

This commit is contained in:
Erich Gubler 2024-11-04 16:56:26 -05:00
parent e6f52bf46d
commit 82e7aa3d5b

View File

@ -2327,33 +2327,34 @@ impl Parser {
self.push_rule_span(Rule::Attribute, lexer); self.push_rule_span(Rule::Attribute, lexer);
while lexer.skip(Token::Attribute) { while lexer.skip(Token::Attribute) {
match lexer.next_ident_with_span()? { let (name, name_span) = lexer.next_ident_with_span()?;
("binding", name_span) => { match name {
"binding" => {
lexer.expect(Token::Paren('('))?; lexer.expect(Token::Paren('('))?;
bind_index.set(self.general_expression(lexer, &mut ctx)?, name_span)?; bind_index.set(self.general_expression(lexer, &mut ctx)?, name_span)?;
lexer.expect(Token::Paren(')'))?; lexer.expect(Token::Paren(')'))?;
} }
("group", name_span) => { "group" => {
lexer.expect(Token::Paren('('))?; lexer.expect(Token::Paren('('))?;
bind_group.set(self.general_expression(lexer, &mut ctx)?, name_span)?; bind_group.set(self.general_expression(lexer, &mut ctx)?, name_span)?;
lexer.expect(Token::Paren(')'))?; lexer.expect(Token::Paren(')'))?;
} }
("id", name_span) => { "id" => {
lexer.expect(Token::Paren('('))?; lexer.expect(Token::Paren('('))?;
id.set(self.general_expression(lexer, &mut ctx)?, name_span)?; id.set(self.general_expression(lexer, &mut ctx)?, name_span)?;
lexer.expect(Token::Paren(')'))?; lexer.expect(Token::Paren(')'))?;
} }
("vertex", name_span) => { "vertex" => {
stage.set(ShaderStage::Vertex, name_span)?; stage.set(ShaderStage::Vertex, name_span)?;
} }
("fragment", name_span) => { "fragment" => {
stage.set(ShaderStage::Fragment, name_span)?; stage.set(ShaderStage::Fragment, name_span)?;
} }
("compute", name_span) => { "compute" => {
stage.set(ShaderStage::Compute, name_span)?; stage.set(ShaderStage::Compute, name_span)?;
compute_span = name_span; compute_span = name_span;
} }
("workgroup_size", name_span) => { "workgroup_size" => {
lexer.expect(Token::Paren('('))?; lexer.expect(Token::Paren('('))?;
let mut new_workgroup_size = [None; 3]; let mut new_workgroup_size = [None; 3];
for (i, size) in new_workgroup_size.iter_mut().enumerate() { for (i, size) in new_workgroup_size.iter_mut().enumerate() {
@ -2371,7 +2372,7 @@ impl Parser {
} }
workgroup_size.set(new_workgroup_size, name_span)?; workgroup_size.set(new_workgroup_size, name_span)?;
} }
("early_depth_test", name_span) => { "early_depth_test" => {
let conservative = if lexer.skip(Token::Paren('(')) { let conservative = if lexer.skip(Token::Paren('(')) {
let (ident, ident_span) = lexer.next_ident_with_span()?; let (ident, ident_span) = lexer.next_ident_with_span()?;
let value = conv::map_conservative_depth(ident, ident_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)?; early_depth_test.set(crate::EarlyDepthTest { conservative }, name_span)?;
} }
(_, word_span) => return Err(Error::UnknownAttribute(word_span)), _ => return Err(Error::UnknownAttribute(name_span)),
} }
} }