Pretty print numeric literals

This commit is contained in:
Joscha 2022-11-20 22:59:14 +01:00
parent 7833ef533d
commit e6bbb37323
2 changed files with 9 additions and 3 deletions

View file

@ -29,7 +29,7 @@ impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Expr {
Self::Call(call) => allocator.text("<call>"),
Self::Field(field) => allocator.text("<field>"),
Self::Var(var) => allocator.text("<var>"),
Self::TableConstr(constr) => allocator.text("<onstr>"),
Self::TableConstr(constr) => allocator.text("<constr>"),
Self::TableDestr(destr) => allocator.text("<destr>"),
Self::FuncDef(def) => allocator.text("<def>"),
Self::Paren {

View file

@ -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("<num>"),
Self::Num(num) => num.pretty(allocator),
Self::String(string) => allocator.text("<string>"),
Self::Table(table) => allocator.text("<table>"),
}