refactor main code
This commit is contained in:
parent
65f64ebcc2
commit
c83df6fd84
20
src/main.rs
20
src/main.rs
@ -79,15 +79,27 @@ fn main() {
|
|||||||
repl.run();
|
repl.run();
|
||||||
}
|
}
|
||||||
[_, ref filename, _..] => {
|
[_, ref filename, _..] => {
|
||||||
run_noninteractive(filename, options);
|
|
||||||
|
run_noninteractive(filename, languages, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_noninteractive(filename: &str, options: EvalOptions) {
|
fn run_noninteractive(filename: &str, languages: Vec<Box<ProgrammingLanguageInterface>>, options: EvalOptions) {
|
||||||
let mut language = maaru_lang::Maaru::new();
|
let path = Path::new(filename);
|
||||||
let mut source_file = File::open(&Path::new(filename)).unwrap();
|
let ext = path.extension().and_then(|e| e.to_str()).unwrap_or_else(|| {
|
||||||
|
println!("Source file lacks extension");
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
let mut language = Box::new(languages.into_iter().find(|lang| lang.get_source_file_suffix() == ext)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
println!("Extension .{} not recognized", ext);
|
||||||
|
exit(1);
|
||||||
|
}));
|
||||||
|
|
||||||
|
let mut source_file = File::open(path).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();
|
||||||
|
|
||||||
if options.compile {
|
if options.compile {
|
||||||
|
Loading…
Reference in New Issue
Block a user