parent
6fe5a8cdef
commit
cdcd24e7b6
@ -5,16 +5,24 @@ mod display;
|
|||||||
pub type IntType = i64;
|
pub type IntType = i64;
|
||||||
pub type FloatType = f64;
|
pub type FloatType = f64;
|
||||||
|
|
||||||
|
/// The value type used by the parser.
|
||||||
|
/// Values can be of different subtypes that are the variants of this enum.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
|
/// A string value.
|
||||||
String(String),
|
String(String),
|
||||||
|
/// A float value.
|
||||||
Float(FloatType),
|
Float(FloatType),
|
||||||
|
/// An integer value.
|
||||||
Int(IntType),
|
Int(IntType),
|
||||||
|
/// A boolean value.
|
||||||
Boolean(bool),
|
Boolean(bool),
|
||||||
|
/// A tuple value.
|
||||||
Tuple(Vec<Value>),
|
Tuple(Vec<Value>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
|
/// Returns true if `self` is a `Value::Int`.
|
||||||
pub fn is_int(&self) -> bool {
|
pub fn is_int(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Value::Int(_) => true,
|
Value::Int(_) => true,
|
||||||
@ -22,6 +30,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if `self` is a `Value::Float`.
|
||||||
pub fn is_float(&self) -> bool {
|
pub fn is_float(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Value::Float(_) => true,
|
Value::Float(_) => true,
|
||||||
@ -29,6 +38,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `self` as a `IntType`, or `Err` if `self` is not a `Value::Int`.
|
||||||
pub fn as_int(&self) -> Result<IntType, Error> {
|
pub fn as_int(&self) -> Result<IntType, Error> {
|
||||||
match self {
|
match self {
|
||||||
Value::Int(i) => Ok(*i),
|
Value::Int(i) => Ok(*i),
|
||||||
@ -36,6 +46,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `self` as a `FloatType`, or `Err` if `self` is not a `Value::Float` or `Value::Int`.
|
||||||
pub fn as_float(&self) -> Result<FloatType, Error> {
|
pub fn as_float(&self) -> Result<FloatType, Error> {
|
||||||
match self {
|
match self {
|
||||||
Value::Float(f) => Ok(*f),
|
Value::Float(f) => Ok(*f),
|
||||||
|
Loading…
Reference in New Issue
Block a user