Drop REPL (George Bush voice) "for now"

This commit is contained in:
Dane Johnson 2024-11-18 21:49:43 -06:00
parent 488d7b1edb
commit 782c1c93f0
2 changed files with 4 additions and 31 deletions

View File

@ -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<PathBuf>,
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),
}
}

View File

@ -198,11 +198,6 @@ pub fn parse(prgm: &str) -> Vec<Stmt> {
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 {