From a9724ced9740673bb111fe8ca34920c724a5df3f Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 19 May 2024 13:55:36 +0200 Subject: [PATCH] fix(parser/unchecked/attributes): Correctly enforce an identifier in `derive` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ebnf grammar specifies an identifier (namely “Error” in the `derive` attribute.), while the parser expected a string literal there. --- src/parser/parsing/unchecked/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/parser/parsing/unchecked/mod.rs b/src/parser/parsing/unchecked/mod.rs index 41aab77..7869a43 100644 --- a/src/parser/parsing/unchecked/mod.rs +++ b/src/parser/parsing/unchecked/mod.rs @@ -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, + }, }), } }