1
0
dust/src/abstract_tree/assignment.rs

67 lines
1.5 KiB
Rust
Raw Normal View History

use crate::{
error::{RuntimeError, ValidationError},
value::Value,
Context,
};
2024-02-25 18:49:26 +00:00
use super::{AbstractTree, Identifier, Statement, Type};
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,
r#type: Option<Type>,
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> {
pub fn new(identifier: Identifier, r#type: Option<Type>, statement: Statement<'src>) -> Self {
2024-02-25 18:49:26 +00:00
Self {
identifier,
r#type,
2024-02-25 18:49:26 +00:00
statement: Box::new(statement),
}
}
}
2024-02-26 21:27:01 +00:00
impl<'src> AbstractTree for Assignment<'src> {
fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> {
todo!()
}
fn validate(&self, _context: &Context) -> Result<(), ValidationError> {
todo!()
}
2024-02-26 21:27:01 +00:00
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
}
}