mirror of
https://github.com/danog/parser.git
synced 2024-11-26 20:04:57 +01:00
chore: allow attributes on enum cases (#196)
Signed-off-by: azjezz <azjezz@protonmail.com>
This commit is contained in:
parent
239bd69b86
commit
ecbced3007
@ -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,
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user