diff options
Diffstat (limited to 'crates/rebel-lang/examples/repl.rs')
-rw-r--r-- | crates/rebel-lang/examples/repl.rs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/crates/rebel-lang/examples/repl.rs b/crates/rebel-lang/examples/repl.rs index 0e3debc..07c906f 100644 --- a/crates/rebel-lang/examples/repl.rs +++ b/crates/rebel-lang/examples/repl.rs @@ -51,6 +51,7 @@ fn main() -> rustyline::Result<()> { while let Ok(line) = rl.readline("> ") { rl.add_history_entry(line.as_str())?; + let tokens = match tokenize::token_stream(&line) { Ok(value) => value, Err(err) => { @@ -58,21 +59,37 @@ fn main() -> rustyline::Result<()> { continue; } }; - let expr = match recipe::expr(&tokens) { + let stmt = match recipe::body_stmt(&tokens) { Ok(value) => value, Err(err) => { println!("Parse error: {err}"); continue; } }; - match Type::ast_expr_type(&ctx, &expr) { - Ok(_) => (), - Err(err) => { - println!("Type error: {err:?}"); - continue; + + match &stmt { + rebel_parse::ast::BodyStmt::Assign { dest: _, expr } => { + match Type::ast_expr_type(&ctx, expr) { + Ok(_) => (), + Err(err) => { + println!("Type error: {err:?}"); + continue; + } + }; } - }; - let value = match Value::eval(&ctx, &expr) { + rebel_parse::ast::BodyStmt::Expr { expr } => { + match Type::ast_expr_type(&ctx, expr) { + Ok(_) => (), + Err(err) => { + println!("Type error: {err:?}"); + continue; + } + }; + } + rebel_parse::ast::BodyStmt::Empty => {} + } + + let value = match ctx.run(&stmt) { Ok(value) => value, Err(err) => { println!("Eval error: {err:?}"); |