use crftng_intrprtrs::run; use std::{fs, io, path}; use tracing::Level; use tracing_subscriber::{EnvFilter, FmtSubscriber}; fn run_file(file: &path::Path) -> Result<(), io::Error> { let src = fs::read_to_string(file)?; run(&src).unwrap(); Ok(()) } fn run_repl() { let mut line_buf = String::new(); loop { match io::stdin().read_line(&mut line_buf) { Ok(n) => { // Check for EOF if n == 0 { break; } let line = line_buf.trim(); if !line.is_empty() { match run(line) { Ok(v) => println!("{:?}", v), Err(e) => println!("{}", e), } line_buf.clear(); } } Err(e) => panic!("{:?}", e), } } } fn main() { dotenv::dotenv().ok(); color_eyre::install().expect("Failed to install color-eyre"); let subscriber = FmtSubscriber::builder() .with_max_level(Level::TRACE) .with_env_filter(EnvFilter::from_env("LOG")) .finish(); tracing::subscriber::set_global_default(subscriber).unwrap(); if let Some(file) = std::env::args_os().nth(1) { run_file(file.as_ref()).unwrap(); } else { run_repl() } }