diff --git a/src/main.rs b/src/main.rs index ad54f61..8fd9a5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,9 @@ fn main() { let calc = &mut Calc::new(); if args.len() > 1 { if args[1].ends_with(".yaiwr") { - run_from_file(&args[1], calc) + let contents = + fs::read_to_string(&args[1]).expect("Should have been able to read the file"); + eval_statement(contents.as_str(), calc); } else { eval_statement(&args[1], calc); } @@ -21,17 +23,6 @@ fn main() { } } -pub fn run_from_file(file_name: &str, calc: &mut Calc) { - let contents = fs::read_to_string(file_name).expect("Should have been able to read the file"); - let lines: Vec<&str> = contents - .split("\n") - .filter(|line| !line.trim().is_empty()) - .collect(); - for line in lines { - eval_statement(line, calc); - } -} - fn repl(calc: &mut Calc) { let stdin = io::stdin(); loop { @@ -52,7 +43,11 @@ fn repl(calc: &mut Calc) { } fn eval_statement(input: &str, calc: &mut Calc) -> Option { - let statements: Vec = input.split(";").map(|x| format!("{};", x)).collect(); + let statements: Vec = input + .replace("\n", "") + .split(";") + .map(|x| format!("{};", x)) + .collect(); let mut result: Option = None; for statement in statements {