mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
format the final comments in records
This commit is contained in:
parent
d93e63bbd0
commit
2000948765
4 changed files with 208 additions and 6 deletions
|
@ -92,6 +92,37 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Similar to fmt_comments_only, but does not finish with a newline()
|
||||
/// and does not create new line if there only are newlines in spaces.
|
||||
/// Used to format final comments in collections (records, lists, ...).
|
||||
pub fn fmt_final_comments_spaces<'a, I>(buf: &mut String<'a>, spaces: I, indent: u16)
|
||||
where
|
||||
I: Iterator<Item = &'a CommentOrNewline<'a>>,
|
||||
{
|
||||
use self::CommentOrNewline::*;
|
||||
|
||||
let mut iter = spaces.peekable();
|
||||
|
||||
while let Some(space) = iter.next() {
|
||||
match space {
|
||||
Newline => {}
|
||||
LineComment(comment) => {
|
||||
buf.push('#');
|
||||
buf.push_str(comment);
|
||||
if let Some(true) = iter.peek().map(|s| s.is_comment()) {
|
||||
newline(buf, indent);
|
||||
}
|
||||
}
|
||||
DocComment(docs) => {
|
||||
buf.push_str("##");
|
||||
buf.push_str(docs);
|
||||
if let Some(true) = iter.peek().map(|s| s.is_comment()) {
|
||||
newline(buf, indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Like format_spaces, but remove newlines and keep only comments.
|
||||
pub fn fmt_comments_only<'a, I>(buf: &mut String<'a>, spaces: I, indent: u16)
|
||||
where
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue