Simplify boxing Expr
This commit is contained in:
parent
5a977e6dde
commit
42369628b6
16 changed files with 68 additions and 62 deletions
|
|
@ -38,7 +38,7 @@ impl Call {
|
|||
expr,
|
||||
s0,
|
||||
s1,
|
||||
arg: Box::new(Expr::Lit(Lit::Nil(span))),
|
||||
arg: Expr::Lit(Lit::Nil(span)).boxed(),
|
||||
s2: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
|
|
@ -55,7 +55,7 @@ impl Call {
|
|||
expr,
|
||||
s0,
|
||||
s1: Space::empty(span),
|
||||
arg: Box::new(Expr::TableConstr(constr)),
|
||||
arg: Expr::TableConstr(constr).boxed(),
|
||||
s2: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl Field {
|
|||
.then(TableConstrElem::Lit(TableLitElem::Positional(index)))
|
||||
.table_constr();
|
||||
let new = Expr::Call(Call::Constr {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Get, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Get, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
constr,
|
||||
span,
|
||||
|
|
@ -44,7 +44,7 @@ impl Field {
|
|||
.then(TableConstrElem::Lit(TableLitElem::Positional(value)))
|
||||
.table_constr();
|
||||
let new = Expr::Call(Call::Constr {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Set, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Set, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
constr,
|
||||
span,
|
||||
|
|
@ -65,7 +65,7 @@ impl Field {
|
|||
expr,
|
||||
s0,
|
||||
s1,
|
||||
index: Box::new(Expr::Lit(Lit::String(StringLit::from_ident(ident)))),
|
||||
index: Expr::Lit(Lit::String(StringLit::from_ident(ident))).boxed(),
|
||||
s2: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
|
|
@ -88,7 +88,7 @@ impl Field {
|
|||
expr,
|
||||
s0,
|
||||
s1,
|
||||
index: Box::new(Expr::Lit(Lit::String(StringLit::from_ident(ident)))),
|
||||
index: Expr::Lit(Lit::String(StringLit::from_ident(ident))).boxed(),
|
||||
s2: Space::empty(span),
|
||||
s3: s2,
|
||||
s4: s3,
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ impl FuncDef {
|
|||
span,
|
||||
})
|
||||
.table_lit();
|
||||
let quote = Box::new(Expr::Lit(Lit::Table(quote)));
|
||||
let quote = Expr::Lit(Lit::Table(quote)).boxed();
|
||||
let scope = Expr::Call(Call::NoArg {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Scope, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Scope, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
|
|
@ -36,7 +36,7 @@ impl FuncDef {
|
|||
name: Ident::new("scope", span),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: Box::new(scope),
|
||||
value: scope.boxed(),
|
||||
span,
|
||||
}))
|
||||
.table_constr(),
|
||||
|
|
@ -56,7 +56,7 @@ impl FuncDef {
|
|||
// `function s0 ( s1 arg s2 ) s3 body`
|
||||
// -> `function ( ) '{ local arg = 'arg(), body }`
|
||||
let arg_call = Expr::Call(Call::NoArg {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Arg, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Arg, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
|
|
@ -66,18 +66,18 @@ impl FuncDef {
|
|||
name: arg,
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: Box::new(arg_call),
|
||||
value: arg_call.boxed(),
|
||||
span,
|
||||
});
|
||||
let body = BoundedSeparated::new(span)
|
||||
.then(TableLitElem::Positional(Box::new(arg_assign)))
|
||||
.then(TableLitElem::Positional(arg_assign.boxed()))
|
||||
.then(TableLitElem::Positional(body))
|
||||
.table_lit();
|
||||
let new = Expr::FuncDef(Self::AnonNoArg {
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
s2: Space::empty(span),
|
||||
body: Box::new(Expr::Lit(Lit::Table(body))),
|
||||
body: Expr::Lit(Lit::Table(body)).boxed(),
|
||||
span,
|
||||
});
|
||||
(new, true)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ impl TableLitElem {
|
|||
match self {
|
||||
Self::Positional(expr) => {
|
||||
let (expr, desugared) = expr.desugar();
|
||||
(Self::Positional(Box::new(expr)), desugared)
|
||||
(Self::Positional(expr.boxed()), desugared)
|
||||
}
|
||||
|
||||
Self::Named {
|
||||
|
|
@ -20,7 +20,7 @@ impl TableLitElem {
|
|||
name,
|
||||
s0,
|
||||
s1,
|
||||
value: Box::new(value),
|
||||
value: value.boxed(),
|
||||
span,
|
||||
};
|
||||
(new, desugared)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl TableConstr {
|
|||
name: Ident::new("raw", span),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: Box::new(Expr::Lit(Lit::Table(elems.table_lit()))),
|
||||
value: Expr::Lit(Lit::Table(elems.table_lit())).boxed(),
|
||||
span,
|
||||
};
|
||||
let mut expr = Expr::Lit(Lit::Table(
|
||||
|
|
@ -36,7 +36,7 @@ impl TableConstr {
|
|||
// -> `expr s0 [ s1 index s2 ] s3 = s4 s5 value`
|
||||
for (s0, (s1, index, s2, s3, s4, value, span), s5) in setters {
|
||||
expr = Expr::Field(Field::Assign {
|
||||
expr: Box::new(expr),
|
||||
expr: expr.boxed(),
|
||||
s0,
|
||||
s1,
|
||||
index,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ fn pattern_to_constr(pattern: TablePattern) -> TableConstr {
|
|||
.0
|
||||
.map(|e| match e {
|
||||
TablePatternElem::Positional(ident) => TableConstrElem::Lit(TableLitElem::Positional(
|
||||
Box::new(Expr::Lit(Lit::String(StringLit::from_ident(ident)))),
|
||||
Expr::Lit(Lit::String(StringLit::from_ident(ident))).boxed(),
|
||||
)),
|
||||
|
||||
TablePatternElem::Named {
|
||||
|
|
@ -22,7 +22,7 @@ fn pattern_to_constr(pattern: TablePattern) -> TableConstr {
|
|||
name,
|
||||
s0,
|
||||
s1,
|
||||
value: Box::new(Expr::Lit(Lit::String(StringLit::from_ident(ident)))),
|
||||
value: Expr::Lit(Lit::String(StringLit::from_ident(ident))).boxed(),
|
||||
span,
|
||||
}),
|
||||
})
|
||||
|
|
@ -41,22 +41,22 @@ impl TableDestr {
|
|||
} = self;
|
||||
|
||||
let mut constr = BoundedSeparated::new(span)
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(Box::new(
|
||||
Expr::TableConstr(pattern_to_constr(pattern)),
|
||||
))))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(
|
||||
Expr::TableConstr(pattern_to_constr(pattern)).boxed(),
|
||||
)))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(value)));
|
||||
if local.is_some() {
|
||||
constr = constr.then(TableConstrElem::Lit(TableLitElem::Named {
|
||||
name: Ident::new("local", span),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
value: Box::new(Expr::Lit(Lit::Bool(true, span))),
|
||||
value: Expr::Lit(Lit::Bool(true, span)).boxed(),
|
||||
span,
|
||||
}));
|
||||
}
|
||||
|
||||
let new = Expr::Call(Call::Constr {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Destructure, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Destructure, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
constr: constr.table_constr(),
|
||||
span,
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ impl Var {
|
|||
// `[ s0 index s1 ]`
|
||||
// -> `'scope()[ s0 index s1 ]`
|
||||
let scope = Expr::Call(Call::NoArg {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Scope, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Scope, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
let new = Expr::Field(Field::Access {
|
||||
expr: Box::new(scope),
|
||||
expr: scope.boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: s0,
|
||||
index,
|
||||
|
|
@ -45,13 +45,13 @@ impl Var {
|
|||
// `[ s0 index s1 ] s2 = s3 value`
|
||||
// -> `'scope()[ s0 index s1 ] s2 = s3 value`
|
||||
let scope = Expr::Call(Call::NoArg {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Scope, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Scope, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
let new = Expr::Field(Field::Assign {
|
||||
expr: Box::new(scope),
|
||||
expr: scope.boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: s0,
|
||||
index,
|
||||
|
|
@ -75,20 +75,20 @@ impl Var {
|
|||
span,
|
||||
} => {
|
||||
let scope = Expr::Call(Call::NoArg {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::Scope, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::Scope, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
let constr = BoundedSeparated::new(span)
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(Box::new(
|
||||
scope,
|
||||
))))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(
|
||||
scope.boxed(),
|
||||
)))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(index)))
|
||||
.then(TableConstrElem::Lit(TableLitElem::Positional(value)))
|
||||
.table_constr();
|
||||
let new = Expr::Call(Call::Constr {
|
||||
expr: Box::new(Expr::Lit(Lit::Builtin(Builtin::SetRaw, span))),
|
||||
expr: Expr::Lit(Lit::Builtin(Builtin::SetRaw, span)).boxed(),
|
||||
s0: Space::empty(span),
|
||||
constr,
|
||||
span,
|
||||
|
|
@ -102,7 +102,7 @@ impl Var {
|
|||
let span = name.span();
|
||||
let new = Expr::Var(Self::Access {
|
||||
s0: Space::empty(span),
|
||||
index: Box::new(Expr::Lit(Lit::String(StringLit::from_ident(name)))),
|
||||
index: Expr::Lit(Lit::String(StringLit::from_ident(name))).boxed(),
|
||||
s1: Space::empty(span),
|
||||
span,
|
||||
});
|
||||
|
|
@ -122,7 +122,7 @@ impl Var {
|
|||
let new = Expr::Var(Self::Assign {
|
||||
local,
|
||||
s0: Space::empty(span),
|
||||
index: Box::new(Expr::Lit(Lit::String(StringLit::from_ident(name)))),
|
||||
index: Expr::Lit(Lit::String(StringLit::from_ident(name))).boxed(),
|
||||
s1: Space::empty(span),
|
||||
s2: s0,
|
||||
s3: s1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue