Added infrastructure for reading files
This commit is contained in:
parent
f014c1a9d9
commit
231de69084
20
src/main.rs
20
src/main.rs
@ -19,13 +19,29 @@ mod eval;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
println!("Schala v 0.02");
|
||||
if let Some(filename) = args.get(1) {
|
||||
let mut source_file = File::open(&Path::new(filename)).unwrap();
|
||||
let mut buffer = String::new();
|
||||
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 {
|
||||
println!("Schala v 0.02");
|
||||
let initial_state = InterpreterState {
|
||||
show_tokens: false,
|
||||
show_parse: false,
|
||||
|
Loading…
Reference in New Issue
Block a user