diff options
author | Qrius <[email protected]> | 2024-09-26 00:11:05 +0200 |
---|---|---|
committer | Qrius <[email protected]> | 2024-09-26 00:11:05 +0200 |
commit | 087fde9d18fc24b8eec7c7191b18c730515f31af (patch) | |
tree | 26e82c38e0dc43241d5b345041e38d3cccb83efe /src/macro_processor | |
parent | ca6571d9d3f1d1961e23691837feb430cbbd0e24 (diff) | |
download | skaldpress-087fde9d18fc24b8eec7c7191b18c730515f31af.tar.gz skaldpress-087fde9d18fc24b8eec7c7191b18c730515f31af.zip |
Add REPL
Diffstat (limited to 'src/macro_processor')
-rw-r--r-- | src/macro_processor/main.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/macro_processor/main.rs b/src/macro_processor/main.rs index 2d34952..5b083c8 100644 --- a/src/macro_processor/main.rs +++ b/src/macro_processor/main.rs @@ -1,9 +1,46 @@ use skaldpress::macro_processor::MacroProcessor; use std::env; use std::fs; +use std::io; +use std::io::Write; + +fn repl() { + println!("=Skaldpress Macro Processor (REPL)"); + println!(" type \"quit\" to exit"); + let mut macro_processor = MacroProcessor::new(); + loop { + let mut input = String::new(); + loop { + print!("> "); + let _ = io::stdout().flush(); + let mut _input = String::new(); + io::stdin().read_line(&mut _input).expect("error: unable to read user input"); + if _input == "\n" { + input.pop(); + break; + } + if _input == "quit\n" { + std::process::exit(0); + } + input.push_str(&_input); + } + println!("\x1b[32m=INPUT\x1b[0m\n{:#?}", input); + println!("\x1b[32m=PROCESSING\x1b[0m"); + match macro_processor.process_input(&input) { + Ok(out) => println!("\x1b[32m=OUTPUT\x1b[0m\n{}", out), + Err(e) => println!("Error {}", e), + } + } +} fn main() { let args: Vec<String> = env::args().collect(); + + if args.len() < 2 { + repl(); + std::process::exit(0); + } + let input_file = match fs::read_to_string(&args[1]) { Ok(x) => x, Err(e) => { |