From 782c1c93f02c11814b72e03dde560719502e44c2 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Mon, 18 Nov 2024 21:49:43 -0600 Subject: [PATCH] Drop REPL (George Bush voice) "for now" --- src/main.rs | 30 ++++-------------------------- src/parser.rs | 5 ----- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/main.rs b/src/main.rs index c09eb15..0e79a81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use std::path::PathBuf; #[clap(author, version, about = "Compiler for Deelang")] struct Cli { #[clap(help="Specify a file to compile")] - file: Option, + file: PathBuf, #[clap(short, long, help="Emit a parse tree")] parse: bool, #[clap(short, long, help="Cross-compile to ECMAScript")] @@ -22,23 +22,9 @@ struct Cli { preprocess: bool, } -fn repl(cli: &Cli) { - let mut toplevel = emitter::LexicalContext::toplevel(); - let mut out = io::stdout(); - loop { - let mut line = String::new(); - io::stdin().read_line(&mut line).unwrap(); - let tree = parser::parse_stmt(&line); - if cli.parse { - println!("{:#?}", tree); - } else if cli.ecmascript { - emitter::emit(&mut out, &tree, &mut toplevel).ok(); - } - }; -} - -fn script(cli: &Cli) { - let mut file = File::open(cli.file.as_ref().unwrap()).expect("Could not read file"); +fn main() { + let cli = Cli::parse(); + let mut file = File::open(&cli.file).expect("Could not read file"); let mut prgm = String::new(); file.read_to_string(&mut prgm).unwrap(); if cli.preprocess { @@ -55,11 +41,3 @@ fn script(cli: &Cli) { emitter::emit_all(&mut out, &tree, &mut toplevel).ok(); } } - -fn main() { - let cli = Cli::parse(); - match cli.file { - None => repl(&cli), - Some(_) => script(&cli), - } -} diff --git a/src/parser.rs b/src/parser.rs index 399092f..cd82081 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -198,11 +198,6 @@ pub fn parse(prgm: &str) -> Vec { deelang_parser::program(&prgm).unwrap() } -pub fn parse_stmt(stmt: &str) -> Stmt { - let stmt = preprocess(stmt); - deelang_parser::stmt(&stmt).unwrap() -} - impl fmt::Display for Stmt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self {