From 9bde97942c97a44722d7e6ced4330c617a074f53 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 26 Feb 2024 15:59:15 -0600 Subject: [PATCH] ast: Enum variants can have no data, or have an associated integer. --- libconlang/src/ast.rs | 3 ++- libconlang/src/ast/ast_impl.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libconlang/src/ast.rs b/libconlang/src/ast.rs index c1a2e14..174791c 100644 --- a/libconlang/src/ast.rs +++ b/libconlang/src/ast.rs @@ -146,7 +146,8 @@ pub struct Variant { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum VariantKind { - Named(Identifier), + Plain, + CLike(u128), Tuple(Vec), Struct(Vec), } diff --git a/libconlang/src/ast/ast_impl.rs b/libconlang/src/ast/ast_impl.rs index da533aa..b74db4f 100644 --- a/libconlang/src/ast/ast_impl.rs +++ b/libconlang/src/ast/ast_impl.rs @@ -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 => EnumKind::Variants, } impl From for VariantKind { - Identifier => VariantKind::Named, + u128 => VariantKind::CLike, Vec => VariantKind::Tuple, // TODO: enum struct variants }