use std::fmt;
use std::fmt::Debug;
use super::types::Type;
use super::value::Value;
#[derive(Debug, Clone)]
pub struct Token {
_type: Type,
value: Option<Box<Value>>,
}
impl fmt::Display for Token {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "Token ({:?}, {:?})", self._type, self.value)
}
}
impl Token {
pub fn new(_type: Type, value: Option<Box<Value>>) -> Self {
Self {
_type: _type,
value: value,
}
}
pub fn empty() -> Self {
Self {
_type: Type::EOF,
value: None,
}
}
pub fn get_type(&self) -> &Type {
&self._type
}
pub fn get_value(&self) -> &Box<Value> {
self.value
.as_ref()
.expect("Tried to get value that was not set. Aborting.")
}
}