mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
doc using syn-ext
This commit is contained in:
1 parent
dded3ffc53
commit
fd3aba5033
3 files changed
+9
-27
No files matched your search
Generated
+2
-2
@@ -1691,9 +1691,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn-ext"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48de58fdf4f8294294c09653384dcb02e8e90b10d61cc0cf554bfbc2e9eaad9a"
|
||||
checksum = "da910e9ec6f88d3f591893025a3040fe2659b7f7ea4eacce5469b7ebe5287339"
|
||||
dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "1.0", features = ["full"] }
|
||||
syn-ext = { version = "0.2", features = ["full"] }
|
||||
syn-ext = { version = "0.2.1", features = ["full"] }
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
rustpython-compiler = { path = "../compiler", version = "0.1.1" }
|
||||
|
||||
+6
-24
@@ -7,8 +7,8 @@ use proc_macro2::TokenStream;
|
||||
use quote::{quote, quote_spanned, ToTokens};
|
||||
use std::collections::HashMap;
|
||||
use syn::{
|
||||
parse_quote, spanned::Spanned, Attribute, AttributeArgs, Ident, Index, Item, Lit, Meta,
|
||||
NestedMeta, Result,
|
||||
parse_quote, spanned::Spanned, Attribute, AttributeArgs, Ident, Index, Item, Meta, NestedMeta,
|
||||
Result,
|
||||
};
|
||||
use syn_ext::ext::*;
|
||||
|
||||
@@ -117,29 +117,11 @@ fn generate_class_def(
|
||||
module_name: Option<&str>,
|
||||
attrs: &[Attribute],
|
||||
) -> std::result::Result<TokenStream, Diagnostic> {
|
||||
let mut doc: Option<Vec<String>> = None;
|
||||
for attr in attrs.iter() {
|
||||
if attr.path.is_ident("doc") {
|
||||
let meta = attr.parse_meta().expect("expected doc attr to be a meta");
|
||||
if let Meta::NameValue(name_value) = meta {
|
||||
if let Lit::Str(s) = name_value.lit {
|
||||
let val = s.value().trim().to_owned();
|
||||
match doc {
|
||||
Some(ref mut doc) => doc.push(val),
|
||||
None => doc = Some(vec![val]),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let doc = match doc {
|
||||
Some(doc) => {
|
||||
let doc = doc.join("\n");
|
||||
quote!(Some(#doc))
|
||||
}
|
||||
None => quote!(None),
|
||||
let doc = if let Some(doc) = attrs.doc() {
|
||||
quote!(Some(#doc))
|
||||
} else {
|
||||
quote!(None)
|
||||
};
|
||||
|
||||
let module_class_name = if let Some(module_name) = module_name {
|
||||
format!("{}.{}", module_name, name)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user