CHECKPOINT: Initial syntax arbitrary implementation.

This commit is contained in:
2024-06-16 20:59:32 -07:00
parent cf7eff7a93
commit 212ca6cc53
13 changed files with 867 additions and 279 deletions

View File

@@ -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>"),
}
}
}