use super::{PrettySimple, Writer, format_bracket_list};
use crate::format_constructor;
use crate::predoc::{Doc, DocE, GroupAnn, IR, Spacing, TextAnn};
impl PrettySimple for Doc {
fn format<W: Writer>(&self, w: &mut W) {
self.0.format(w);
}
fn is_simple(&self) -> bool {
self.0.is_simple()
}
fn has_delimiters(&self) -> bool {
self.0.has_delimiters()
}
fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl PrettySimple for IR {
fn format<W: Writer>(&self, w: &mut W) {
format_bracket_list(w, &self.0, false);
if !self.0.is_empty() {
w.newline();
}
}
}
impl PrettySimple for Spacing {
fn format<W: Writer>(&self, w: &mut W) {
crate::format_enum!(self, w, {
Newlines(n) => [n],
Softbreak => [],
Break => [],
Hardspace => [],
Softspace => [],
Space => [],
Hardline => [],
Emptyline => [],
});
}
fn is_simple(&self) -> bool {
!matches!(self, Self::Newlines(_))
}
fn renders_inline_parens(&self) -> bool {
matches!(self, Self::Newlines(_))
}
}
impl PrettySimple for GroupAnn {
fn format<W: Writer>(&self, w: &mut W) {
crate::format_enum!(self, w, {
RegularG => [],
Priority => [],
Transparent => [],
});
}
fn is_simple(&self) -> bool {
true
}
}
impl PrettySimple for TextAnn {
fn format<W: Writer>(&self, w: &mut W) {
crate::format_enum!(self, w, {
RegularT => [],
Comment => [],
TrailingComment => [],
Trailing => [],
});
}
fn is_simple(&self) -> bool {
true
}
}
impl PrettySimple for DocE {
fn format<W: Writer>(&self, w: &mut W) {
crate::format_enum!(self, w, {
Text(nest, off, ann, text) => [nest, off, ann, text],
Spacing(sp) => [sp],
Group(ann, doc) => [ann, doc],
Nest(n, o) => [n, o],
});
}
fn is_simple(&self) -> bool {
matches!(
self,
Self::Spacing(_) | Self::Text(_, _, _, _) | Self::Nest(..)
)
}
}