mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Hardcode Read and Echo
This commit is contained in:
parent
6c0e34f5fc
commit
88f8325fb3
2 changed files with 53 additions and 8 deletions
|
@ -2,8 +2,12 @@ extern crate roc;
|
|||
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use roc::expr::Expr::*;
|
||||
use roc::expr::Expr;
|
||||
use roc::eval::eval;
|
||||
use roc::eval::from_evaluated;
|
||||
use roc::parse;
|
||||
use std::io;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let mut file = File::open("test.roc")?;
|
||||
|
@ -13,7 +17,34 @@ fn main() -> std::io::Result<()> {
|
|||
|
||||
let expr = parse::parse_string(contents.as_str()).unwrap();
|
||||
|
||||
println!("\n\u{001B}[4mroc out\u{001B}[24m\n\n{}\n", eval(expr).to_string());
|
||||
match from_evaluated(eval(expr)) {
|
||||
Error(problem) => {
|
||||
println!("\n\u{001B}[4mruntime error\u{001B}[24m\n\n{:?}\n", problem)
|
||||
},
|
||||
ApplyVariant(name, payload) => {
|
||||
match name.as_str() {
|
||||
"Echo" => {
|
||||
println!("{}", payload.unwrap().first().unwrap());
|
||||
},
|
||||
"Read" => {
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input)?;
|
||||
|
||||
println!("[debug] You said: {}", input);
|
||||
},
|
||||
_ => {
|
||||
display_expr(ApplyVariant(name, payload));
|
||||
}
|
||||
}
|
||||
},
|
||||
output => {
|
||||
display_expr(output);
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn display_expr(expr: Expr) {
|
||||
println!("\n\u{001B}[4mroc out\u{001B}[24m\n\n{}\n", expr);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue