This commit is contained in:
2024-10-06 12:42:46 -04:00
parent 148ad00c83
commit e5aea8b24e
26 changed files with 1338 additions and 613 deletions

View File

@@ -1,39 +1,15 @@
use std::{
ffi::OsStr,
io::{BufRead, BufReader},
};
mod parser;
mod token;
mod util;
use parser::{print_error, Expr, Module, TokenCursor};
mod v1;
mod v2;
fn main() {
let arg = std::env::args_os().nth(1);
if let Some(file) = arg {
run_file(&file);
if let Some(path) = arg {
let file = std::fs::read_to_string(path).expect("failed to read file");
println!("{file}");
v1::parse_file(&file);
// v2::parse_file(&file);
} else {
run_stdin();
}
}
fn run_file(path: &OsStr) {
let file = std::fs::read_to_string(path).expect("failed to read file");
let tokens = token::parse(&file).unwrap();
match Module::parse(&mut TokenCursor::from(tokens.as_slice())) {
Err(err) => print_error(err, &file),
Ok(module) => println!("{module:#?}"),
}
}
fn run_stdin() {
for line in BufReader::new(std::io::stdin()).lines() {
let str = &line.expect("failed to read line");
let tokens = token::parse(str).unwrap();
println!(
"{:?}",
Expr::parse(&mut TokenCursor::from(tokens.as_slice()))
);
v1::run_stdin();
}
}