chore: allow attributes on enum cases (#196)

Signed-off-by: azjezz <azjezz@protonmail.com>
This commit is contained in:
Saif Eddin Gmati 2022-12-10 16:41:56 +01:00 committed by GitHub
parent 239bd69b86
commit ecbced3007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -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<AttributeGroup>,
pub name: SimpleIdentifier,
}
@ -42,6 +43,7 @@ pub struct BackedEnumCase {
pub start: Span,
pub end: Span,
pub name: SimpleIdentifier,
pub attributes: Vec<AttributeGroup>,
pub value: Expression,
}

View File

@ -103,9 +103,11 @@ pub fn parse(state: &mut State) -> ParseResult<Statement> {
}
fn unit_member(state: &mut State, enum_name: String) -> ParseResult<UnitEnumMember> {
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<UnitEnumMemb
let end = utils::skip_semicolon(state)?;
return Ok(UnitEnumMember::Case(UnitEnumCase { start, end, name }));
return Ok(UnitEnumMember::Case(UnitEnumCase {
start,
end,
name,
attributes,
}));
}
let modifiers = modifiers::collect(state)?;
@ -135,9 +142,11 @@ fn unit_member(state: &mut State, enum_name: String) -> ParseResult<UnitEnumMemb
}
fn backed_member(state: &mut State, enum_name: String) -> ParseResult<BackedEnumMember> {
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<BackedEnum
end,
name,
value,
attributes,
}));
}