Simplify TypeDefinition type
This commit is contained in:
parent
ec074177d5
commit
5e105177cf
@ -9,18 +9,11 @@ use crate::{
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
||||||
pub struct EnumDefinition {
|
pub struct EnumDefinition {
|
||||||
identifier: Identifier,
|
identifier: Identifier,
|
||||||
variants: Vec<(Identifier, VariantContent)>,
|
variants: Vec<(Identifier, Option<Type>)>,
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
|
||||||
pub enum VariantContent {
|
|
||||||
Type(Type),
|
|
||||||
TypeDefinition(TypeDefinition),
|
|
||||||
None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EnumDefinition {
|
impl EnumDefinition {
|
||||||
pub fn new(identifier: Identifier, variants: Vec<(Identifier, VariantContent)>) -> Self {
|
pub fn new(identifier: Identifier, variants: Vec<(Identifier, Option<Type>)>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
identifier,
|
identifier,
|
||||||
variants,
|
variants,
|
||||||
@ -57,16 +50,7 @@ impl AbstractTree for EnumDefinition {
|
|||||||
if child.kind() == "type" {
|
if child.kind() == "type" {
|
||||||
let r#type = Type::from_syntax(child, source, context)?;
|
let r#type = Type::from_syntax(child, source, context)?;
|
||||||
|
|
||||||
variants.push((identifier.clone(), VariantContent::Type(r#type)));
|
variants.push((identifier.clone(), Some(r#type)));
|
||||||
}
|
|
||||||
|
|
||||||
if child.kind() == "type_definition" {
|
|
||||||
let type_definition = TypeDefinition::from_syntax(child, source, context)?;
|
|
||||||
|
|
||||||
variants.push((
|
|
||||||
identifier.clone(),
|
|
||||||
VariantContent::TypeDefinition(type_definition),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ use enum_iterator::{all, Sequence};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::rw_lock_error::RwLockError, Context, EnumDefinition, Identifier, Type, TypeDefinition,
|
error::rw_lock_error::RwLockError, Context, EnumDefinition, Identifier, Type, TypeDefinition,
|
||||||
VariantContent,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static OPTION: OnceLock<Result<TypeDefinition, RwLockError>> = OnceLock::new();
|
static OPTION: OnceLock<Result<TypeDefinition, RwLockError>> = OnceLock::new();
|
||||||
@ -34,8 +33,8 @@ impl BuiltInTypeDefinition {
|
|||||||
let definition = TypeDefinition::Enum(EnumDefinition::new(
|
let definition = TypeDefinition::Enum(EnumDefinition::new(
|
||||||
Identifier::new(self.name()),
|
Identifier::new(self.name()),
|
||||||
vec![
|
vec![
|
||||||
(Identifier::new("Some"), VariantContent::Type(Type::Any)),
|
(Identifier::new("Some"), Some(Type::Any)),
|
||||||
(Identifier::new("None"), VariantContent::None),
|
(Identifier::new("None"), None),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -45,8 +44,8 @@ impl BuiltInTypeDefinition {
|
|||||||
let definition = TypeDefinition::Enum(EnumDefinition::new(
|
let definition = TypeDefinition::Enum(EnumDefinition::new(
|
||||||
Identifier::new(self.name()),
|
Identifier::new(self.name()),
|
||||||
vec![
|
vec![
|
||||||
(Identifier::new("Ok"), VariantContent::Type(Type::Any)),
|
(Identifier::new("Ok"), Some(Type::Any)),
|
||||||
(Identifier::new("Err"), VariantContent::Type(Type::Any)),
|
(Identifier::new("Err"), Some(Type::Any)),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user