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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user