Pretty print literals partially

This commit is contained in:
Joscha 2022-11-20 22:22:32 +01:00
parent 03e7f10739
commit 4156006ada
3 changed files with 19 additions and 1 deletions

View file

@ -1,3 +1,4 @@
mod basic;
mod expr;
mod lit;
mod program;

View file

@ -5,7 +5,7 @@ use crate::ast::Expr;
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Expr {
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
match self {
Self::Lit(lit) => allocator.text("<lit>"),
Self::Lit(lit) => lit.pretty(allocator),
Self::Call(call) => allocator.text("<call>"),
Self::Field(field) => allocator.text("<field>"),
Self::Var(var) => allocator.text("<var>"),

17
src/pretty/lit.rs Normal file
View file

@ -0,0 +1,17 @@
use pretty::{DocAllocator, DocBuilder, Pretty};
use crate::ast::Lit;
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Lit {
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
match self {
Self::Nil(_) => allocator.text("nil"),
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::String(string) => allocator.text("<string>"),
Self::Table(table) => allocator.text("<table>"),
}
}
}