[fine] Re-work compiler main, checking is everything

This commit is contained in:
John Doty 2024-01-11 06:32:23 -08:00
parent 5c05077312
commit d8db65af55
3 changed files with 67 additions and 30 deletions

View file

@ -1,4 +1,32 @@
use std::fs;
use parser::parse;
use semantics::{check, Semantics};
pub mod compiler;
pub mod parser;
pub mod semantics;
pub mod tokens;
pub mod vm;
pub fn process_file(file: &str) {
let source = match fs::read_to_string(file) {
Ok(c) => c,
Err(e) => {
eprintln!("Unable to read file {file}: {e}");
return;
}
};
// What am I doing here?
let (tree, lines) = parse(&source);
let semantics = Semantics::new(&tree, &lines);
check(&semantics);
// OK now there might be errors.
let mut errors = semantics.snapshot_errors();
errors.reverse();
for e in errors {
eprintln!("{file}: {}:{}: {}", e.start.0, e.start.1, e.message);
}
}