Part of the work for a doc handler

This commit is contained in:
greg 2018-09-22 00:24:27 -07:00
parent 693766fa59
commit f67793308e
3 changed files with 11 additions and 3 deletions

View File

@ -1,5 +1,4 @@
#![feature(trace_macros)]
#![feature(proc_macro)]
extern crate proc_macro;
#[macro_use]
extern crate quote;
@ -52,7 +51,7 @@ fn extract_attribute_list(name: &str, attrs: &Vec<Attribute>) -> Option<Vec<(Ide
})
}
#[proc_macro_derive(ProgrammingLanguageInterface, attributes(LanguageName, SourceFileExtension, PipelineSteps))]
#[proc_macro_derive(ProgrammingLanguageInterface, attributes(LanguageName, SourceFileExtension, PipelineSteps, DocMethod))]
pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream {
let ast: DeriveInput = syn::parse(input).unwrap();
let name = &ast.ident;
@ -62,6 +61,7 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream
let file_ext = extract_attribute_arg_by_name("SourceFileExtension", attrs).expect("SourceFileExtension is required");
let passes = extract_attribute_list("PipelineSteps", attrs).expect("PipelineSteps are required");
let pass_idents = passes.iter().map(|x| x.0);
let doc_method: Option<String> = extract_attribute_arg_by_name("DocMethod", attrs);
//let pass_names: Vec<String> = passes.iter().map(|pass| pass.0.to_string()).collect();
let pass_descriptors = passes.iter().map(|pass| {
@ -97,6 +97,8 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream
//vec![ #(PassDescriptor { name: #pass_names.to_string(), debug_options: vec![] }),* ]
}
}
//TODO if doc_method is defined, add code here
};
tokens.into()
}

View File

@ -35,12 +35,18 @@ mod eval;
#[LanguageName = "Schala"]
#[SourceFileExtension = "schala"]
#[PipelineSteps(tokenizing, parsing(compact,expanded,trace), symbol_table, typechecking, ast_reducing, eval)]
#[DocMethod = "get_doc"]
pub struct Schala {
state: eval::State<'static>,
symbol_table: Rc<RefCell<symbol_table::SymbolTable>>,
type_context: typechecking::TypeContext<'static>,
}
impl Schala {
fn get_doc(&self, _commands: &Vec<&str>) -> Option<String> {
Some(format!("yup this is getting called right"))
}
}
impl Schala {
fn new_blank_env() -> Schala {

View File

@ -156,7 +156,7 @@ pub trait ProgrammingLanguageInterface {
fn custom_interpreter_directives_help(&self) -> String {
format!(">> No custom interpreter directives specified <<")
}
fn get_doc(&mut self, _commands: &Vec<&str>) -> Option<String> {
fn get_doc(&self, _commands: &Vec<&str>) -> Option<String> {
None
}
}