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:
parent
2b317f36f5
commit
a9724ced97
|
@ -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,
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue