#![feature(proc_macro)] extern crate proc_macro; #[macro_use] extern crate syn; #[macro_use] extern crate quote; use proc_macro::TokenStream; use syn::{Expr, Lit, ExprLit}; use syn::punctuated::Punctuated; use syn::synom::Synom; fn get_string_args(input: Expr) -> Vec { let mut contained_strings = Vec::new(); match input { Expr::Array(array) => { for item in array.elems { if let Expr::Lit(ExprLit { lit: Lit::Str(s), ..}) = item { contained_strings.push(s.value()); } else { panic!("Non-string-literal input to compiler_pass_sequence"); } } }, _ => panic!("Non-array input to compiler_pass_sequence"), } contained_strings } #[proc_macro] pub fn compiler_pass_sequence(input: TokenStream) -> TokenStream { /* for token_tree in input { //println!("ITEM: {:?}", token_tree.kind); match token_tree.kind { TokenNode::Literal(l) => println!("{:?}", l), _ => () } } */ let input: Expr = syn::parse(input).unwrap(); let stages = get_string_args(input); let from_macro = format!("{:?}", stages); let output = quote! { fn new_execute(&mut self, input: &str, _options: &EvalOptions) -> FinishedComputation { let evaluation = UnfinishedComputation::default(); evaluation.output(Err(#from_macro.to_string())) } }; output.into() } /* #[compiler_pass(*/ #[proc_macro_attribute] pub fn compiler_pass(metadata: TokenStream, function: TokenStream) -> TokenStream { //println!("FROM MACRO: {}", function); println!("Compiler pass metadata: {}", metadata); function } #[cfg(test)] mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); } } /* in Rocket * #[get("/")] fn hi() -> &'static str { "hello" } GETS MAPPED TO: static hi_info = RouteInfo { name: "hi", method: Method::Get, path: "/", handler: hi_route, } fn hi_route(req: &Request) -> Outcome { let responder = hi(); Outcome::from(req, responder); } */