Added infrastructure for reading files

This commit is contained in:
greg 2016-01-24 22:25:12 -08:00
parent f014c1a9d9
commit 231de69084

View File

@ -19,13 +19,29 @@ mod eval;
fn main() { fn main() {
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
println!("Schala v 0.02");
if let Some(filename) = args.get(1) { if let Some(filename) = args.get(1) {
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();
panic!("Not implemented yet");
let tokens = match tokenize(&buffer) {
Some(t) => t,
None => { println!("Tokenization error"); return; }
};
let ast = match parse(&tokens, &[]) {
Ok(ast) => ast,
Err(err) => { println!("Parse error: {:?}", err); return; }
};
let mut evaluator = Evaluator::new();
let results = evaluator.run(ast);
for result in results.iter() {
println!("{}", result);
}
} else { } else {
println!("Schala v 0.02");
let initial_state = InterpreterState { let initial_state = InterpreterState {
show_tokens: false, show_tokens: false,
show_parse: false, show_parse: false,