mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-13 01:35:31 +01:00
Multiple expressions can be evaluated on a single line Signed-off-by: teo3300 <matteo.rogora@live.it>
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
// io lib to read input and print output
|
|
use std::io::{self, Write};
|
|
|
|
mod printer;
|
|
mod reader;
|
|
mod types;
|
|
|
|
mod step1_read_print;
|
|
use step1_read_print::rep;
|
|
|
|
fn main() -> io::Result<()> {
|
|
loop {
|
|
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)?;
|
|
|
|
if line == "\n" {
|
|
break;
|
|
}
|
|
|
|
input.push_str(&line);
|
|
|
|
// Perform rep on whole available input
|
|
match rep(&input) {
|
|
Ok(output) => {
|
|
for el in output {
|
|
println!("{}", el);
|
|
}
|
|
}
|
|
Err(err) => {
|
|
if line == "\n" {
|
|
println!("ERROR: {}", err);
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|