|
|
|
@ -170,7 +170,24 @@ impl Walkable for OwnedLiteral {
|
|
|
|
|
|
|
|
|
|
impl Castable for OwnedLiteral {
|
|
|
|
|
fn cast_to_type<'a>(&'a self, target: &str) -> Option<IceResult<'a>> {
|
|
|
|
|
todo!()
|
|
|
|
|
match (self, target) {
|
|
|
|
|
(OwnedLiteral::LString(text), "number") => text
|
|
|
|
|
.parse::<u64>()
|
|
|
|
|
.map(|num| IceResult::from_owned(OwnedLiteral::LPositiveInteger(num)))
|
|
|
|
|
.or_else(|_| {
|
|
|
|
|
text.parse::<i64>()
|
|
|
|
|
.map(|num| IceResult::from_owned(OwnedLiteral::LNegativeInteger(num)))
|
|
|
|
|
})
|
|
|
|
|
.or_else(|_| {
|
|
|
|
|
text.parse::<f64>()
|
|
|
|
|
.map(|num| IceResult::from_owned(OwnedLiteral::LFloat(num)))
|
|
|
|
|
})
|
|
|
|
|
.ok(),
|
|
|
|
|
(OwnedLiteral::LPositiveInteger(_), "number") => Some(IceResult::from_borrowed(self)),
|
|
|
|
|
(OwnedLiteral::LNegativeInteger(_), "number") => Some(IceResult::from_borrowed(self)),
|
|
|
|
|
(OwnedLiteral::LFloat(_), "number") => Some(IceResult::from_borrowed(self)),
|
|
|
|
|
(_, _) => panic!("Unimplemented cast"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|