Files
rust-mal/src/step1_read_print.rs
teo3300 7be624e032 Cleaning repl
Cleaning repl, removing multi-statement repl, further implementation as
separated code from the rest

Signed-off-by: teo3300 <matteo.rogora@live.it>
2023-06-10 03:10:47 +02:00

37 lines
909 B
Rust

// Structure the main functions of the interpreter
//
// For now just act as an echo, note that each function should not modify the
// input, thus this can be referenced by the previous step without the need
// to allocate more memory
use crate::printer::pr_str;
use crate::reader::read_str;
use crate::types::{MalRet, MalType};
#[allow(non_snake_case)]
/// Read input and generate an ast
fn READ(input: &str) -> MalRet {
match read_str(input) {
Ok(ast) => Ok(ast),
Err(err) => Err(format!("@ READ: {}", err)),
}
}
#[allow(non_snake_case)]
/// Evaluate the generated ast
fn EVAL(ast: MalType) -> MalRet {
Ok(ast)
}
#[allow(non_snake_case)]
/// Print out the result of the evaluation
fn PRINT(output: MalType) -> String {
pr_str(&output, true)
}
pub fn rep(input: &str) -> Result<String, String> {
let ast = READ(input)?;
let out = EVAL(ast)?;
Ok(PRINT(out))
}