From c03ec9e5f46008a0f17fe2db2abec9301d1dbae3 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sat, 22 Jan 2022 06:53:56 +0700 Subject: [PATCH] fix: better list & vector fmt --- src/main.rs | 4 +++- src/token.rs | 18 +++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9062b55..e2e2618 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,9 @@ fn main() { // Everything is in a List(..) so we need to get it out and make it into // a vector of Expr instead, so we can compile it. let a = util::unwrap_list_nest(ast.unwrap()); - println!("{:#?}", a); + for e in a.iter() { + println!("{}", e); + } // TODO: compile to something else.. } } diff --git a/src/token.rs b/src/token.rs index fadd65c..6d1d3eb 100644 --- a/src/token.rs +++ b/src/token.rs @@ -20,22 +20,10 @@ impl std::fmt::Display for Expr { Expr::Null => write!(f, "Null"), Expr::Bool(b) => write!(f, "{}", b), Expr::Number(n) => write!(f, "{}", n), - Expr::String(s) => write!(f, "{}", unescape(s.to_string())), + Expr::String(s) => write!(f, "\"{}\"", unescape(s.to_string())), Expr::Symbol(s) => write!(f, "{}", s), - Expr::List(l, _) => { - write!(f, "(")?; - for e in l.iter() { - write!(f, "{}", e)?; - } - write!(f, ")") - } - Expr::Vector(l, _) => { - write!(f, "[")?; - for e in l.iter() { - write!(f, "{}", e)?; - } - write!(f, "]") - } + Expr::List(l, _) => write!(f, "({})", l.iter().map(|e| format!("{}", e)).collect::>().join(" ")), + Expr::Vector(l, _) => write!(f, "[{}]", l.iter().map(|e| format!("{}", e)).collect::>().join(", ")), } } }