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
9d14d2e061
commit
4feae61a76
|
@ -193,14 +193,26 @@ impl Parser {
|
||||||
|
|
||||||
let attribute = match keyword {
|
let attribute = match keyword {
|
||||||
AttributeKeyword::derive => {
|
AttributeKeyword::derive => {
|
||||||
let string_literal = self.parse_bracket_string_literal()?;
|
self.expect(token![CurvedBracketOpen])?;
|
||||||
match string_literal.content.as_str() {
|
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 {
|
"Error" => Ok(Attribute::derive {
|
||||||
value: DeriveValue::Error,
|
value: DeriveValue::Error,
|
||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
_ => Err(error::ParsingError::WrongDeriveValue {
|
_ => Err(error::ParsingError::WrongDeriveValue {
|
||||||
specified: string_literal,
|
specified: StringLiteral {
|
||||||
|
content: string_literal.to_owned(),
|
||||||
|
span: string_literal_token.span,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue