From ecbced30075bb88c8ebd0e8b7d1dc9fbb98c2d4c Mon Sep 17 00:00:00 2001 From: Saif Eddin Gmati <29315886+azjezz@users.noreply.github.com> Date: Sat, 10 Dec 2022 16:41:56 +0100 Subject: [PATCH] chore: allow attributes on enum cases (#196) Signed-off-by: azjezz --- src/parser/ast/enums.rs | 4 +++- src/parser/internal/enums.rs | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/parser/ast/enums.rs b/src/parser/ast/enums.rs index cbc1a02..3bfd5df 100644 --- a/src/parser/ast/enums.rs +++ b/src/parser/ast/enums.rs @@ -7,10 +7,11 @@ use crate::parser::ast::functions::Method; use crate::parser::ast::identifiers::SimpleIdentifier; use crate::parser::ast::Expression; -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq)] pub struct UnitEnumCase { pub start: Span, pub end: Span, + pub attributes: Vec, pub name: SimpleIdentifier, } @@ -42,6 +43,7 @@ pub struct BackedEnumCase { pub start: Span, pub end: Span, pub name: SimpleIdentifier, + pub attributes: Vec, pub value: Expression, } diff --git a/src/parser/internal/enums.rs b/src/parser/internal/enums.rs index 3c0e5bb..21c96cb 100644 --- a/src/parser/internal/enums.rs +++ b/src/parser/internal/enums.rs @@ -103,9 +103,11 @@ pub fn parse(state: &mut State) -> ParseResult { } fn unit_member(state: &mut State, enum_name: String) -> ParseResult { - let has_attributes = attributes::gather_attributes(state)?; + attributes::gather_attributes(state)?; + + if state.current.kind == TokenKind::Case { + let attributes = state.get_attributes(); - if !has_attributes && state.current.kind == TokenKind::Case { let start = state.current.span; state.next(); @@ -121,7 +123,12 @@ fn unit_member(state: &mut State, enum_name: String) -> ParseResult ParseResult ParseResult { - let has_attributes = attributes::gather_attributes(state)?; + attributes::gather_attributes(state)?; + + if state.current.kind == TokenKind::Case { + let attributes = state.get_attributes(); - if !has_attributes && state.current.kind == TokenKind::Case { let start = state.current.span; state.next(); @@ -162,6 +171,7 @@ fn backed_member(state: &mut State, enum_name: String) -> ParseResult