diff --git a/Cargo.lock b/Cargo.lock index 55cc2a4..1a3f9a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,6 +84,14 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "oyster" version = "0.1.0" +dependencies = [ + "oyster_lineedit", + "oyster_parser", +] + +[[package]] +name = "oyster_lineedit" +version = "0.0.0" [[package]] name = "oyster_parser" diff --git a/crates/oyster/Cargo.toml b/crates/oyster/Cargo.toml index 9cdf166..27099dc 100644 --- a/crates/oyster/Cargo.toml +++ b/crates/oyster/Cargo.toml @@ -4,3 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] +oyster_lineedit = { path = "../oyster_lineedit" } +oyster_parser = { path = "../oyster_parser" } diff --git a/crates/oyster/src/main.rs b/crates/oyster/src/main.rs index e7a11a9..5e6b11c 100644 --- a/crates/oyster/src/main.rs +++ b/crates/oyster/src/main.rs @@ -1,3 +1,14 @@ +use oyster_lineedit::readline; +use oyster_parser::ast::Code; + fn main() { - println!("Hello, world!"); + loop { + let prog = readline("> ").unwrap(); + + if prog.trim() == "exit" { + break; + } + + Code::try_from(prog.as_ref()).unwrap(); + } } diff --git a/crates/oyster_lineedit/Cargo.toml b/crates/oyster_lineedit/Cargo.toml new file mode 100644 index 0000000..ed81f51 --- /dev/null +++ b/crates/oyster_lineedit/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "oyster_lineedit" +version = "0.0.0" +edition = "2021" + +[lib] +doctest = false diff --git a/crates/oyster_lineedit/src/lib.rs b/crates/oyster_lineedit/src/lib.rs new file mode 100644 index 0000000..37efefb --- /dev/null +++ b/crates/oyster_lineedit/src/lib.rs @@ -0,0 +1,11 @@ +use std::io::{self, Write}; + +pub fn readline(prompt: &str) -> Result { + print!("{}", prompt); + io::stdout().flush()?; + + let mut buf = String::new(); + io::stdin().read_line(&mut buf)?; + + Ok(buf) +}