Skip to content

Commit

Permalink
removed unused nl split
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel-Durov committed Mar 13, 2023
1 parent 82701a8 commit 09e9e57
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 {
Expand All @@ -52,7 +43,11 @@ fn repl(calc: &mut Calc) {
}

fn eval_statement(input: &str, calc: &mut Calc) -> Option<u64> {
let statements: Vec<String> = input.split(";").map(|x| format!("{};", x)).collect();
let statements: Vec<String> = input
.replace("\n", "")
.split(";")
.map(|x| format!("{};", x))
.collect();

let mut result: Option<u64> = None;
for statement in statements {
Expand Down

0 comments on commit 09e9e57

Please sign in to comment.