Split main() into subfunctions
This commit is contained in:
parent
3fe9ec95d5
commit
cd69ebaa9d
11
src/main.rs
11
src/main.rs
@ -21,6 +21,13 @@ mod eval;
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
if let Some(filename) = args.get(1) {
|
||||
run_noninteractive(filename);
|
||||
} else {
|
||||
run_repl();
|
||||
}
|
||||
}
|
||||
|
||||
fn run_noninteractive(filename: &String) {
|
||||
let mut source_file = File::open(&Path::new(filename)).unwrap();
|
||||
let mut buffer = String::new();
|
||||
source_file.read_to_string(&mut buffer).unwrap();
|
||||
@ -40,8 +47,9 @@ fn main() {
|
||||
for result in results.iter() {
|
||||
println!("{}", result);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
fn run_repl() {
|
||||
println!("Schala v 0.02");
|
||||
let initial_state = InterpreterState {
|
||||
show_tokens: false,
|
||||
@ -50,7 +58,6 @@ fn main() {
|
||||
};
|
||||
REPL::with_prompt_and_state(Box::new(repl_handler), ">> ", initial_state)
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
||||
struct InterpreterState {
|
||||
|
Loading…
Reference in New Issue
Block a user