1
0
dust/src/abstract_tree/assignment.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2024-02-26 21:27:01 +00:00
use crate::{error::RuntimeError, value::Value, Context};
2024-02-25 18:49:26 +00:00
2024-02-26 21:27:01 +00:00
use super::{AbstractTree, Identifier, Statement};
2024-02-25 18:49:26 +00:00
2024-02-25 19:26:22 +00:00
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
2024-02-26 21:27:01 +00:00
pub struct Assignment<'src> {
identifier: Identifier<'src>,
statement: Box<Statement<'src>>,
2024-02-25 18:49:26 +00:00
}
2024-02-26 21:27:01 +00:00
impl<'src> Assignment<'src> {
pub fn new(identifier: Identifier<'src>, statement: Statement<'src>) -> Self {
2024-02-25 18:49:26 +00:00
Self {
identifier,
statement: Box::new(statement),
}
}
}
2024-02-26 21:27:01 +00:00
impl<'src> AbstractTree for Assignment<'src> {
fn run(self, _context: &Context) -> Result<Value, RuntimeError> {
todo!()
// let value = self.statement.run(context)?;
2024-02-25 18:49:26 +00:00
2024-02-26 21:27:01 +00:00
// context.set(self.identifier, value)?;
2024-02-25 18:49:26 +00:00
2024-02-26 21:27:01 +00:00
// Ok(Value::none())
2024-02-25 18:49:26 +00:00
}
}
#[cfg(test)]
mod tests {
2024-02-26 21:27:01 +00:00
// use super::*;
2024-02-25 18:49:26 +00:00
#[test]
fn assign_value() {
2024-02-26 21:27:01 +00:00
todo!()
// let context = Context::new();
// Assignment::new(
// Identifier::new("foobar"),
// Statement::Value(Value::integer(42)),
// )
// .run(&context)
// .unwrap();
// assert_eq!(
// context.get(&Identifier::new("foobar")).unwrap(),
// Some(Value::integer(42))
// )
2024-02-25 18:49:26 +00:00
}
}