@@ -203,6 +203,22 @@ impl<T> From<Vec1Ref<T>> for Vec1<T> {
|
||||
}
|
||||
|
||||
impl TypedExpr {
|
||||
pub fn is_simple_expr_to_format(&self) -> bool {
|
||||
match self {
|
||||
Self::String { .. } | Self::UInt { .. } | Self::ByteArray { .. } | Self::Var { .. } => {
|
||||
true
|
||||
}
|
||||
Self::Pair { fst, snd, .. } => {
|
||||
fst.is_simple_expr_to_format() && snd.is_simple_expr_to_format()
|
||||
}
|
||||
Self::Tuple { elems, .. } => elems.iter().all(|e| e.is_simple_expr_to_format()),
|
||||
Self::List { elements, .. } if elements.len() <= 3 => {
|
||||
elements.iter().all(|e| e.is_simple_expr_to_format())
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn and_then(self, next: Self) -> Self {
|
||||
if let TypedExpr::Trace {
|
||||
tipo,
|
||||
|
||||
@@ -382,7 +382,18 @@ impl<'comments> Formatter<'comments> {
|
||||
.append(wrap_args(elems.iter().map(|e| (self.const_expr(e), false))).group())
|
||||
}
|
||||
TypedExpr::List { elements, .. } => {
|
||||
wrap_args(elements.iter().map(|e| (self.const_expr(e), false))).group()
|
||||
let comma: fn() -> Document<'a> =
|
||||
if elements.iter().all(TypedExpr::is_simple_expr_to_format) {
|
||||
|| flex_break(",", ", ")
|
||||
} else {
|
||||
|| break_(",", ", ")
|
||||
};
|
||||
|
||||
list(
|
||||
join(elements.iter().map(|e| self.const_expr(e)), comma()),
|
||||
elements.len(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
TypedExpr::Var { name, .. } => name.to_doc(),
|
||||
_ => Document::Str(""),
|
||||
|
||||
Reference in New Issue
Block a user