Skip to content

Commit

Permalink
feat(wgsl-in): add unimpl. diag. for compound stmt. @diagnostic(…)s
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Nov 13, 2024
1 parent 9141923 commit ca22458
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ pub enum ExpectedToken<'a> {
Variable,
/// Access of a function
Function,
/// The `diagnostic` identifier of the `@diagnostic(…)` attribute.
DiagnosticAttribute,
}

#[derive(Clone, Copy, Debug, Error, PartialEq)]
Expand Down Expand Up @@ -388,6 +390,9 @@ impl<'a> Error<'a> {
ExpectedToken::AfterIdentListComma => {
"next argument or end of list (';')".to_string()
}
ExpectedToken::DiagnosticAttribute => {
"the 'diagnostic' attribute identifier".to_string()
}
};
ParseError {
message: format!(
Expand Down
26 changes: 26 additions & 0 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,32 @@ impl Parser {

ctx.local_table.push_scope();

let mut diagnostic_filters = DiagnosticFilterMap::new();

self.push_rule_span(Rule::Attribute, lexer);
while lexer.skip(Token::Attribute) {
let (name, name_span) = lexer.next_ident_with_span()?;
if let Some(DirectiveKind::Diagnostic) = DirectiveKind::from_ident(name) {
if let Some(filter) = self.diagnostic_filter(lexer)? {
let span = self.peek_rule_span(lexer);
diagnostic_filters.add(filter, span)?;
}
} else {
return Err(Error::Unexpected(
name_span,
ExpectedToken::DiagnosticAttribute,
));
}
}
self.pop_rule_span(lexer);

if !diagnostic_filters.is_empty() {
return Err(Error::DiagnosticAttributeNotYetImplementedAtParseSite {
site_name_plural: "compound statements",
spans: diagnostic_filters.spans().collect(),
});
}

let brace_span = lexer.expect_span(Token::Paren('{'))?;
let brace_nesting_level = Self::increase_brace_nesting(brace_nesting_level, brace_span)?;
let mut block = ast::Block::default();
Expand Down

0 comments on commit ca22458

Please sign in to comment.