fix(parser/unchecked/attributes): Correctly enforce an identifier in `derive`

The ebnf grammar specifies an identifier (namely “Error” in the
`derive` attribute.), while the parser expected a string literal there.
This commit is contained in:
Benedikt Peetz 2024-05-19 13:55:36 +02:00
parent 9953b50846
commit 4f846058ba
Signed by: bpeetz
GPG Key ID: B6139BCB07CE946D
1 changed files with 15 additions and 3 deletions

View File

@ -193,14 +193,26 @@ impl Parser {
let attribute = match keyword {
AttributeKeyword::derive => {
let string_literal = self.parse_bracket_string_literal()?;
match string_literal.content.as_str() {
self.expect(token![CurvedBracketOpen])?;
let string_literal_token = self.expect(token![Identifier])?;
let string_literal =
if let TokenKind::Identifier(ident) = string_literal_token.kind() {
ident
} else {
unreachable! {"The token is a identifier, as checked by the `expect`"};
};
self.expect(token![CurvedBracketClose])?;
match string_literal.as_str() {
"Error" => Ok(Attribute::derive {
value: DeriveValue::Error,
span,
}),
_ => Err(error::ParsingError::WrongDeriveValue {
specified: string_literal,
specified: StringLiteral {
content: string_literal.to_owned(),
span: string_literal_token.span,
},
}),
}
}