work
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user