crftng-intrprtrs/src/interpreter/ast_walker/statement_interpreter.rs

31 lines
770 B
Rust

use super::Interpret;
use super::{types::Value, RuntimeError};
use crate::ast::statement::statement_node;
impl Interpret for statement_node::Statement {
fn interpret(&self) -> Result<Value, RuntimeError> {
statement_node::all_variants!(self, n => n.interpret())
}
}
impl Interpret for statement_node::PrintStatement {
fn interpret(&self) -> Result<Value, RuntimeError> {
let res = self.0.interpret()?;
println!("{:?}", res);
Ok(res)
}
}
impl Interpret for statement_node::ExpressionStatement {
fn interpret(&self) -> Result<Value, RuntimeError> {
self.0.interpret()
}
}
impl Interpret for statement_node::VariableAssignmentStatement {
fn interpret(&self) -> Result<Value, RuntimeError> {
let expr_val = self.node.interpret()?;
Ok(expr_val)
}
}