Pretty print function calls

This commit is contained in:
Joscha 2022-11-20 23:45:28 +01:00
parent fc139c31f4
commit 81e2a28b06
3 changed files with 34 additions and 1 deletions

View file

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

32
src/pretty/call.rs Normal file
View file

@ -0,0 +1,32 @@
use pretty::{DocAllocator, DocBuilder, Pretty};
use crate::ast::Call;
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Call {
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
match self {
Self::Arg {
expr,
s0,
s1,
arg,
s2,
span: _,
} => expr
.pretty(allocator)
.append(arg.pretty(allocator).parens()),
Self::NoArg {
expr,
s0,
s1,
span: _,
} => expr.pretty(allocator).append(allocator.nil().parens()),
Self::Constr {
expr,
s0,
constr,
span: _,
} => expr.pretty(allocator).append(constr.pretty(allocator)),
}
}
}

View file

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