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() {
|
fn main() {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
if let Some(filename) = args.get(1) {
|
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 source_file = File::open(&Path::new(filename)).unwrap();
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
source_file.read_to_string(&mut buffer).unwrap();
|
source_file.read_to_string(&mut buffer).unwrap();
|
||||||
@ -40,8 +47,9 @@ fn main() {
|
|||||||
for result in results.iter() {
|
for result in results.iter() {
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
fn run_repl() {
|
||||||
println!("Schala v 0.02");
|
println!("Schala v 0.02");
|
||||||
let initial_state = InterpreterState {
|
let initial_state = InterpreterState {
|
||||||
show_tokens: false,
|
show_tokens: false,
|
||||||
@ -51,7 +59,6 @@ fn main() {
|
|||||||
REPL::with_prompt_and_state(Box::new(repl_handler), ">> ", initial_state)
|
REPL::with_prompt_and_state(Box::new(repl_handler), ">> ", initial_state)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
struct InterpreterState {
|
struct InterpreterState {
|
||||||
show_tokens: bool,
|
show_tokens: bool,
|
||||||
|
Loading…
Reference in New Issue
Block a user