33 lines
776 B
Rust
33 lines
776 B
Rust
use core::fmt;
|
|
use std::collections::LinkedList;
|
|
|
|
use super::{expr::Expr, Identifier};
|
|
|
|
#[derive(Debug)]
|
|
pub enum Value {
|
|
Int(usize),
|
|
String(String),
|
|
Function(Vec<Identifier>, LinkedList<Expr>),
|
|
Structural(usize, Vec<Value>),
|
|
}
|
|
|
|
impl fmt::Display for Value {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::Int(v) => write!(f, "{}", v),
|
|
Self::String(val) => write!(f, "\"{val}\""),
|
|
Self::Function(args, exprs) => write!(f,
|
|
"function({}):{}",
|
|
args.into_iter()
|
|
.map(|a| a.to_string())
|
|
.collect::<Vec<_>>()
|
|
.join(", "),
|
|
exprs.into_iter()
|
|
.map(|e| format!("\n\t{e}"))
|
|
.collect::<String>(),
|
|
),
|
|
Self::Structural(_, _) => todo!(),
|
|
}
|
|
}
|
|
}
|