mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
refactor: add Parser::directive_ident_list
helper
This commit is contained in:
parent
7aa00a07e1
commit
54861b712c
@ -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!(
|
||||
|
@ -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>,
|
||||
|
Loading…
Reference in New Issue
Block a user