diff --git a/src/main.rs b/src/main.rs index 1b5d639..c1fcefa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ mod logger; -fn main() -> ExitCode { +fn main() -> anyhow::Result<()> { let cli = mclangc::cli::CliArgs::parse(); cli.set_log_level(); cli.validate(); @@ -15,25 +15,16 @@ fn main() -> ExitCode { let fp = PathBuf::from(file); if !fp.exists() { error!("File {fp:?} doesnt exits, exiting"); - return ExitCode::FAILURE; + anyhow::bail!("") } let data = std::fs::read_to_string(fp).unwrap(); info!("Tokenising {file}"); - let Ok(tokens) = mclangc::tokeniser::tokenise(&data, &file) else { - error!("Failed to tokenise file, exiting"); - return ExitCode::FAILURE; - }; + let tokens = mclangc::tokeniser::tokenise(&data, &file)?; info!("Parsing {file}"); - let Ok(prog) = mclangc::parser::parse_program(tokens) else { - error!("Failed to parse file, exiting"); - return ExitCode::FAILURE; - }; + let mut prog = mclangc::parser::parse_program(tokens)?; info!("Validating {file}"); - let Ok(validated) = mclangc::validator::validate_code(&prog) else { - error!("Failed to validate file, exiting"); - return ExitCode::FAILURE; - }; + let validated = mclangc::validator::validate_code(&mut prog)?; } - ExitCode::SUCCESS + Ok(()) }