1
0
dust/src/value/function.rs

39 lines
877 B
Rust
Raw Normal View History

2023-08-22 15:40:50 +00:00
use std::fmt::{self, Display, Formatter};
use serde::{Deserialize, Serialize};
2023-10-31 13:31:10 +00:00
use crate::{Identifier, Statement};
2023-08-22 15:40:50 +00:00
2023-09-30 21:52:37 +00:00
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Function {
2023-10-07 16:37:35 +00:00
parameters: Vec<Identifier>,
2023-10-31 13:31:10 +00:00
body: Box<Statement>,
2023-09-30 21:52:37 +00:00
}
2023-08-22 15:40:50 +00:00
impl Function {
2023-10-31 13:31:10 +00:00
pub fn new(identifiers: Vec<Identifier>, items: Statement) -> Self {
2023-09-30 21:52:37 +00:00
Function {
2023-10-07 16:37:35 +00:00
parameters: identifiers,
2023-10-31 13:31:10 +00:00
body: Box::new(items),
2023-09-30 21:52:37 +00:00
}
2023-08-22 15:40:50 +00:00
}
2023-10-06 21:11:50 +00:00
pub fn identifiers(&self) -> &Vec<Identifier> {
2023-10-07 16:37:35 +00:00
&self.parameters
2023-10-06 21:11:50 +00:00
}
2023-10-31 13:31:10 +00:00
pub fn body(&self) -> &Statement {
2023-10-07 16:37:35 +00:00
&self.body
2023-10-06 21:11:50 +00:00
}
}
2023-08-22 15:40:50 +00:00
impl Display for Function {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
2023-09-30 21:52:37 +00:00
write!(
f,
2023-10-06 17:32:58 +00:00
"function < {:?} > {{ {:?} }}", // TODO: Correct this output
2023-10-07 16:37:35 +00:00
self.parameters, self.body
2023-09-30 21:52:37 +00:00
)
2023-08-22 15:40:50 +00:00
}
}