diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 9b10502..d0fa1ff 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -242,3 +242,9 @@ impl HasSpan for Expr { } } } + +impl Expr { + pub fn boxed(self) -> Box { + Box::new(self) + } +} diff --git a/src/desugar/call.rs b/src/desugar/call.rs index bef48b1..ec6ab89 100644 --- a/src/desugar/call.rs +++ b/src/desugar/call.rs @@ -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, }); diff --git a/src/desugar/field.rs b/src/desugar/field.rs index c429f87..7bbba62 100644 --- a/src/desugar/field.rs +++ b/src/desugar/field.rs @@ -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, diff --git a/src/desugar/func_def.rs b/src/desugar/func_def.rs index 1b370eb..a40c88d 100644 --- a/src/desugar/func_def.rs +++ b/src/desugar/func_def.rs @@ -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) diff --git a/src/desugar/lit.rs b/src/desugar/lit.rs index f88efa6..9a94278 100644 --- a/src/desugar/lit.rs +++ b/src/desugar/lit.rs @@ -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) diff --git a/src/desugar/table_constr.rs b/src/desugar/table_constr.rs index 42123b1..d4e3b68 100644 --- a/src/desugar/table_constr.rs +++ b/src/desugar/table_constr.rs @@ -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, diff --git a/src/desugar/table_destr.rs b/src/desugar/table_destr.rs index 831464b..6428a3b 100644 --- a/src/desugar/table_destr.rs +++ b/src/desugar/table_destr.rs @@ -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, diff --git a/src/desugar/var.rs b/src/desugar/var.rs index 39af1e5..821860d 100644 --- a/src/desugar/var.rs +++ b/src/desugar/var.rs @@ -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, diff --git a/src/parser/expr.rs b/src/parser/expr.rs index 3bae445..bd2b373 100644 --- a/src/parser/expr.rs +++ b/src/parser/expr.rs @@ -18,7 +18,7 @@ fn atom_paren( .then_ignore(just(')')) .map_with_span(|((s0, inner), s1), span| Expr::Paren { s0, - inner: Box::new(inner), + inner: inner.boxed(), s1, span, }) @@ -63,11 +63,11 @@ fn left_assoc( over.then(op_over.repeated()) .foldl(|left, (s0, op, s1, right)| Expr::BinOp { span: left.span().join(right.span()), - left: Box::new(left), + left: left.boxed(), s0, op, s1, - right: Box::new(right), + right: right.boxed(), }) .boxed() } @@ -89,11 +89,11 @@ fn right_assoc( .then(over) .foldr(|(left, s0, op, s1), right| Expr::BinOp { span: left.span().join(right.span()), - left: Box::new(left), + left: left.boxed(), s0, op, s1, - right: Box::new(right), + right: right.boxed(), }) .boxed() } diff --git a/src/parser/func_def.rs b/src/parser/func_def.rs index 54765f1..3bb273d 100644 --- a/src/parser/func_def.rs +++ b/src/parser/func_def.rs @@ -19,7 +19,7 @@ fn func_def_anon_no_arg( s0, s1, s2, - body: Box::new(body), + body: body.boxed(), span, }) } @@ -45,7 +45,7 @@ fn func_def_anon_arg( arg, s2, s3, - body: Box::new(body), + body: body.boxed(), span, }, ) @@ -65,7 +65,7 @@ fn func_def_anon_destr( s0, pattern, s1, - body: Box::new(body), + body: body.boxed(), span, }) } @@ -94,7 +94,7 @@ fn func_def_named_no_arg( s1, s2, s3, - body: Box::new(body), + body: body.boxed(), span, }, ) @@ -128,7 +128,7 @@ fn func_def_named_arg( arg, s3, s4, - body: Box::new(body), + body: body.boxed(), span, }, ) @@ -157,7 +157,7 @@ fn func_def_named_destr( s1, pattern, s2, - body: Box::new(body), + body: body.boxed(), span, } }) diff --git a/src/parser/lit.rs b/src/parser/lit.rs index 6b09982..e368684 100644 --- a/src/parser/lit.rs +++ b/src/parser/lit.rs @@ -132,7 +132,7 @@ pub fn table_lit_elem( ) -> EParser { let positional = expr .clone() - .map(|value| TableLitElem::Positional(Box::new(value))); + .map(|value| TableLitElem::Positional(value.boxed())); let named = ident .then(space.clone()) @@ -143,7 +143,7 @@ pub fn table_lit_elem( name, s0, s1, - value: Box::new(value), + value: value.boxed(), span, }); diff --git a/src/parser/prefix.rs b/src/parser/prefix.rs index ddae0bd..f53c78f 100644 --- a/src/parser/prefix.rs +++ b/src/parser/prefix.rs @@ -17,7 +17,7 @@ enum Prefix { impl Prefix { fn into_expr(self, span: Span, expr: Expr) -> Expr { - let expr = Box::new(expr); + let expr = expr.boxed(); match self { Self::Neg { minus, s0 } => Expr::Neg { minus, diff --git a/src/parser/suffix.rs b/src/parser/suffix.rs index cb02008..d519c13 100644 --- a/src/parser/suffix.rs +++ b/src/parser/suffix.rs @@ -57,7 +57,7 @@ enum Suffix { impl Suffix { fn into_expr(self, span: Span, expr: Expr) -> Expr { - let expr = Box::new(expr); + let expr = expr.boxed(); match self { Self::CallArg { s0, s1, arg, s2 } => Expr::Call(Call::Arg { expr, @@ -143,7 +143,7 @@ fn suffix_call_arg( .map(|(((s0, s1), arg), s2)| Suffix::CallArg { s0, s1, - arg: Box::new(arg), + arg: arg.boxed(), s2, }) } @@ -180,7 +180,7 @@ fn suffix_field_access( .map(|(((s0, s1), index), s2)| Suffix::FieldAccess { s0, s1, - index: Box::new(index), + index: index.boxed(), s2, }) } @@ -204,11 +204,11 @@ fn suffix_field_assign( |((((((s0, s1), index), s2), s3), s4), value)| Suffix::FieldAssign { s0, s1, - index: Box::new(index), + index: index.boxed(), s2, s3, s4, - value: Box::new(value), + value: value.boxed(), }, ) } @@ -246,7 +246,7 @@ fn suffix_field_assign_ident( ident, s2, s3, - value: Box::new(value), + value: value.boxed(), }, ) } diff --git a/src/parser/table_constr.rs b/src/parser/table_constr.rs index 65abbcb..b294329 100644 --- a/src/parser/table_constr.rs +++ b/src/parser/table_constr.rs @@ -25,11 +25,11 @@ fn table_constr_elem( .map_with_span( |(((((s0, index), s1), s2), s3), value), span| TableConstrElem::Indexed { s0, - index: Box::new(index), + index: index.boxed(), s1, s2, s3, - value: Box::new(value), + value: value.boxed(), span, }, ); diff --git a/src/parser/table_destr.rs b/src/parser/table_destr.rs index 0504513..c215a19 100644 --- a/src/parser/table_destr.rs +++ b/src/parser/table_destr.rs @@ -59,7 +59,7 @@ pub fn table_destr( pattern, s0, s1, - value: Box::new(value), + value: value.boxed(), span, }) .boxed() diff --git a/src/parser/var.rs b/src/parser/var.rs index 80722e1..c5806dc 100644 --- a/src/parser/var.rs +++ b/src/parser/var.rs @@ -14,7 +14,7 @@ fn var_access(space: EParser, expr: EParser) -> impl Parser