From 80eb703f5eeb01f1d7e5ba7bfcc479b1ea234bd6 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 29 Sep 2018 01:20:31 -0700 Subject: [PATCH] Finally got get_doc hookup in codegen macro working --- schala-codegen/src/lib.rs | 12 +++++++----- schala-lang/src/lib.rs | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/schala-codegen/src/lib.rs b/schala-codegen/src/lib.rs index e026d2f..3ef4430 100644 --- a/schala-codegen/src/lib.rs +++ b/schala-codegen/src/lib.rs @@ -72,13 +72,13 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream let passes = extract_attribute_list("PipelineSteps", attrs).expect("PipelineSteps are required"); let pass_idents = passes.iter().map(|x| x.0.clone()); - let doc_method: Option= find_attr_by_name("DocMethod", attrs).and_then(|attr| { + let doc_method: Option= find_attr_by_name("DocMethod", attrs).and_then(|attr| { let tts = attr.tts.clone().into_iter().collect::>(); if tts.len() == 2 { let ref after_equals: proc_macro2::TokenTree = tts[1]; match after_equals { - proc_macro2::TokenTree::Ident(ident) => Some(ident.to_string()), + proc_macro2::TokenTree::Ident(ident) => Some(ident.clone()), _ => None } } else { @@ -88,9 +88,9 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream let doc_method_body = match doc_method { None => quote! { }, - Some(s) => quote!{ + Some(method_name) => quote! { fn get_doc(&self, commands: &Vec<&str>) -> Option { - #s(commands) + self.#method_name(commands) } } }; @@ -128,8 +128,10 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream vec![ #(#pass_descriptors),* ] //vec![ #(PassDescriptor { name: #pass_names.to_string(), debug_options: vec![] }),* ] } - } + #doc_method_body + + } }; let output: TokenStream = tokens.into(); diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 390ef98..2359a95 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -44,8 +44,8 @@ pub struct Schala { } impl Schala { - fn get_doc(&self, _commands: &Vec<&str>) -> Option { - Some(format!("yup this is getting called right")) + fn get_doc(&self, commands: &Vec<&str>) -> Option { + Some(format!("Documentation on commands: {:?}", commands)) } }