mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Merge branch 'main' into builtin-task
This commit is contained in:
commit
8288af3156
67 changed files with 4727 additions and 264 deletions
|
@ -450,17 +450,13 @@ impl<'a> Formattable for ValueDef<'a> {
|
|||
AnnotatedBody {
|
||||
ann_pattern,
|
||||
ann_type,
|
||||
comment,
|
||||
lines_between,
|
||||
body_pattern,
|
||||
body_expr,
|
||||
} => {
|
||||
fmt_general_def(ann_pattern, buf, indent, ":", &ann_type.value, newlines);
|
||||
|
||||
if let Some(comment_str) = comment {
|
||||
buf.push_str(" #");
|
||||
buf.spaces(1);
|
||||
buf.push_str(comment_str.trim());
|
||||
}
|
||||
fmt_annotated_body_comment(buf, indent, lines_between);
|
||||
|
||||
buf.newline();
|
||||
fmt_body(buf, &body_pattern.value, &body_expr.value, indent);
|
||||
|
@ -586,6 +582,49 @@ pub fn fmt_defs(buf: &mut Buf, defs: &Defs, indent: u16) {
|
|||
defs.format(buf, indent);
|
||||
}
|
||||
|
||||
pub fn fmt_annotated_body_comment<'a>(
|
||||
buf: &mut Buf,
|
||||
indent: u16,
|
||||
lines_between: &'a [roc_parse::ast::CommentOrNewline<'a>],
|
||||
) {
|
||||
let mut comment_iter = lines_between.iter();
|
||||
if let Some(comment_first) = comment_iter.next() {
|
||||
match comment_first {
|
||||
roc_parse::ast::CommentOrNewline::Newline => (),
|
||||
roc_parse::ast::CommentOrNewline::DocComment(comment_str) => {
|
||||
buf.push_str(" # #");
|
||||
buf.spaces(1);
|
||||
buf.push_str(comment_str.trim());
|
||||
}
|
||||
roc_parse::ast::CommentOrNewline::LineComment(comment_str) => {
|
||||
buf.push_str(" #");
|
||||
buf.spaces(1);
|
||||
buf.push_str(comment_str.trim());
|
||||
}
|
||||
}
|
||||
|
||||
for comment_or_newline in comment_iter {
|
||||
match comment_or_newline {
|
||||
roc_parse::ast::CommentOrNewline::Newline => (),
|
||||
roc_parse::ast::CommentOrNewline::DocComment(comment_str) => {
|
||||
buf.newline();
|
||||
buf.indent(indent);
|
||||
buf.push_str("# #");
|
||||
buf.spaces(1);
|
||||
buf.push_str(comment_str.trim());
|
||||
}
|
||||
roc_parse::ast::CommentOrNewline::LineComment(comment_str) => {
|
||||
buf.newline();
|
||||
buf.indent(indent);
|
||||
buf.push_str("#");
|
||||
buf.spaces(1);
|
||||
buf.push_str(comment_str.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fmt_body<'a>(buf: &mut Buf, pattern: &'a Pattern<'a>, body: &'a Expr<'a>, indent: u16) {
|
||||
// Check if this is an assignment into the unit value
|
||||
let is_unit_assignment = if let Pattern::RecordDestructure(collection) = pattern {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue