From 81e2a28b0643097868e2e762c9f3c2a008df3c90 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 20 Nov 2022 23:45:28 +0100 Subject: [PATCH] Pretty print function calls --- src/pretty.rs | 1 + src/pretty/call.rs | 32 ++++++++++++++++++++++++++++++++ src/pretty/expr.rs | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/pretty/call.rs diff --git a/src/pretty.rs b/src/pretty.rs index 3a21e41..bede489 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -1,4 +1,5 @@ mod basic; +mod call; mod expr; mod lit; mod program; diff --git a/src/pretty/call.rs b/src/pretty/call.rs new file mode 100644 index 0000000..84d2b5b --- /dev/null +++ b/src/pretty/call.rs @@ -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)), + } + } +} diff --git a/src/pretty/expr.rs b/src/pretty/expr.rs index f366edd..bc8b2a8 100644 --- a/src/pretty/expr.rs +++ b/src/pretty/expr.rs @@ -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(""), + Self::Call(call) => call.pretty(allocator), Self::Field(field) => allocator.text(""), Self::Var(var) => allocator.text(""), Self::TableConstr(constr) => constr.pretty(allocator),