CHECKPOINT: Initial syntax arbitrary implementation.
This commit is contained in:
@@ -84,7 +84,10 @@ impl Program {
|
||||
impl TopLevel {
|
||||
pub fn pretty<'a>(&self, allocator: &'a Allocator<'a>) -> DocBuilder<'a, Allocator<'a>> {
|
||||
match self {
|
||||
TopLevel::Expression(expr) => expr.pretty(allocator),
|
||||
TopLevel::Expression(expr) => expr
|
||||
.pretty(allocator)
|
||||
.append(allocator.text(";"))
|
||||
.append(allocator.hardline()),
|
||||
TopLevel::Structure(_, name, fields) => allocator
|
||||
.text("struct")
|
||||
.append(allocator.space())
|
||||
@@ -95,17 +98,24 @@ impl TopLevel {
|
||||
.append(
|
||||
allocator
|
||||
.concat(fields.iter().map(|(name, ty)| {
|
||||
let type_bit = if let Some(ty) = ty {
|
||||
allocator
|
||||
.text(":")
|
||||
.append(allocator.space())
|
||||
.append(ty.pretty(allocator))
|
||||
} else {
|
||||
allocator.nil()
|
||||
};
|
||||
allocator
|
||||
.text(name.to_string())
|
||||
.append(allocator.text(":"))
|
||||
.append(allocator.space())
|
||||
.append(ty.pretty(allocator))
|
||||
.append(type_bit)
|
||||
.append(allocator.text(";"))
|
||||
.append(allocator.hardline())
|
||||
}))
|
||||
.nest(2),
|
||||
)
|
||||
.append(allocator.text("}")),
|
||||
.append(allocator.text("}"))
|
||||
.append(allocator.hardline()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,6 +241,8 @@ impl Value {
|
||||
|
||||
allocator.text(value_str)
|
||||
}
|
||||
|
||||
Value::Void => allocator.text("<void>"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user