mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-13 01:35:31 +01:00
Multi-expr repl improved
Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
14
src/main.rs
14
src/main.rs
@ -9,6 +9,7 @@ mod step1_read_print;
|
||||
use step1_read_print::rep;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let mut num = 0;
|
||||
loop {
|
||||
let mut input = String::new();
|
||||
loop {
|
||||
@ -20,27 +21,28 @@ fn main() -> io::Result<()> {
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line)?;
|
||||
|
||||
if line == "\n" {
|
||||
input.push_str(&line);
|
||||
if input == "\n" {
|
||||
break;
|
||||
}
|
||||
|
||||
input.push_str(&line);
|
||||
|
||||
// Perform rep on whole available input
|
||||
match rep(&input) {
|
||||
Ok(output) => {
|
||||
for el in output {
|
||||
println!("{}", el);
|
||||
num += 1;
|
||||
println!("[{}]> {}", num, el);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
if line == "\n" {
|
||||
println!("ERROR: {}", err);
|
||||
num += 1;
|
||||
println!("; [{}]> {}", num, err);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ use crate::types::{MalErr, MalType};
|
||||
fn READ(input: &str) -> Result<Vec<MalType>, MalErr> {
|
||||
match read_str(input) {
|
||||
Ok(ast) => Ok(ast),
|
||||
Err(err) => Err(format!("Unexpected error during READ: {}", err)),
|
||||
Err(err) => Err(format!("@ READ: {}", err)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user