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:
teo3300
2023-06-07 14:41:12 +02:00
parent 9d35d24cd4
commit 54d196582f
5 changed files with 75 additions and 53 deletions

View File

@ -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;
}
}