Skip to content

Commit

Permalink
refactor(naga): hoist Attribute's name{,_span} bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Nov 5, 2024
1 parent 1add61c commit 4b4a208
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)?;
Expand All @@ -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)),
}
}

Expand Down

0 comments on commit 4b4a208

Please sign in to comment.