Introduce record! combinator

... and refactor header parser to fully use combinators, in support of future combinator-based superpowers
This commit is contained in:
Joshua Warner 2022-11-26 09:48:34 -08:00
parent ec6db293f5
commit 2b91af02df
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
26 changed files with 1709 additions and 1486 deletions

View file

@ -63,9 +63,7 @@ pub trait Formattable {
_parens: Parens,
_newlines: Newlines,
indent: u16,
) {
self.format(buf, indent);
}
);
fn format<'buf>(&self, buf: &mut Buf<'buf>, indent: u16) {
self.format_with_options(buf, Parens::NotNeeded, Newlines::No, indent);
@ -96,18 +94,13 @@ where
}
}
impl<'a, T> Formattable for Collection<'a, T>
where
T: Formattable,
{
fn is_multiline(&self) -> bool {
// if there are any comments, they must go on their own line
// because otherwise they'd comment out the closing delimiter
!self.final_comments().is_empty() ||
// if any of the items in the collection are multiline,
// then the whole collection must be multiline
self.items.iter().any(Formattable::is_multiline)
}
pub fn is_collection_multiline<T: Formattable>(collection: &Collection<'_, T>) -> bool {
// if there are any comments, they must go on their own line
// because otherwise they'd comment out the closing delimiter
!collection.final_comments().is_empty() ||
// if any of the items in the collection are multiline,
// then the whole collection must be multiline
collection.items.iter().any(Formattable::is_multiline)
}
/// A Located formattable value is also formattable
@ -577,7 +570,7 @@ impl<'a> Formattable for HasImpls<'a> {
fn is_multiline(&self) -> bool {
match self {
HasImpls::SpaceBefore(_, _) | HasImpls::SpaceAfter(_, _) => true,
HasImpls::HasImpls(impls) => impls.is_multiline(),
HasImpls::HasImpls(impls) => is_collection_multiline(impls),
}
}
@ -657,7 +650,7 @@ impl<'a> Formattable for HasAbilities<'a> {
fn is_multiline(&self) -> bool {
match self {
HasAbilities::SpaceAfter(..) | HasAbilities::SpaceBefore(..) => true,
HasAbilities::Has(has_abilities) => has_abilities.is_multiline(),
HasAbilities::Has(has_abilities) => is_collection_multiline(has_abilities),
}
}