From ef2f7b6121941b666f94668fbf521533f8447de7 Mon Sep 17 00:00:00 2001 From: Lloyd Date: Fri, 29 Aug 2025 02:32:22 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=99=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 2 +- src/parser.rs | 17 +---------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c41f55..cc38f07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,5 +12,5 @@ fn main() { let mut t = Tokenizer::new(&input).unwrap(); println!("{:?}", t.tokens); let ast = parser::parse(&mut t).unwrap(); - println!("{}", ast.pretty_tree()); + println!("{}", ast.pretty()); } diff --git a/src/parser.rs b/src/parser.rs index 6f1bc2a..b9ee14b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -52,22 +52,7 @@ impl fmt::Display for Expr { } impl Expr { - pub fn pretty(&self, indent: usize) -> String { - let pad = " ".repeat(indent); - match self { - Expr::Literal(lit) => format!("{pad}Literal({lit:?})"), - Expr::Group(expr) => format!("{pad}Group(\n{}\n{pad})", expr.pretty(indent + 1)), - Expr::Prefix { op, expr } => { - format!("{pad}Prefix({op:?}\n{}\n{pad})", expr.pretty(indent + 1)) - } - Expr::Infix { op, lhs, rhs } => format!( - "{pad}Infix({op:?}\n{}\n{}\n{pad})", - lhs.pretty(indent + 1), - rhs.pretty(indent + 1) - ), - } - } - pub fn pretty_tree(&self) -> String { + pub fn pretty(&self) -> String { // entry point for users — root printed without └── let mut result = String::new(); result.push_str(&format!("{}\n", self.node_name()));