mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Feedback: dry out term, make fmt_spaces_with_newline_mode more readable, explicitly implement all the variants in ann_lift_spaces
This commit is contained in:
parent
8642f8500e
commit
6ac6a7c19a
3 changed files with 98 additions and 21 deletions
|
@ -37,17 +37,22 @@ pub fn fmt_spaces_with_newline_mode(
|
|||
mode,
|
||||
SpacesNewlineMode::SkipNewlinesAtStart | SpacesNewlineMode::SkipNewlinesAtBoth
|
||||
) {
|
||||
while let Some(CommentOrNewline::Newline) = spaces.first() {
|
||||
spaces = &spaces[1..];
|
||||
}
|
||||
let skip_count = spaces
|
||||
.iter()
|
||||
.take_while(|s| *s == &CommentOrNewline::Newline)
|
||||
.count();
|
||||
spaces = &spaces[skip_count..];
|
||||
}
|
||||
if matches!(
|
||||
mode,
|
||||
SpacesNewlineMode::SkipNewlinesAtEnd | SpacesNewlineMode::SkipNewlinesAtBoth
|
||||
) {
|
||||
while let Some(CommentOrNewline::Newline) = spaces.last() {
|
||||
spaces = &spaces[..spaces.len() - 1];
|
||||
}
|
||||
let skip_count = spaces
|
||||
.iter()
|
||||
.rev()
|
||||
.take_while(|s| *s == &CommentOrNewline::Newline)
|
||||
.count();
|
||||
spaces = &spaces[..spaces.len() - skip_count];
|
||||
}
|
||||
fmt_spaces(buf, spaces.iter(), indent);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue