|
|
@ -27,6 +27,30 @@ impl From<Sexp> for LispType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<&Sexp> for LispType
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn from(from: &Sexp) -> Self
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match from {
|
|
|
|
|
|
|
|
Sexp::Atom(atom) => atom.into(),
|
|
|
|
|
|
|
|
Sexp::List(_) => Self::List
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<&Atom> for LispType
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn from(from: &Atom) -> Self
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match from {
|
|
|
|
|
|
|
|
Atom::F(_) => Self::Float,
|
|
|
|
|
|
|
|
Atom::I(_) => Self::Integer,
|
|
|
|
|
|
|
|
Atom::S(_) => Self::String,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Atom> for LispType
|
|
|
|
impl From<Atom> for LispType
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fn from(from: Atom) -> Self
|
|
|
|
fn from(from: Atom) -> Self
|
|
|
@ -175,3 +199,55 @@ impl TryIntoExt for Atom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// To avoid some `clone()`s
|
|
|
|
|
|
|
|
pub trait TryGetExt: Sized
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn try_get_list(&self) -> Result<&[Sexp], Error>;
|
|
|
|
|
|
|
|
fn try_get_atom(&self) -> Result<&Atom, Error>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn try_get_string(&self) -> Result<&String, Error>;
|
|
|
|
|
|
|
|
fn try_get_int(&self) -> Result<&i64, Error>;
|
|
|
|
|
|
|
|
fn try_get_float(&self) -> Result<&f64, Error>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl TryGetExt for Sexp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn try_get_list(&self) -> Result<&[Sexp], Error>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::List(list) => Ok(&list[..]),
|
|
|
|
|
|
|
|
other => Err(Error::bad_type(LispType::List, other)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn try_get_atom(&self) -> Result<&Atom, Error>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::Atom(atom) => Ok(atom),
|
|
|
|
|
|
|
|
other => Err(Error::bad_type(LispType::Atom, other)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn try_get_string(&self) -> Result<&String, Error>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::Atom(Atom::S(string)) => Ok(string),
|
|
|
|
|
|
|
|
other => Err(Error::bad_type(LispType::String, other)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn try_get_int(&self) -> Result<&i64, Error>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::Atom(Atom::I(int)) => Ok(int),
|
|
|
|
|
|
|
|
other => Err(Error::bad_type(LispType::Integer, other)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn try_get_float(&self) -> Result<&f64, Error>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::Atom(Atom::F(float)) => Ok(float),
|
|
|
|
|
|
|
|
other => Err(Error::bad_type(LispType::Float, other)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|