mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
cleanup
This commit is contained in:
parent
d61b8c88a1
commit
36ccafd8ab
4 changed files with 29 additions and 27 deletions
|
@ -26,6 +26,24 @@ pub trait Formattable<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A Located formattable value is also formattable
|
||||||
|
impl<'a, T> Formattable<'a> for Located<T>
|
||||||
|
where
|
||||||
|
T: Formattable<'a>,
|
||||||
|
{
|
||||||
|
fn is_multiline(&self) -> bool {
|
||||||
|
self.value.is_multiline()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_with_parens(&self, buf: &mut String<'a>, parens: Parens, indent: u16) {
|
||||||
|
self.value.format_with_parens(buf, parens, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format(&self, buf: &mut String<'a>, indent: u16) {
|
||||||
|
self.value.format(buf, indent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Formattable<'a> for TypeAnnotation<'a> {
|
impl<'a> Formattable<'a> for TypeAnnotation<'a> {
|
||||||
fn is_multiline(&self) -> bool {
|
fn is_multiline(&self) -> bool {
|
||||||
use roc_parse::ast::TypeAnnotation::*;
|
use roc_parse::ast::TypeAnnotation::*;
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn fmt_def<'a>(buf: &mut String<'a>, def: &'a Def<'a>, indent: u16) {
|
||||||
} else {
|
} else {
|
||||||
for var in *vars {
|
for var in *vars {
|
||||||
buf.push(' ');
|
buf.push(' ');
|
||||||
fmt_pattern(buf, &var.value, indent, Parens::NotNeeded, false);
|
fmt_pattern(buf, &var.value, indent, Parens::NotNeeded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ pub fn fmt_body<'a>(
|
||||||
body: &'a Expr<'a>,
|
body: &'a Expr<'a>,
|
||||||
indent: u16,
|
indent: u16,
|
||||||
) {
|
) {
|
||||||
fmt_pattern(buf, pattern, indent, Parens::InApply, false);
|
fmt_pattern(buf, pattern, indent, Parens::InApply);
|
||||||
buf.push_str(" =");
|
buf.push_str(" =");
|
||||||
if is_multiline_expr(body) {
|
if is_multiline_expr(body) {
|
||||||
match body {
|
match body {
|
||||||
|
@ -78,7 +78,7 @@ pub fn fmt_type_annotation<'a>(
|
||||||
annotation: &'a TypeAnnotation<'a>,
|
annotation: &'a TypeAnnotation<'a>,
|
||||||
indent: u16,
|
indent: u16,
|
||||||
) {
|
) {
|
||||||
fmt_pattern(buf, pattern, indent, Parens::NotNeeded, false);
|
fmt_pattern(buf, pattern, indent, Parens::NotNeeded);
|
||||||
buf.push_str(" : ");
|
buf.push_str(" : ");
|
||||||
fmt_annotation(buf, annotation, indent);
|
fmt_annotation(buf, annotation, indent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -587,7 +587,6 @@ fn fmt_when<'a>(
|
||||||
&first_pattern.value,
|
&first_pattern.value,
|
||||||
indent + INDENT,
|
indent + INDENT,
|
||||||
Parens::NotNeeded,
|
Parens::NotNeeded,
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
for when_pattern in rest {
|
for when_pattern in rest {
|
||||||
if is_multiline {
|
if is_multiline {
|
||||||
|
@ -597,13 +596,7 @@ fn fmt_when<'a>(
|
||||||
} else {
|
} else {
|
||||||
buf.push_str(" | ");
|
buf.push_str(" | ");
|
||||||
}
|
}
|
||||||
fmt_pattern(
|
fmt_pattern(buf, &when_pattern.value, indent + INDENT, Parens::NotNeeded);
|
||||||
buf,
|
|
||||||
&when_pattern.value,
|
|
||||||
indent + INDENT,
|
|
||||||
Parens::NotNeeded,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(guard_expr) = &branch.guard {
|
if let Some(guard_expr) = &branch.guard {
|
||||||
|
@ -762,7 +755,7 @@ pub fn fmt_closure<'a>(
|
||||||
let mut it = loc_patterns.iter().peekable();
|
let mut it = loc_patterns.iter().peekable();
|
||||||
|
|
||||||
while let Some(loc_pattern) = it.next() {
|
while let Some(loc_pattern) = it.next() {
|
||||||
fmt_pattern(buf, &loc_pattern.value, indent, Parens::NotNeeded, false);
|
fmt_pattern(buf, &loc_pattern.value, indent, Parens::NotNeeded);
|
||||||
|
|
||||||
if it.peek().is_some() {
|
if it.peek().is_some() {
|
||||||
if arguments_are_multiline {
|
if arguments_are_multiline {
|
||||||
|
|
|
@ -9,7 +9,6 @@ pub fn fmt_pattern<'a>(
|
||||||
pattern: &'a Pattern<'a>,
|
pattern: &'a Pattern<'a>,
|
||||||
indent: u16,
|
indent: u16,
|
||||||
parens: Parens,
|
parens: Parens,
|
||||||
_only_comments: bool,
|
|
||||||
) {
|
) {
|
||||||
pattern.format_with_parens(buf, parens, indent);
|
pattern.format_with_parens(buf, parens, indent);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +25,8 @@ impl<'a> Formattable<'a> for Pattern<'a> {
|
||||||
|
|
||||||
Pattern::Nested(nested_pat) => is_multiline_pattern(nested_pat),
|
Pattern::Nested(nested_pat) => is_multiline_pattern(nested_pat),
|
||||||
|
|
||||||
Pattern::RecordDestructure(fields) => fields.iter().any(|f| f.value.is_multiline()),
|
Pattern::RecordDestructure(fields) => fields.iter().any(|f| f.is_multiline()),
|
||||||
Pattern::RecordField(_, subpattern) => subpattern.value.is_multiline(),
|
Pattern::RecordField(_, subpattern) => subpattern.is_multiline(),
|
||||||
|
|
||||||
Pattern::Identifier(_)
|
Pattern::Identifier(_)
|
||||||
| Pattern::GlobalTag(_)
|
| Pattern::GlobalTag(_)
|
||||||
|
@ -61,15 +60,11 @@ impl<'a> Formattable<'a> for Pattern<'a> {
|
||||||
buf.push('(');
|
buf.push('(');
|
||||||
}
|
}
|
||||||
|
|
||||||
loc_pattern
|
loc_pattern.format_with_parens(buf, Parens::InApply, indent);
|
||||||
.value
|
|
||||||
.format_with_parens(buf, Parens::InApply, indent);
|
|
||||||
|
|
||||||
for loc_arg in loc_arg_patterns.iter() {
|
for loc_arg in loc_arg_patterns.iter() {
|
||||||
buf.push(' ');
|
buf.push(' ');
|
||||||
loc_arg
|
loc_arg.format_with_parens(buf, Parens::InApply, indent);
|
||||||
.value
|
|
||||||
.format_with_parens(buf, Parens::InApply, indent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if parens {
|
if parens {
|
||||||
|
@ -82,9 +77,7 @@ impl<'a> Formattable<'a> for Pattern<'a> {
|
||||||
let mut it = loc_patterns.iter().peekable();
|
let mut it = loc_patterns.iter().peekable();
|
||||||
|
|
||||||
while let Some(loc_pattern) = it.next() {
|
while let Some(loc_pattern) = it.next() {
|
||||||
loc_pattern
|
loc_pattern.format_with_parens(buf, Parens::NotNeeded, indent);
|
||||||
.value
|
|
||||||
.format_with_parens(buf, Parens::NotNeeded, indent);
|
|
||||||
|
|
||||||
if it.peek().is_some() {
|
if it.peek().is_some() {
|
||||||
buf.push_str(", ");
|
buf.push_str(", ");
|
||||||
|
@ -97,9 +90,7 @@ impl<'a> Formattable<'a> for Pattern<'a> {
|
||||||
RecordField(name, loc_pattern) => {
|
RecordField(name, loc_pattern) => {
|
||||||
buf.push_str(name);
|
buf.push_str(name);
|
||||||
buf.push_str(": ");
|
buf.push_str(": ");
|
||||||
loc_pattern
|
loc_pattern.format_with_parens(buf, Parens::NotNeeded, indent);
|
||||||
.value
|
|
||||||
.format_with_parens(buf, Parens::NotNeeded, indent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NumLiteral(string) => buf.push_str(string),
|
NumLiteral(string) => buf.push_str(string),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue