//! The preprocessing we apply to doc comments. //! //! #[derive(Parser)] works in terms of "paragraphs". Paragraph is a sequence of //! non-empty adjacent lines, delimited by sequences of blank (whitespace only) lines.
use std::iter;
pub(crate) fn extract_doc_comment(attrs: &[syn::Attribute]) -> Vec<String> { // multiline comments (`/** ... */`) may have LFs (`\n`) in them, // we need to split so we could handle the lines correctly // // we also need to remove leading and trailing blank lines letmut lines: Vec<_> = attrs
.iter()
.filter(|attr| attr.path().is_ident("doc"))
.filter_map(|attr| { // non #[doc = "..."] attributes are not our concern // we leave them for rustc to handle match &attr.meta {
syn::Meta::NameValue(syn::MetaNameValue {
value:
syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(s),
..
}),
..
}) => Some(s.value()),
_ => None,
}
})
.skip_while(|s| is_blank(s))
.flat_map(|s| { let lines = s
.split('\n')
.map(|s| { // remove one leading space no matter what let s = s.strip_prefix(' ').unwrap_or(s);
s.to_owned()
})
.collect::<Vec<_>>();
lines
})
.collect();
pub(crate) fn format_doc_comment(
lines: &[String],
preprocess: bool,
force_long: bool,
) -> (Option<String>, Option<String>) { iflet Some(first_blank) = lines.iter().position(|s| is_blank(s)) { let (short, long) = if preprocess { let paragraphs = split_paragraphs(lines); let short = paragraphs[0].clone(); let long = paragraphs.join("\n\n");
(remove_period(short), long)
} else { let short = lines[..first_blank].join("\n"); let long = lines.join("\n");
(short, long)
};
(Some(short), Some(long))
} else { let (short, long) = if preprocess { let short = merge_lines(lines); let long = force_long.then(|| short.clone()); let short = remove_period(short);
(short, long)
} else { let short = lines.join("\n"); let long = force_long.then(|| short.clone());
(short, long)
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.