Simplify creating Expr
This commit is contained in:
parent
42369628b6
commit
fafc567447
15 changed files with 163 additions and 112 deletions
|
|
@ -22,25 +22,24 @@ impl FuncDef {
|
|||
span,
|
||||
})
|
||||
.table_lit();
|
||||
let quote = Expr::Lit(Lit::Table(quote)).boxed();
|
||||
let scope = Expr::Call(Call::NoArg {
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Scope, span)).boxed(),
|
||||
let quote = Lit::Table(quote).expr().boxed();
|
||||
let scope = Call::NoArg {
|
||||
expr: Lit::Builtin(Builtin::Scope, span).expr().boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
let new = Expr::TableConstr(
|
||||
BoundedSeparated::new(span)
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(quote)))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Named {
|
||||
name: Ident::new("scope", span),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: scope.boxed(),
|
||||
span,
|
||||
}))
|
||||
.table_constr(),
|
||||
);
|
||||
};
|
||||
let new = BoundedSeparated::new(span)
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(quote)))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Named {
|
||||
name: Ident::new("scope", span),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: scope.expr().boxed(),
|
||||
span,
|
||||
}))
|
||||
.table_constr()
|
||||
.expr();
|
||||
(new, true)
|
||||
}
|
||||
|
||||
|
|
@ -55,32 +54,32 @@ impl FuncDef {
|
|||
} => {
|
||||
// `function s0 ( s1 arg s2 ) s3 body`
|
||||
// -> `function ( ) '{ local arg = 'arg(), body }`
|
||||
let arg_call = Expr::Call(Call::NoArg {
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Arg, span)).boxed(),
|
||||
let arg_call = Call::NoArg {
|
||||
expr: Lit::Builtin(Builtin::Arg, span).expr().boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
let arg_assign = Expr::Var(Var::AssignIdent {
|
||||
};
|
||||
let arg_assign = Var::AssignIdent {
|
||||
local: Some(Space::empty(span)),
|
||||
name: arg,
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: arg_call.boxed(),
|
||||
value: arg_call.expr().boxed(),
|
||||
span,
|
||||
});
|
||||
};
|
||||
let body = BoundedSeparated::new(span)
|
||||
.then(TableLitElem::Positional(arg_assign.boxed()))
|
||||
.then(TableLitElem::Positional(arg_assign.expr().boxed()))
|
||||
.then(TableLitElem::Positional(body))
|
||||
.table_lit();
|
||||
let new = Expr::FuncDef(Self::AnonNoArg {
|
||||
let new = Self::AnonNoArg {
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
s2: Space::empty(span),
|
||||
body: Expr::Lit(Lit::Table(body)).boxed(),
|
||||
body: Lit::Table(body).expr().boxed(),
|
||||
span,
|
||||
});
|
||||
(new, true)
|
||||
};
|
||||
(new.expr(), true)
|
||||
}
|
||||
|
||||
Self::AnonDestr {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue