From e6bbb373230b4729abaa468b43e8a57f0c7847c4 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 20 Nov 2022 22:59:14 +0100 Subject: [PATCH] Pretty print numeric literals --- src/pretty/expr.rs | 2 +- src/pretty/lit.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pretty/expr.rs b/src/pretty/expr.rs index e75b7e8..d402480 100644 --- a/src/pretty/expr.rs +++ b/src/pretty/expr.rs @@ -29,7 +29,7 @@ impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Expr { Self::Call(call) => allocator.text(""), Self::Field(field) => allocator.text(""), Self::Var(var) => allocator.text(""), - Self::TableConstr(constr) => allocator.text(""), + Self::TableConstr(constr) => allocator.text(""), Self::TableDestr(destr) => allocator.text(""), Self::FuncDef(def) => allocator.text(""), Self::Paren { diff --git a/src/pretty/lit.rs b/src/pretty/lit.rs index d58fd24..d4eebb3 100644 --- a/src/pretty/lit.rs +++ b/src/pretty/lit.rs @@ -1,6 +1,12 @@ use pretty::{DocAllocator, DocBuilder, Pretty}; -use crate::ast::Lit; +use crate::ast::{Lit, NumLit}; + +impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for NumLit { + fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> { + allocator.text(format!("{self:?}")) + } +} impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Lit { fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> { @@ -9,7 +15,7 @@ impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Lit { Self::Bool(false, _) => allocator.text("false"), Self::Bool(true, _) => allocator.text("true"), Self::Builtin(builtin, _) => allocator.text(format!("{builtin:?}")), - Self::Num(num) => allocator.text(""), + Self::Num(num) => num.pretty(allocator), Self::String(string) => allocator.text(""), Self::Table(table) => allocator.text(""), }