mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-13 01:35:31 +01:00
Oneline multi expression
Multiple expressions can be evaluated on a single line Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
29
src/main.rs
29
src/main.rs
@ -10,34 +10,33 @@ use step1_read_print::rep;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
loop {
|
||||
print!("user> ");
|
||||
// Flush the prompt to appear before command
|
||||
let _ = io::stdout().flush();
|
||||
|
||||
let mut input = String::new();
|
||||
loop {
|
||||
print!("user> ");
|
||||
// Flush the prompt to appear before command
|
||||
let _ = io::stdout().flush();
|
||||
|
||||
// Read line to compose program inpug
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line)?;
|
||||
|
||||
// Append line to input
|
||||
input.push_str(&line);
|
||||
|
||||
// If there is nothing to evaluate skip rep
|
||||
if input == "\n" {
|
||||
continue;
|
||||
if line == "\n" {
|
||||
break;
|
||||
}
|
||||
|
||||
input.push_str(&line);
|
||||
|
||||
// Perform rep on whole available input
|
||||
match rep(&input) {
|
||||
Ok(output) => println!("{}", output),
|
||||
Err((err, depth)) => {
|
||||
Ok(output) => {
|
||||
for el in output {
|
||||
println!("{}", el);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
if line == "\n" {
|
||||
println!("ERROR: {}", err);
|
||||
} else {
|
||||
print!("user> {}", " ".repeat(depth));
|
||||
// Flush the prompt to appear before command
|
||||
let _ = io::stdout().flush();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user