mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Fix multiline str pattern newline multiplication
This commit is contained in:
parent
e9a8588c3e
commit
f1d9667ea0
5 changed files with 92 additions and 0 deletions
|
@ -473,6 +473,7 @@ pub fn pattern_lift_spaces<'a, 'b: 'a>(
|
|||
match pat {
|
||||
Pattern::Apply(func, args) => {
|
||||
let func_lifted = pattern_lift_spaces(arena, &func.value);
|
||||
|
||||
let args = arena.alloc_slice_copy(args);
|
||||
let (before, func, after) = if let Some(last) = args.last_mut() {
|
||||
let last_lifted = pattern_lift_spaces(arena, &last.value);
|
||||
|
@ -528,6 +529,19 @@ pub fn pattern_lift_spaces<'a, 'b: 'a>(
|
|||
Pattern::SpaceBefore(expr, spaces) => {
|
||||
let mut inner = pattern_lift_spaces(arena, expr);
|
||||
inner.before = merge_spaces(arena, spaces, inner.before);
|
||||
|
||||
if starts_with_block_str(&inner.item)
|
||||
&& matches!(inner.before.last(), Some(CommentOrNewline::Newline))
|
||||
{
|
||||
// Ick!
|
||||
// The block string will keep "generating" newlines when formatted (it wants to start on its own line),
|
||||
// so we strip one out here.
|
||||
//
|
||||
// Note that this doesn't affect Expr's because those have explicit parens, and we can control
|
||||
// whether spaces cross that boundary.
|
||||
inner.before = &inner.before[..inner.before.len() - 1];
|
||||
}
|
||||
|
||||
inner
|
||||
}
|
||||
Pattern::SpaceAfter(expr, spaces) => {
|
||||
|
@ -543,6 +557,17 @@ pub fn pattern_lift_spaces<'a, 'b: 'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn starts_with_block_str(item: &Pattern<'_>) -> bool {
|
||||
match item {
|
||||
Pattern::As(inner, _) | Pattern::Apply(inner, _) => starts_with_block_str(&inner.value),
|
||||
Pattern::SpaceBefore(inner, _) | Pattern::SpaceAfter(inner, _) => {
|
||||
starts_with_block_str(inner)
|
||||
}
|
||||
Pattern::StrLiteral(str_literal) => is_str_multiline(str_literal),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pattern_lift_spaces_before<'a, 'b: 'a>(
|
||||
arena: &'a Bump,
|
||||
pat: &Pattern<'b>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue