Multi-expr repl improved

Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
teo3300
2023-06-07 18:50:31 +02:00
parent 54d196582f
commit ce21d3b728
2 changed files with 9 additions and 7 deletions

View File

@ -9,6 +9,7 @@ mod step1_read_print;
use step1_read_print::rep; use step1_read_print::rep;
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let mut num = 0;
loop { loop {
let mut input = String::new(); let mut input = String::new();
loop { loop {
@ -20,27 +21,28 @@ fn main() -> io::Result<()> {
let mut line = String::new(); let mut line = String::new();
io::stdin().read_line(&mut line)?; io::stdin().read_line(&mut line)?;
if line == "\n" { input.push_str(&line);
if input == "\n" {
break; break;
} }
input.push_str(&line);
// Perform rep on whole available input // Perform rep on whole available input
match rep(&input) { match rep(&input) {
Ok(output) => { Ok(output) => {
for el in output { for el in output {
println!("{}", el); num += 1;
println!("[{}]> {}", num, el);
} }
} }
Err(err) => { Err(err) => {
if line == "\n" { if line == "\n" {
println!("ERROR: {}", err); num += 1;
println!("; [{}]> {}", num, err);
} else { } else {
continue; continue;
} }
} }
} };
break; break;
} }
} }

View File

@ -13,7 +13,7 @@ use crate::types::{MalErr, MalType};
fn READ(input: &str) -> Result<Vec<MalType>, MalErr> { fn READ(input: &str) -> Result<Vec<MalType>, MalErr> {
match read_str(input) { match read_str(input) {
Ok(ast) => Ok(ast), Ok(ast) => Ok(ast),
Err(err) => Err(format!("Unexpected error during READ: {}", err)), Err(err) => Err(format!("@ READ: {}", err)),
} }
} }