ast: Enum variants can have no data, or have an associated integer.

This commit is contained in:
John 2024-02-26 15:59:15 -06:00
parent bb3eecd190
commit 9bde97942c
2 changed files with 5 additions and 3 deletions

View File

@ -146,7 +146,8 @@ pub struct Variant {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum VariantKind {
Named(Identifier),
Plain,
CLike(u128),
Tuple(Vec<Ty>),
Struct(Vec<StructMember>),
}

View File

@ -186,7 +186,8 @@ mod display {
impl Display for VariantKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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::Struct(v) => delimit(separate(v, ",\n"), BRACES)(f),
}
@ -664,7 +665,7 @@ mod convert {
Vec<Variant> => EnumKind::Variants,
}
impl From for VariantKind {
Identifier => VariantKind::Named,
u128 => VariantKind::CLike,
Vec<Ty> => VariantKind::Tuple,
// TODO: enum struct variants
}