diff --git a/naga/src/front/wgsl/error.rs b/naga/src/front/wgsl/error.rs index 64fdc3de9..44b370963 100644 --- a/naga/src/front/wgsl/error.rs +++ b/naga/src/front/wgsl/error.rs @@ -112,6 +112,8 @@ impl std::error::Error for ParseError { pub enum ExpectedToken<'a> { Token(Token<'a>), Identifier, + AfterIdentListComma, + AfterIdentListArg, /// Expected: constant, parenthesized expression, identifier PrimaryExpression, /// Expected: assignment, increment/decrement expression @@ -345,6 +347,12 @@ impl<'a> Error<'a> { ExpectedToken::Type => "type".to_string(), ExpectedToken::Variable => "variable access".to_string(), ExpectedToken::Function => "function name".to_string(), + ExpectedToken::AfterIdentListArg => { + "next argument, trailing comma, or end of list (',' or ';')".to_string() + } + ExpectedToken::AfterIdentListComma => { + "next argument or end of list (';')".to_string() + } }; ParseError { message: format!( diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index e7097345b..5c768fe70 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -2258,6 +2258,36 @@ impl Parser { Ok(fun) } + #[allow(unused)] + fn directive_ident_list<'a>( + &self, + lexer: &mut Lexer<'a>, + handler: impl FnMut(&'a str, Span) -> Result<(), Error<'a>>, + ) -> Result<(), Error<'a>> { + let mut handler = handler; + 'next_arg: loop { + let (ident, span) = lexer.next_ident_with_span()?; + handler(ident, span)?; + + let expected_token = match lexer.peek().0 { + Token::Separator(',') => { + let _ = lexer.next(); + if matches!(lexer.peek().0, Token::Word(..)) { + continue 'next_arg; + } + ExpectedToken::AfterIdentListComma + } + _ => ExpectedToken::AfterIdentListArg, + }; + + if !matches!(lexer.next().0, Token::Separator(';')) { + return Err(Error::Unexpected(span, expected_token)); + } + + break Ok(()); + } + } + fn global_decl<'a>( &mut self, lexer: &mut Lexer<'a>,