mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
Flesh out expr_lift_spaces, in particular handling DbgStmt properly
This commit is contained in:
parent
5c387857ff
commit
fc74b67d86
5 changed files with 136 additions and 1 deletions
|
@ -1084,11 +1084,109 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => Spaces {
|
||||
Expr::Float(_)
|
||||
| Expr::Num(_)
|
||||
| Expr::NonBase10Int { .. }
|
||||
| Expr::Str(_)
|
||||
| Expr::SingleQuote(_)
|
||||
| Expr::AccessorFunction(_)
|
||||
| Expr::RecordUpdater(_)
|
||||
| Expr::RecordAccess(_, _)
|
||||
| Expr::TupleAccess(_, _)
|
||||
| Expr::Var { .. }
|
||||
| Expr::Underscore(_)
|
||||
| Expr::Crash
|
||||
| Expr::Tag(_)
|
||||
| Expr::OpaqueRef(_)
|
||||
| Expr::Dbg
|
||||
| Expr::Try
|
||||
| Expr::List(_)
|
||||
| Expr::Record(_)
|
||||
| Expr::Tuple(_)
|
||||
| Expr::RecordBuilder { .. }
|
||||
| Expr::RecordUpdate { .. } => Spaces {
|
||||
before: &[],
|
||||
item: *expr,
|
||||
after: &[],
|
||||
},
|
||||
|
||||
Expr::TrySuffix { target, expr } => {
|
||||
let expr_lifted = expr_lift_spaces_after(Parens::InApply, arena, expr);
|
||||
|
||||
Spaces {
|
||||
before: &[],
|
||||
item: Expr::TrySuffix {
|
||||
target: *target,
|
||||
expr: arena.alloc(expr_lifted.item),
|
||||
},
|
||||
after: expr_lifted.after,
|
||||
}
|
||||
}
|
||||
Expr::DbgStmt {
|
||||
first,
|
||||
extra_args,
|
||||
continuation,
|
||||
} => {
|
||||
let continuation_lifted =
|
||||
expr_lift_spaces_after(Parens::NotNeeded, arena, &continuation.value);
|
||||
|
||||
Spaces {
|
||||
before: &[],
|
||||
item: Expr::DbgStmt {
|
||||
first: *first,
|
||||
extra_args,
|
||||
continuation: arena
|
||||
.alloc(Loc::at(continuation.region, continuation_lifted.item)),
|
||||
},
|
||||
after: continuation_lifted.after,
|
||||
}
|
||||
}
|
||||
Expr::LowLevelDbg(_, _, _) => {
|
||||
unreachable!("LowLevelDbg should only exist after desugaring, not during formatting")
|
||||
}
|
||||
Expr::BinOps(lefts, right) => {
|
||||
let lefts = arena.alloc_slice_copy(lefts);
|
||||
|
||||
let before = if let Some(first) = lefts.first_mut() {
|
||||
let lifted = expr_lift_spaces_before(Parens::InOperator, arena, &first.0.value);
|
||||
*first = (Loc::at(first.0.region, lifted.item), first.1);
|
||||
lifted.before
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
|
||||
let right_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &right.value);
|
||||
|
||||
Spaces {
|
||||
before,
|
||||
item: Expr::BinOps(lefts, arena.alloc(Loc::at(right.region, right_lifted.item))),
|
||||
after: right_lifted.after,
|
||||
}
|
||||
}
|
||||
Expr::UnaryOp(expr, op) => {
|
||||
let expr_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &expr.value);
|
||||
|
||||
Spaces {
|
||||
before: &[],
|
||||
item: Expr::UnaryOp(arena.alloc(Loc::at(expr.region, expr_lifted.item)), *op),
|
||||
after: expr_lifted.after,
|
||||
}
|
||||
}
|
||||
|
||||
Expr::MalformedIdent(_, _)
|
||||
| Expr::MalformedSuffixed(_)
|
||||
| Expr::PrecedenceConflict(_)
|
||||
| Expr::EmptyRecordBuilder(_)
|
||||
| Expr::SingleFieldRecordBuilder(_)
|
||||
| Expr::OptionalFieldInRecordBuilder(_, _) => Spaces {
|
||||
before: &[],
|
||||
item: *expr,
|
||||
after: &[],
|
||||
}, // _ => Spaces {
|
||||
// before: &[],
|
||||
// item: *expr,
|
||||
// after: &[],
|
||||
// },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
dbg g
|
||||
L #
|
|
@ -0,0 +1,31 @@
|
|||
SpaceAfter(
|
||||
DbgStmt {
|
||||
first: @4-5 Var {
|
||||
module_name: "",
|
||||
ident: "g",
|
||||
},
|
||||
extra_args: [],
|
||||
continuation: @6-12 SpaceBefore(
|
||||
ParensAround(
|
||||
ParensAround(
|
||||
SpaceAfter(
|
||||
Tag(
|
||||
"L",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
},
|
||||
[
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
dbg g
|
||||
((L
|
||||
))#
|
|
@ -368,6 +368,7 @@ mod test_snapshots {
|
|||
pass/dbg_stmt_in_parens.expr,
|
||||
pass/dbg_stmt_multiline.expr,
|
||||
pass/dbg_stmt_two_exprs.expr,
|
||||
pass/dbg_then_double_parens_cont.expr,
|
||||
pass/def_bang.expr,
|
||||
pass/def_multistring_apply.expr,
|
||||
pass/defs_suffixed_middle_extra_indents.moduledefs,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue