Desugar function calls without args
This commit is contained in:
parent
52c1aeba35
commit
a3d6efcaec
3 changed files with 71 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
mod basic;
|
||||
mod call;
|
||||
mod expr;
|
||||
mod lit;
|
||||
mod program;
|
||||
|
|
|
|||
67
src/desugar/call.rs
Normal file
67
src/desugar/call.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use crate::ast::{Call, Expr, Lit, Space};
|
||||
use crate::span::HasSpan;
|
||||
|
||||
impl Call {
|
||||
pub fn desugar(self) -> (Expr, bool) {
|
||||
match self {
|
||||
Self::Arg {
|
||||
expr,
|
||||
s0,
|
||||
s1,
|
||||
arg,
|
||||
s2,
|
||||
span,
|
||||
} => {
|
||||
let new = Expr::Call(Self::Arg {
|
||||
expr,
|
||||
s0,
|
||||
s1,
|
||||
arg,
|
||||
s2,
|
||||
span,
|
||||
});
|
||||
(new, false) // TODO Implement
|
||||
}
|
||||
|
||||
Self::NoArg { expr, s0, s1, span } => {
|
||||
let (expr, desugared) = expr.desugar();
|
||||
if desugared {
|
||||
let new = Expr::Call(Self::NoArg {
|
||||
expr: Box::new(expr),
|
||||
s0,
|
||||
s1,
|
||||
span,
|
||||
});
|
||||
return (new, true);
|
||||
}
|
||||
|
||||
let arg_span = s1.span().at_start();
|
||||
let arg = Expr::Lit(Lit::Nil(arg_span));
|
||||
let new = Expr::Call(Self::Arg {
|
||||
expr: Box::new(expr),
|
||||
s0,
|
||||
s1,
|
||||
arg: Box::new(arg),
|
||||
s2: Space::empty(arg_span.at_end()),
|
||||
span,
|
||||
});
|
||||
(new, true)
|
||||
}
|
||||
|
||||
Self::Constr {
|
||||
expr,
|
||||
s0,
|
||||
constr,
|
||||
span,
|
||||
} => {
|
||||
let new = Expr::Call(Self::Constr {
|
||||
expr,
|
||||
s0,
|
||||
constr,
|
||||
span,
|
||||
});
|
||||
(new, false) // TODO Implement
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,8 @@ impl Expr {
|
|||
(Self::Lit(lit), desugared)
|
||||
}
|
||||
|
||||
Self::Call(call) => (Self::Call(call), false), // TODO Implement
|
||||
Self::Call(call) => call.desugar(),
|
||||
|
||||
Self::Field(field) => (Self::Field(field), false), // TODO Implement
|
||||
Self::Var(var) => (Self::Var(var), false), // TODO Implement
|
||||
Self::TableConstr(constr) => (Self::TableConstr(constr), false), // TODO Implement
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue