Add more Display implementations
This commit is contained in:
parent
6130f73ca8
commit
9a2e4f3649
@ -264,16 +264,20 @@ impl Display for Type {
|
|||||||
value_parameters,
|
value_parameters,
|
||||||
return_type,
|
return_type,
|
||||||
} => {
|
} => {
|
||||||
write!(f, "fn (")?;
|
write!(f, "fn ")?;
|
||||||
|
|
||||||
if let Some(type_parameters) = type_parameters {
|
if let Some(type_parameters) = type_parameters {
|
||||||
|
write!(f, "<")?;
|
||||||
|
|
||||||
for identifier in type_parameters {
|
for identifier in type_parameters {
|
||||||
write!(f, "{} ", identifier)?;
|
write!(f, "{}, ", identifier)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, ")(")?;
|
write!(f, ">")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write!(f, "(")?;
|
||||||
|
|
||||||
if let Some(value_parameters) = value_parameters {
|
if let Some(value_parameters) = value_parameters {
|
||||||
for (identifier, r#type) in value_parameters {
|
for (identifier, r#type) in value_parameters {
|
||||||
write!(f, "{identifier}: {type}")?;
|
write!(f, "{identifier}: {type}")?;
|
||||||
|
@ -159,11 +159,11 @@ impl TypeConstructor {
|
|||||||
impl Display for TypeConstructor {
|
impl Display for TypeConstructor {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
TypeConstructor::Function(WithPosition { node, position }) => write!(f, "{node}")?,
|
TypeConstructor::Function(WithPosition { node, .. }) => write!(f, "{node}")?,
|
||||||
TypeConstructor::Invokation(type_invokation) => write!(f, "{type_invokation}")?,
|
TypeConstructor::Invokation(type_invokation) => write!(f, "{type_invokation}")?,
|
||||||
TypeConstructor::List(WithPosition { node, position }) => write!(f, "{node}")?,
|
TypeConstructor::List(WithPosition { node, .. }) => write!(f, "{node}")?,
|
||||||
TypeConstructor::ListOf(WithPosition { node, position }) => write!(f, "{node}")?,
|
TypeConstructor::ListOf(WithPosition { node, .. }) => write!(f, "{node}")?,
|
||||||
TypeConstructor::Map(WithPosition { node, position }) => {
|
TypeConstructor::Map(WithPosition { node, .. }) => {
|
||||||
write!(f, "{{ ")?;
|
write!(f, "{{ ")?;
|
||||||
|
|
||||||
for (identifier, constructor) in node {
|
for (identifier, constructor) in node {
|
||||||
@ -172,7 +172,7 @@ impl Display for TypeConstructor {
|
|||||||
|
|
||||||
write!(f, "}}")?;
|
write!(f, "}}")?;
|
||||||
}
|
}
|
||||||
TypeConstructor::Raw(WithPosition { node, position }) => write!(f, "{node}")?,
|
TypeConstructor::Raw(WithPosition { node, .. }) => write!(f, "{node}")?,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -191,7 +191,14 @@ pub enum RawTypeConstructor {
|
|||||||
|
|
||||||
impl Display for RawTypeConstructor {
|
impl Display for RawTypeConstructor {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
todo!()
|
match self {
|
||||||
|
RawTypeConstructor::Any => write!(f, "any"),
|
||||||
|
RawTypeConstructor::Boolean => write!(f, "bool"),
|
||||||
|
RawTypeConstructor::Float => write!(f, "float"),
|
||||||
|
RawTypeConstructor::Integer => write!(f, "int"),
|
||||||
|
RawTypeConstructor::Range => write!(f, "range"),
|
||||||
|
RawTypeConstructor::String => write!(f, "str"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +211,29 @@ pub struct FunctionTypeConstructor {
|
|||||||
|
|
||||||
impl Display for FunctionTypeConstructor {
|
impl Display for FunctionTypeConstructor {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
todo!()
|
write!(f, "fn ")?;
|
||||||
|
|
||||||
|
if let Some(parameters) = &self.type_parameters {
|
||||||
|
write!(f, "<")?;
|
||||||
|
|
||||||
|
for identifier in parameters {
|
||||||
|
write!(f, "{}, ", identifier.node)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(f, ">")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(parameters) = &self.value_parameters {
|
||||||
|
for (identifier, constructor) in parameters {
|
||||||
|
write!(f, "{}: {constructor}", identifier.node)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(f, "(")?;
|
||||||
|
|
||||||
|
write!(f, ")")?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +245,9 @@ pub struct ListTypeConstructor {
|
|||||||
|
|
||||||
impl Display for ListTypeConstructor {
|
impl Display for ListTypeConstructor {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
todo!()
|
let ListTypeConstructor { length, item_type } = self;
|
||||||
|
|
||||||
|
write!(f, "[{item_type}; {length}]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,18 +687,18 @@ impl Display for ValueNode {
|
|||||||
value_parameters,
|
value_parameters,
|
||||||
return_type,
|
return_type,
|
||||||
body,
|
body,
|
||||||
context_template,
|
context_template: _,
|
||||||
}) => {
|
}) => {
|
||||||
write!(f, "fn ")?;
|
write!(f, "fn ")?;
|
||||||
|
|
||||||
if let Some(type_parameters) = type_parameters {
|
if let Some(type_parameters) = type_parameters {
|
||||||
write!(f, "(")?;
|
write!(f, "<")?;
|
||||||
|
|
||||||
for identifier in type_parameters {
|
for identifier in type_parameters {
|
||||||
write!(f, "{identifier}")?;
|
write!(f, "{identifier}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, ")")?;
|
write!(f, ">")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(value_parameters) = value_parameters {
|
if let Some(value_parameters) = value_parameters {
|
||||||
@ -711,7 +711,11 @@ impl Display for ValueNode {
|
|||||||
write!(f, ")")?;
|
write!(f, ")")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "{}", body.node)
|
if let Some(r#type) = return_type {
|
||||||
|
write!(f, " -> {type}")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(f, " {}", body.node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ impl Display for Value {
|
|||||||
write!(f, "fn ")?;
|
write!(f, "fn ")?;
|
||||||
|
|
||||||
if let Some(type_parameters) = type_parameters {
|
if let Some(type_parameters) = type_parameters {
|
||||||
write!(f, "(")?;
|
write!(f, "<")?;
|
||||||
|
|
||||||
for (index, identifier) in type_parameters.into_iter().enumerate() {
|
for (index, identifier) in type_parameters.into_iter().enumerate() {
|
||||||
if index == type_parameters.len() - 1 {
|
if index == type_parameters.len() - 1 {
|
||||||
@ -200,7 +200,7 @@ impl Display for Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, ")")?;
|
write!(f, ">")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "(")?;
|
write!(f, "(")?;
|
||||||
|
Loading…
Reference in New Issue
Block a user