ast: Enum variants can have no data, or have an associated integer.
This commit is contained in:
parent
bb3eecd190
commit
9bde97942c
@ -146,7 +146,8 @@ pub struct Variant {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum VariantKind {
|
pub enum VariantKind {
|
||||||
Named(Identifier),
|
Plain,
|
||||||
|
CLike(u128),
|
||||||
Tuple(Vec<Ty>),
|
Tuple(Vec<Ty>),
|
||||||
Struct(Vec<StructMember>),
|
Struct(Vec<StructMember>),
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,8 @@ mod display {
|
|||||||
impl Display for VariantKind {
|
impl Display for VariantKind {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
VariantKind::Named(n) => n.fmt(f),
|
VariantKind::Plain => Ok(()),
|
||||||
|
VariantKind::CLike(n) => n.fmt(f),
|
||||||
VariantKind::Tuple(v) => delimit(separate(v, ", "), INLINE_PARENS)(f),
|
VariantKind::Tuple(v) => delimit(separate(v, ", "), INLINE_PARENS)(f),
|
||||||
VariantKind::Struct(v) => delimit(separate(v, ",\n"), BRACES)(f),
|
VariantKind::Struct(v) => delimit(separate(v, ",\n"), BRACES)(f),
|
||||||
}
|
}
|
||||||
@ -664,7 +665,7 @@ mod convert {
|
|||||||
Vec<Variant> => EnumKind::Variants,
|
Vec<Variant> => EnumKind::Variants,
|
||||||
}
|
}
|
||||||
impl From for VariantKind {
|
impl From for VariantKind {
|
||||||
Identifier => VariantKind::Named,
|
u128 => VariantKind::CLike,
|
||||||
Vec<Ty> => VariantKind::Tuple,
|
Vec<Ty> => VariantKind::Tuple,
|
||||||
// TODO: enum struct variants
|
// TODO: enum struct variants
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user