From: Ian Jackson Date: Sat, 24 Jul 2021 11:34:45 +0000 (+0100) Subject: config, wip macro, generete fields with SKLs X-Git-Tag: hippotat/1.0.0~491 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=c5dd37ebbc5ebdc7d49c926916c57b0df9ecccaf;p=hippotat.git config, wip macro, generete fields with SKLs Signed-off-by: Ian Jackson --- diff --git a/macros/macros.rs b/macros/macros.rs index 6431471..3f249be 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -28,22 +28,19 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { }; let target = &input.ident; - let names = fields.named.iter().map( - |f| Literal::string( &f.ident.as_ref().unwrap().to_string() ) - ) - .collect_vec(); + let mut names = vec![]; let mut output = vec![]; for field in &fields.named { dbg!(field); - let mut skl = quote!{ SKL::Ordinary }; + let mut skl = quote!{ SectionKindList::Ordinary }; let mut method = quote!{ ordinary }; for attr in &field.attrs { if attr.tokens.is_empty() { let atspan = attr.path.segments.last().unwrap().ident.span(); method = attr.path.to_token_stream(); if &attr.path == &parse_quote!{ limited } { - skl = quote_spanned!{atspan=> SKL::Limited }; + skl = quote_spanned!{atspan=> SectionKindList::Limited }; } } else if &attr.path == &parse_quote!{ special } { let meta = match attr.parse_meta().unwrap() { @@ -65,6 +62,9 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let fname_string = fname.as_ref().unwrap().to_string(); let fname_lit = Literal::string( &fname_string ); + names.push(quote!{ + (#fname_lit, #skl), + }); output.push(quote!{ #fname: rctx. #method ( #fname_lit )?, }); @@ -73,7 +73,8 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let output = quote! { impl #target { - const FIELDS: &'static [&'static str] = &[ #( #names ),* ]; + const FIELDS: &'static [(&'static str, SectionKindList)] + = &[ #( #names ),* ]; fn resolve_instance(rctx: &ResolveContext) -> ::std::result::Result<#target, anyhow::Error>