This commit is contained in:
2026-04-11 15:21:03 -04:00
parent 229b026573
commit 2582e8c87e
15 changed files with 301 additions and 199 deletions
+29
View File
@@ -0,0 +1,29 @@
use super::*;
pub struct Func {
args: Vec<Id<Ident>>,
body: Id<Expr>,
}
impl Parsable for Func {
fn parse(ctx: &mut ParseCtx) -> Result<Self, CompilerMsg> {
ctx.expect(Token::OpenParen)?;
let args = ctx.list(Token::Comma, Token::CloseParen)?;
let body = ctx.parse()?;
Ok(Self { args, body })
}
}
impl FmtNode for Func {
fn fmt(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result {
write!(f, "(")?;
if let Some((last, rest)) = self.args.split_last() {
for arg in rest {
write!(f, "{}, ", arg.dsp(ctx))?;
}
write!(f, "{}", last.dsp(ctx))?;
}
write!(f, ") {}", self.body.dsp(ctx))?;
Ok(())
}
}