2022-10-10 20:55:50 +00:00
|
|
|
pub fn read_brainfuck_code(source: &String) -> String {
|
|
|
|
info!("Reading brainfuck source code from file: {}", source);
|
|
|
|
match std::fs::read_to_string(source) {
|
|
|
|
Ok(source) => clean(source),
|
|
|
|
Err(e) => {
|
|
|
|
error!("Failed to read source code file: {}", e);
|
|
|
|
eprintln!("Failed to read source code file: {}", e);
|
|
|
|
std::process::exit(1);
|
2022-10-07 19:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-07 23:06:35 +00:00
|
|
|
}
|
2022-10-08 20:11:13 +00:00
|
|
|
|
|
|
|
fn clean(source: String) -> String {
|
|
|
|
source
|
|
|
|
.chars()
|
|
|
|
.filter(|c| match c {
|
|
|
|
'+' | '-' | '<' | '>' | '[' | ']' | '.' | ',' => true,
|
|
|
|
_ => false,
|
|
|
|
})
|
|
|
|
.collect()
|
|
|
|
}
|