schala/schala-codegen/src/lib.rs

68 lines
1.6 KiB
Rust
Raw Normal View History

#![feature(proc_macro)]
extern crate proc_macro;
#[macro_use]
extern crate quote;
extern crate syn;
2018-04-30 02:24:21 -07:00
use proc_macro::TokenStream;
2018-04-30 02:24:21 -07:00
use syn::DeriveInput;
#[proc_macro]
pub fn print_a_thing(_input: TokenStream) -> TokenStream {
"println!(\"Invoked from a proc macro\");".parse().unwrap()
}
2018-05-02 02:14:36 -07:00
#[proc_macro_derive(ProgrammingLanguageInterface, attributes(LanguageName, FileExtension, PipelineSteps))]
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()
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}