Wire functions through everything, with some unimplemented, and add a basic scoped map.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::syntax::ast::{Expression, Program, Statement, Value};
|
||||
use pretty::{DocAllocator, DocBuilder, Pretty};
|
||||
|
||||
use super::ConstantType;
|
||||
use super::{ConstantType, TopLevel};
|
||||
|
||||
impl<'a, 'b, D, A> Pretty<'a, D, A> for &'b Program
|
||||
where
|
||||
@@ -11,9 +11,9 @@ where
|
||||
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D, A> {
|
||||
let mut result = allocator.nil();
|
||||
|
||||
for stmt in self.statements.iter() {
|
||||
for tl in self.items.iter() {
|
||||
result = result
|
||||
.append(stmt.pretty(allocator))
|
||||
.append(tl.pretty(allocator))
|
||||
.append(allocator.text(";"))
|
||||
.append(allocator.hardline());
|
||||
}
|
||||
@@ -22,6 +22,32 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, D, A> Pretty<'a, D, A> for &'b TopLevel
|
||||
where
|
||||
A: 'a,
|
||||
D: ?Sized + DocAllocator<'a, A>,
|
||||
{
|
||||
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D, A> {
|
||||
match self {
|
||||
TopLevel::Statement(stmt) => stmt.pretty(allocator),
|
||||
TopLevel::Function(name, arg_names, body) => allocator
|
||||
.text("function")
|
||||
.append(allocator.space())
|
||||
.append(allocator.text(name.to_string()))
|
||||
.append(
|
||||
allocator
|
||||
.intersperse(
|
||||
arg_names.iter().map(|x| allocator.text(x.to_string())),
|
||||
CommaSep {},
|
||||
)
|
||||
.parens(),
|
||||
)
|
||||
.append(allocator.space())
|
||||
.append(body.pretty(allocator)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, D, A> Pretty<'a, D, A> for &'b Statement
|
||||
where
|
||||
A: 'a,
|
||||
|
||||
Reference in New Issue
Block a user