Pretty print literals partially
This commit is contained in:
parent
03e7f10739
commit
4156006ada
3 changed files with 19 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
mod basic;
|
mod basic;
|
||||||
mod expr;
|
mod expr;
|
||||||
|
mod lit;
|
||||||
mod program;
|
mod program;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::ast::Expr;
|
||||||
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Expr {
|
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Expr {
|
||||||
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
|
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
|
||||||
match self {
|
match self {
|
||||||
Self::Lit(lit) => allocator.text("<lit>"),
|
Self::Lit(lit) => lit.pretty(allocator),
|
||||||
Self::Call(call) => allocator.text("<call>"),
|
Self::Call(call) => allocator.text("<call>"),
|
||||||
Self::Field(field) => allocator.text("<field>"),
|
Self::Field(field) => allocator.text("<field>"),
|
||||||
Self::Var(var) => allocator.text("<var>"),
|
Self::Var(var) => allocator.text("<var>"),
|
||||||
|
|
|
||||||
17
src/pretty/lit.rs
Normal file
17
src/pretty/lit.rs
Normal 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>"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue