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> {
|
2024-02-28 22:49:46 +00:00
|
|
|
identifier: Identifier,
|
2024-02-26 21:27:01 +00:00
|
|
|
statement: Box<Statement<'src>>,
|
2024-02-25 18:49:26 +00:00
|
|
|
}
|
|
|
|
|
2024-02-26 21:27:01 +00:00
|
|
|
impl<'src> Assignment<'src> {
|
2024-02-28 22:49:46 +00:00
|
|
|
pub fn new(identifier: Identifier, 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
|
|
|
}
|
|
|
|
}
|