From 824dacacaa16ca2735710080f5d84a60ab452d85 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Fri, 14 Nov 2025 20:45:52 +0000 Subject: [PATCH] alt --- tools/src/main.rs | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/tools/src/main.rs b/tools/src/main.rs index 2f05552..879d038 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs @@ -335,32 +335,16 @@ fn parse_impl(item_impl: &ItemImpl) -> Option { /// Handles both `///` comments (converted to `#[doc = "..."]` by syn) /// and explicit `#[doc = "..."]` attributes. fn extract_docstring(attrs: &[Attribute]) -> Option { - let mut docs = Vec::new(); + // Convert the attribute’s token stream back to source‑like text. + let text = attrs + .iter() + .map(|a| a.tokens.to_string()) + .collect::>() + .join("\n"); - for attr in attrs { - // `path()` is the correct method; `path` is a field - if attr.path().is_ident("doc") { - // #[doc = "…"] - if let Ok(meta) = attr.parse_meta() { - if let syn::Meta::NameValue(nv) = meta { - // The value is an `Expr`. Pull out a string literal. - if let syn::Expr::Lit(syn::ExprLit { - lit: syn::Lit::Str(lit_str), - .. - }) = nv.value - { - docs.push(lit_str.value()); - } - } - } - } - } - - if docs.is_empty() { - None - } else { - Some(docs.join("\n")) - } + let re = Regex::new(r#"(?m)^\s*(?:///|#\[\s*doc\s*=\s*")(.+?)(?:")?$"#).ok()?; + re.captures(&text) + .and_then(|c| c.get(1).map(|m| m.as_str().to_string())) } fn parse_mod(item_mod: &ItemMod) -> Option {