This commit is contained in:
2026-04-11 03:50:43 -04:00
parent 29316e6353
commit 229b026573
16 changed files with 266 additions and 136 deletions
+35
View File
@@ -0,0 +1,35 @@
use super::*;
pub struct Module {
items: Vec<Id<Item>>,
}
impl Parsable for Module {
fn parse(ctx: &mut ParseCtx) -> Result<Self, CompilerMsg> {
let mut items = Vec::new();
if ctx.peek().is_none() {
return Ok(Self { items });
}
items.push(ctx.parse()?);
while *ctx.expect_peek()? == Token::Semicolon {
ctx.next();
items.push(ctx.parse()?);
}
Ok(Self { items })
}
}
impl FmtNode for Module {
fn fmt(&self, f: &mut std::fmt::Formatter, mut ctx: DisplayCtx) -> std::fmt::Result {
ctx.indent += 3;
write!(f, "{{")?;
if !self.items.is_empty() {
writeln!(f)?;
}
for &i in &self.items {
writeln!(f, "{}{};", " ".repeat(ctx.indent), i.dsp(ctx))?;
}
write!(f, "}}")?;
Ok(())
}
}