2018-04-27 02:19:09 -07:00
|
|
|
#![feature(proc_macro)]
|
|
|
|
extern crate proc_macro;
|
2018-04-30 00:35:42 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate quote;
|
|
|
|
extern crate syn;
|
2018-04-30 02:24:21 -07:00
|
|
|
|
2018-04-27 02:19:09 -07:00
|
|
|
use proc_macro::TokenStream;
|
2018-04-30 02:24:21 -07:00
|
|
|
use syn::DeriveInput;
|
2018-04-27 02:19:09 -07:00
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn print_a_thing(_input: TokenStream) -> TokenStream {
|
|
|
|
"println!(\"Invoked from a proc macro\");".parse().unwrap()
|
|
|
|
}
|
|
|
|
|
2018-04-30 00:35:42 -07:00
|
|
|
|
2018-05-02 02:14:36 -07:00
|
|
|
#[proc_macro_derive(ProgrammingLanguageInterface, attributes(LanguageName, FileExtension, PipelineSteps))]
|
2018-04-30 00:35:42 -07:00
|
|
|
pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream {
|
2018-04-30 02:24:21 -07:00
|
|
|
let ast: DeriveInput = syn::parse(input).unwrap();
|
|
|
|
let name = &ast.ident;
|
2018-05-02 03:53:38 -07:00
|
|
|
let attrs = &ast.attrs;
|
|
|
|
|
|
|
|
println!("ATTRS {:?}", attrs);
|
|
|
|
//let language_name = attrs.iter().find(
|
|
|
|
|
2018-05-02 02:14:36 -07:00
|
|
|
|
2018-04-30 02:24:21 -07:00
|
|
|
let tokens = quote! {
|
|
|
|
impl ProgrammingLanguageInterface for #name {
|
2018-05-02 02:14:36 -07:00
|
|
|
fn get_language_name(&self) -> String {
|
|
|
|
"Schala".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_source_file_suffix(&self) -> String {
|
|
|
|
format!("schala")
|
|
|
|
}
|
|
|
|
fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {
|
|
|
|
let mut chain = pass_chain![self, options;
|
|
|
|
tokenizing_stage,
|
|
|
|
parsing_stage,
|
|
|
|
symbol_table_stage,
|
|
|
|
typechecking_stage,
|
|
|
|
eval_stage
|
|
|
|
];
|
|
|
|
chain(input)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_stages(&self) -> Vec<String> {
|
|
|
|
vec![
|
|
|
|
format!("tokenizing_stage"),
|
|
|
|
format!("parsing_stage"), //TODO handle both types of this
|
|
|
|
format!("symbol_table_stage"),
|
|
|
|
format!("typechecking_stage"),
|
|
|
|
format!("eval_stage")
|
|
|
|
]
|
|
|
|
}
|
2018-04-30 02:24:21 -07:00
|
|
|
}
|
|
|
|
};
|
2018-05-02 02:14:36 -07:00
|
|
|
|
2018-04-30 02:24:21 -07:00
|
|
|
tokens.into()
|
2018-04-30 00:35:42 -07:00
|
|
|
}
|
|
|
|
|
2018-04-27 02:19:09 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
assert_eq!(2 + 2, 4);
|
|
|
|
}
|
|
|
|
}
|