diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 2072a31..20260cd 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -336,43 +336,3 @@ impl LogicalOp { Spanned::new(Self::Or, span) } } - -impl Expr { - pub fn print_rpn(&self) -> String { - match self { - Expr::Binary { left, op, right } => { - let left = left.print_rpn(); - let right = right.print_rpn(); - format!("({} {left} {right})", op.as_ref()) - } - Expr::Grouping { inner } => format!("({})", inner.print_rpn()), - Expr::Literal { lit } => match lit.as_ref() { - Literal::String(s) => format!("\"{s}\""), - Literal::Number(n) => format!("{n}"), - Literal::Bool(b) => format!("{b}"), - Literal::Nil => "nil".to_string(), - }, - Expr::Unary { op, expr } => match op.as_ref() { - UnaryOp::Negative => format!("(- {})", expr.print_rpn()), - UnaryOp::Invert => format!("(! {})", expr.print_rpn()), - }, - Expr::Var { name } => name.as_ref().to_string(), - Expr::Assignment { target, value } => match target.as_ref() { - Lval::Ident { name } => format!("set {} ({})", name, value.print_rpn()), - }, - Expr::Logical { left, op, right } => { - let left = left.print_rpn(); - let right = right.print_rpn(); - format!("({} {left} {right})", op.as_ref()) - } - Expr::Call { callee, arguments } => { - let arguments = arguments - .iter() - .map(|a| a.as_ref().print_rpn()) - .collect::>() - .join(" "); - format!("(call {} {arguments})", callee.print_rpn()) - } - } - } -} diff --git a/src/ast/mod.rs b/src/ast/mod.rs index f26f56d..5320e27 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -8,25 +8,3 @@ pub use stmt::Stmt; #[derive(Clone, Debug)] pub struct Ast(pub Vec>); - -impl Ast { - pub fn print_rpn(&self) -> String { - self.0 - .iter() - .map(|s| match s.as_ref() { - Stmt::Expr(e) => e.print_rpn(), - Stmt::Print(e) => format!("print {}", e.print_rpn()), - Stmt::VarDecl { - name, - initializer: Some(e), - } => format!("set {name} {}", e.print_rpn()), - Stmt::Function { name, .. } => format!("(fun {name})"), - Stmt::VarDecl { name, .. } => format!("set {name}"), - Stmt::Block(_) => "block".to_string(), - Stmt::If { .. } => "if".to_string(), - Stmt::While { .. } => "while".to_string(), - }) - .collect::>() - .join("\n") - } -} diff --git a/src/runners/repl.rs b/src/runners/repl.rs index 7a899c2..ecfe62b 100644 --- a/src/runners/repl.rs +++ b/src/runners/repl.rs @@ -59,7 +59,6 @@ pub fn run_repl() -> Result<()> { continue; } }; - println!("{}", ast.print_rpn()); if let Err(e) = interpreter.interpret(&ast) { let report = Report::new(e).with_source_code(line.clone());