1
0

Simplify TypeDefinition type

This commit is contained in:
Jeff 2024-02-15 16:06:47 -05:00
parent ec074177d5
commit 5e105177cf
2 changed files with 7 additions and 24 deletions

View File

@ -9,18 +9,11 @@ use crate::{
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct EnumDefinition {
identifier: Identifier,
variants: Vec<(Identifier, VariantContent)>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub enum VariantContent {
Type(Type),
TypeDefinition(TypeDefinition),
None,
variants: Vec<(Identifier, Option<Type>)>,
}
impl EnumDefinition {
pub fn new(identifier: Identifier, variants: Vec<(Identifier, VariantContent)>) -> Self {
pub fn new(identifier: Identifier, variants: Vec<(Identifier, Option<Type>)>) -> Self {
Self {
identifier,
variants,
@ -57,16 +50,7 @@ impl AbstractTree for EnumDefinition {
if child.kind() == "type" {
let r#type = Type::from_syntax(child, source, context)?;
variants.push((identifier.clone(), VariantContent::Type(r#type)));
}
if child.kind() == "type_definition" {
let type_definition = TypeDefinition::from_syntax(child, source, context)?;
variants.push((
identifier.clone(),
VariantContent::TypeDefinition(type_definition),
));
variants.push((identifier.clone(), Some(r#type)));
}
}
}

View File

@ -4,7 +4,6 @@ use enum_iterator::{all, Sequence};
use crate::{
error::rw_lock_error::RwLockError, Context, EnumDefinition, Identifier, Type, TypeDefinition,
VariantContent,
};
static OPTION: OnceLock<Result<TypeDefinition, RwLockError>> = OnceLock::new();
@ -34,8 +33,8 @@ impl BuiltInTypeDefinition {
let definition = TypeDefinition::Enum(EnumDefinition::new(
Identifier::new(self.name()),
vec![
(Identifier::new("Some"), VariantContent::Type(Type::Any)),
(Identifier::new("None"), VariantContent::None),
(Identifier::new("Some"), Some(Type::Any)),
(Identifier::new("None"), None),
],
));
@ -45,8 +44,8 @@ impl BuiltInTypeDefinition {
let definition = TypeDefinition::Enum(EnumDefinition::new(
Identifier::new(self.name()),
vec![
(Identifier::new("Ok"), VariantContent::Type(Type::Any)),
(Identifier::new("Err"), VariantContent::Type(Type::Any)),
(Identifier::new("Ok"), Some(Type::Any)),
(Identifier::new("Err"), Some(Type::Any)),
],
));