use sindra::Type;
use std::fmt;
#[derive(Copy, Debug, Clone, Hash, PartialEq)]
pub enum PType {
String,
Float,
Int,
Boolean,
Complex,
Set,
Void
}
impl Type for PType {
fn name(&self) -> &str {
match *self {
PType::String => "string",
PType::Float => "float",
PType::Int => "int",
PType::Boolean => "bool",
PType::Complex => "complex",
PType::Set => "set",
PType::Void => "void",
}
}
}
impl<'a> From<&'a str> for PType {
fn from(s: &'a str) -> PType {
match s {
"string" => PType::String,
"float" => PType::Float,
"int" => PType::Int,
"bool" => PType::Boolean,
"complex" => PType::Complex,
"set" => PType::Set,
_ => PType::Void,
}
}
}
impl fmt::Display for PType {
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
write!(f, "{}", self.name())
}
}