Implement the outstanding type casts for OwnedLiterals.

This commit is contained in:
Tom Alexander 2020-06-14 17:37:51 -04:00
parent eb3b1ae30a
commit 021a7bd739
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -226,22 +226,60 @@ impl Castable for OwnedLiteral {
.map(|num| IceResult::from_owned(OwnedLiteral::LFloat(num)))
})
.ok(),
(OwnedLiteral::LBoolean(_), "number") => todo!(),
(OwnedLiteral::LBoolean(boolean), "number") => {
if *boolean {
Some(IceResult::from_owned(OwnedLiteral::LPositiveInteger(1)))
} else {
Some(IceResult::from_owned(OwnedLiteral::LPositiveInteger(0)))
}
}
(OwnedLiteral::LPositiveInteger(_), "number") => Some(IceResult::from_borrowed(self)),
(OwnedLiteral::LNegativeInteger(_), "number") => Some(IceResult::from_borrowed(self)),
(OwnedLiteral::LFloat(_), "number") => Some(IceResult::from_borrowed(self)),
(OwnedLiteral::LString(text), "string") => todo!(),
(OwnedLiteral::LBoolean(_), "string") => todo!(),
(OwnedLiteral::LPositiveInteger(_), "string") => todo!(),
(OwnedLiteral::LNegativeInteger(_), "string") => todo!(),
(OwnedLiteral::LFloat(_), "string") => todo!(),
(OwnedLiteral::LString(_), "string") => Some(IceResult::from_borrowed(self)),
(OwnedLiteral::LBoolean(boolean), "string") => Some(IceResult::from_owned(
OwnedLiteral::LString(boolean.to_string()),
)),
(OwnedLiteral::LPositiveInteger(num), "string") => Some(IceResult::from_owned(
OwnedLiteral::LString(num.to_string()),
)),
(OwnedLiteral::LNegativeInteger(num), "string") => Some(IceResult::from_owned(
OwnedLiteral::LString(num.to_string()),
)),
(OwnedLiteral::LFloat(num), "string") => Some(IceResult::from_owned(
OwnedLiteral::LString(num.to_string()),
)),
(OwnedLiteral::LString(text), "boolean") => todo!(),
(OwnedLiteral::LBoolean(_), "boolean") => todo!(),
(OwnedLiteral::LPositiveInteger(_), "boolean") => todo!(),
(OwnedLiteral::LNegativeInteger(_), "boolean") => todo!(),
(OwnedLiteral::LFloat(_), "boolean") => todo!(),
(OwnedLiteral::LString(text), "boolean") => {
if text.is_empty() {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(false)))
} else {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(true)))
}
}
(OwnedLiteral::LBoolean(_), "boolean") => Some(IceResult::from_borrowed(self)),
(OwnedLiteral::LPositiveInteger(num), "boolean") => {
if *num == 0 {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(false)))
} else {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(true)))
}
}
(OwnedLiteral::LNegativeInteger(num), "boolean") => {
if *num == 0 {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(false)))
} else {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(true)))
}
}
(OwnedLiteral::LFloat(num), "boolean") => {
if *num == 0.0 || num.is_nan() {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(false)))
} else {
Some(IceResult::from_owned(OwnedLiteral::LBoolean(true)))
}
}
(_, _) => panic!("Unimplemented cast"),
}
}