2018-09-20 04:47:58 +00:00
|
|
|
#![feature(proc_macro_diagnostic, proc_macro_span)]
|
2018-08-07 02:58:07 +00:00
|
|
|
#![feature(crate_visibility_modifier)]
|
2018-09-20 04:14:30 +00:00
|
|
|
#![feature(transpose_result)]
|
|
|
|
#![feature(rustc_private)]
|
2018-08-07 02:58:07 +00:00
|
|
|
#![recursion_limit="128"]
|
2018-04-12 23:07:37 +00:00
|
|
|
|
|
|
|
#[macro_use] extern crate quote;
|
2018-08-07 02:58:07 +00:00
|
|
|
#[macro_use] extern crate derive_utils;
|
2018-09-20 04:47:58 +00:00
|
|
|
extern crate indexmap;
|
2018-08-07 02:58:07 +00:00
|
|
|
extern crate proc_macro;
|
2018-09-20 04:14:30 +00:00
|
|
|
extern crate rocket_http as http;
|
|
|
|
extern crate indexmap;
|
|
|
|
|
|
|
|
extern crate syntax_pos;
|
2018-04-12 23:07:37 +00:00
|
|
|
|
2018-09-20 04:14:30 +00:00
|
|
|
#[macro_use] mod proc_macro_ext;
|
2018-08-07 02:58:07 +00:00
|
|
|
mod derive;
|
2018-09-16 07:33:16 +00:00
|
|
|
mod attribute;
|
2018-09-16 07:44:47 +00:00
|
|
|
mod bang;
|
2018-08-07 02:58:07 +00:00
|
|
|
mod http_codegen;
|
2018-09-16 07:33:16 +00:00
|
|
|
mod syn_ext;
|
2018-04-12 23:07:37 +00:00
|
|
|
|
2018-09-20 04:14:30 +00:00
|
|
|
use http::Method;
|
|
|
|
use proc_macro::TokenStream;
|
2018-09-15 06:15:31 +00:00
|
|
|
crate use derive_utils::proc_macro2;
|
2018-04-12 23:07:37 +00:00
|
|
|
|
2018-09-20 04:14:30 +00:00
|
|
|
crate static ROUTE_STRUCT_PREFIX: &str = "static_rocket_route_info_for_";
|
|
|
|
crate static CATCH_STRUCT_PREFIX: &str = "static_rocket_catch_info_for_";
|
|
|
|
crate static CATCH_FN_PREFIX: &str = "rocket_catch_fn_";
|
|
|
|
crate static ROUTE_FN_PREFIX: &str = "rocket_route_fn_";
|
|
|
|
crate static URI_MACRO_PREFIX: &str = "rocket_uri_macro_";
|
|
|
|
crate static ROCKET_PARAM_PREFIX: &str = "__rocket_param_";
|
|
|
|
|
|
|
|
macro_rules! route_attribute {
|
|
|
|
($name:ident => $method:expr) => (
|
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn $name(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
|
|
attribute::route::route_attribute($method, args, input)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
route_attribute!(route => None);
|
|
|
|
route_attribute!(get => Method::Get);
|
|
|
|
route_attribute!(put => Method::Put);
|
|
|
|
route_attribute!(post => Method::Post);
|
|
|
|
route_attribute!(delete => Method::Delete);
|
|
|
|
route_attribute!(head => Method::Head);
|
|
|
|
route_attribute!(patch => Method::Patch);
|
|
|
|
route_attribute!(options => Method::Options);
|
2018-04-12 23:07:37 +00:00
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[proc_macro_derive(FromFormValue, attributes(form))]
|
|
|
|
pub fn derive_from_form_value(input: TokenStream) -> TokenStream {
|
|
|
|
derive::from_form_value::derive_from_form_value(input)
|
2018-04-12 23:07:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[proc_macro_derive(FromForm, attributes(form))]
|
|
|
|
pub fn derive_from_form(input: TokenStream) -> TokenStream {
|
|
|
|
derive::from_form::derive_from_form(input)
|
2018-04-12 23:07:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[proc_macro_derive(Responder, attributes(response))]
|
|
|
|
pub fn derive_responder(input: TokenStream) -> TokenStream {
|
|
|
|
derive::responder::derive_responder(input)
|
2018-04-12 23:07:37 +00:00
|
|
|
}
|
2018-09-16 07:33:16 +00:00
|
|
|
|
2018-09-16 07:44:47 +00:00
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn catch(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
|
|
attribute::catch::catch_attribute(args, input)
|
2018-06-28 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[proc_macro]
|
2018-09-16 07:44:47 +00:00
|
|
|
pub fn routes(input: TokenStream) -> TokenStream {
|
|
|
|
bang::routes_macro(input)
|
2018-06-28 15:55:15 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 07:44:47 +00:00
|
|
|
#[proc_macro]
|
|
|
|
pub fn catchers(input: TokenStream) -> TokenStream {
|
|
|
|
bang::catchers_macro(input)
|
2018-09-16 07:33:16 +00:00
|
|
|
}
|
2018-09-20 04:47:58 +00:00
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn uri(input: TokenStream) -> TokenStream {
|
|
|
|
bang::uri_macro(input)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn rocket_internal_uri(input: TokenStream) -> TokenStream {
|
|
|
|
bang::uri_internal_macro(input)
|
|
|
|
}
|