mod ast; mod parsing; mod typing; use clap::{Parser, Subcommand}; use crate::ast::module::Module; /// Experimental compiler for lila #[derive(Parser, Debug)] #[command(author = "Romain P. ")] #[command(version, about, long_about = None)] struct Cli { #[command(subcommand)] command: Commands, } #[derive(Subcommand, Debug)] enum Commands { Parse { /// Path to the source files files: Vec, /// Dump the AST to stdout #[arg(long)] dump_ast: bool, /// Add missing return types in the AST #[arg(long)] type_check: bool, }, } fn main() { let cli = Cli::parse(); match &cli.command { Commands::Parse { files, dump_ast, type_check, } => { let paths = files.iter().map(std::path::Path::new); let modules: Vec = paths .map(|path| match parsing::parse_file(&path) { Ok(module) => module, Err(e) => panic!("Parsing error: {:#?}", e), }) .collect(); if *type_check { for module in &modules { if let Err(e) = module.type_check() { eprintln!("{}", e); return; } } } if *dump_ast { for module in &modules { println!("{:#?}", &module); } return; } println!("Parsing OK"); } } }