use clap::{Parser, Subcommand}; use hencelisp::*; use std::fs; #[derive(Debug, Parser)] #[clap(author, version, about, long_about = None)] struct Cli { #[clap(subcommand)] commands: Commands, } #[derive(Debug, Subcommand)] enum Commands { #[clap(about = "Lexes source code and outputs tokens")] Lex { #[clap(value_parser)] src: String, }, #[clap(about = "Parses source code and outputs AST")] Parse { #[clap(value_parser)] src: String, }, #[clap(about = "Compiles source code to hence assembly")] Compile { #[clap(value_parser)] src: String, #[clap(value_parser)] out: Option, #[clap(long, action)] dump: bool, }, } fn main() { let args = Cli::parse(); match args.commands { Commands::Lex { src } => { let source = fs::read_to_string(src).unwrap(); let tokens = lexer::lex(source).unwrap(); dbg!(tokens); } Commands::Parse { src } => { let source = fs::read_to_string(src).unwrap(); let tokens = lexer::lex(source).unwrap(); let ast = parser::parse(tokens).unwrap(); dbg!(ast); } Commands::Compile { src, out, dump } => { let source = fs::read_to_string(src).unwrap(); let tokens = lexer::lex(source).unwrap(); let ast = parser::parse(tokens).unwrap(); let mut data = compiler::Data::new(); compiler::compile(ast, &mut data).unwrap(); dbg!(data); } } }