Skip to content

Commit

Permalink
moved clean_file to lib.rs to clean input when called as library
Browse files Browse the repository at this point in the history
  • Loading branch information
Joeyh021 committed Feb 27, 2022
1 parent 1569c76 commit 4aefb04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ use unicode_segmentation::UnicodeSegmentation;

mod test;

//remove comments from input string
fn clean_file(file: &str) -> String {
file.lines()
.filter_map(|line: &str| line.split('#').next())
.collect::<Vec<&str>>()
.join("")
}

//parse the unicode graphemes into instruction vec
fn parse(commands: &str) -> Vec<Instruction> {
commands
clean_file(commands)
.graphemes(true)
.filter_map(Instruction::from_glyph)
.collect()
Expand Down
10 changes: 1 addition & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ use std::env;
use std::io::{stdin, BufRead};
use std::path::Path;

//remove comments from file
fn clean_file(file: &str) -> String {
file.lines()
.filter_map(|line: &str| line.split('#').next())
.collect::<Vec<&str>>()
.join("")
}

//get all input from stdin
fn get_input() -> String {
let mut buf = String::new();
Expand Down Expand Up @@ -55,7 +47,7 @@ fn main() {

//run the program
println!("Running OOLANG file: {filename}...");
if let Some(i) = oolang::run_cli(&clean_file(&file), &get_input()) {
if let Some(i) = oolang::run_cli(&file, &get_input()) {
println!("Result: {}", i)
} else {
println!("Your program has no output. Perhaps there was an error?")
Expand Down

0 comments on commit 4aefb04

Please sign in to comment.