checkpoint
This commit is contained in:
@@ -21,47 +21,6 @@ impl TopLevel {
|
||||
pub fn pretty<'a>(&self, allocator: &'a Allocator<'a>) -> DocBuilder<'a, Allocator<'a>> {
|
||||
match self {
|
||||
TopLevel::Expression(expr) => expr.pretty(allocator),
|
||||
TopLevel::Function(name, args, rettype, body) => allocator
|
||||
.text("function")
|
||||
.append(allocator.space())
|
||||
.append(
|
||||
name.as_ref()
|
||||
.map(|x| allocator.text(x.to_string()))
|
||||
.unwrap_or_else(|| allocator.nil()),
|
||||
)
|
||||
.append(
|
||||
allocator
|
||||
.intersperse(
|
||||
args.iter().map(|(x, t)| {
|
||||
allocator.text(x.to_string()).append(
|
||||
t.as_ref()
|
||||
.map(|t| {
|
||||
allocator
|
||||
.text(":")
|
||||
.append(allocator.space())
|
||||
.append(t.pretty(allocator))
|
||||
})
|
||||
.unwrap_or_else(|| allocator.nil()),
|
||||
)
|
||||
}),
|
||||
allocator.text(","),
|
||||
)
|
||||
.parens(),
|
||||
)
|
||||
.append(
|
||||
rettype
|
||||
.as_ref()
|
||||
.map(|rettype| {
|
||||
allocator
|
||||
.space()
|
||||
.append(allocator.text("->"))
|
||||
.append(allocator.space())
|
||||
.append(rettype.pretty(allocator))
|
||||
})
|
||||
.unwrap_or_else(|| allocator.nil()),
|
||||
)
|
||||
.append(allocator.space())
|
||||
.append(body.pretty(allocator)),
|
||||
TopLevel::Structure(_, name, fields) => allocator
|
||||
.text("struct")
|
||||
.append(allocator.space())
|
||||
@@ -148,6 +107,47 @@ impl Expression {
|
||||
.append(allocator.text("="))
|
||||
.append(allocator.space())
|
||||
.append(expr.pretty(allocator)),
|
||||
Expression::Function(_, name, args, rettype, body) => allocator
|
||||
.text("function")
|
||||
.append(allocator.space())
|
||||
.append(
|
||||
name.as_ref()
|
||||
.map(|x| allocator.text(x.to_string()))
|
||||
.unwrap_or_else(|| allocator.nil()),
|
||||
)
|
||||
.append(
|
||||
allocator
|
||||
.intersperse(
|
||||
args.iter().map(|(x, t)| {
|
||||
allocator.text(x.to_string()).append(
|
||||
t.as_ref()
|
||||
.map(|t| {
|
||||
allocator
|
||||
.text(":")
|
||||
.append(allocator.space())
|
||||
.append(t.pretty(allocator))
|
||||
})
|
||||
.unwrap_or_else(|| allocator.nil()),
|
||||
)
|
||||
}),
|
||||
allocator.text(","),
|
||||
)
|
||||
.parens(),
|
||||
)
|
||||
.append(
|
||||
rettype
|
||||
.as_ref()
|
||||
.map(|rettype| {
|
||||
allocator
|
||||
.space()
|
||||
.append(allocator.text("->"))
|
||||
.append(allocator.space())
|
||||
.append(rettype.pretty(allocator))
|
||||
})
|
||||
.unwrap_or_else(|| allocator.nil()),
|
||||
)
|
||||
.append(allocator.space())
|
||||
.append(body.pretty(allocator)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user