#![crate_type = "dylib"]
#![feature(quote, concat_idents, plugin_registrar, rustc_private)]
#![feature(custom_attribute)]
#![feature(i128_type)]
#![allow(unused_attributes)]
#![allow(deprecated)]
#[macro_use] extern crate log;
#[macro_use] extern crate rustc;
extern crate syntax;
extern crate syntax_ext;
extern crate syntax_pos;
extern crate rustc_plugin;
extern crate rocket;
#[macro_use] mod utils;
mod parser;
mod macros;
mod decorators;
mod lints;
use std::env;
use rustc_plugin::Registry;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
const DEBUG_ENV_VAR: &'static str = "ROCKET_CODEGEN_DEBUG";
const PARAM_PREFIX: &'static str = "rocket_param_";
const ROUTE_STRUCT_PREFIX: &'static str = "static_rocket_route_info_for_";
const CATCH_STRUCT_PREFIX: &'static str = "static_rocket_catch_info_for_";
const ROUTE_FN_PREFIX: &'static str = "rocket_route_fn_";
const CATCH_FN_PREFIX: &'static str = "rocket_catch_fn_";
const ROUTE_ATTR: &'static str = "rocket_route";
const ROUTE_INFO_ATTR: &'static str = "rocket_route_info";
const CATCHER_ATTR: &'static str = "rocket_catcher";
macro_rules! register_decorators {
($registry:expr, $($name:expr => $func:ident),+) => (
$($registry.register_syntax_extension(Symbol::intern($name),
SyntaxExtension::MultiModifier(Box::new(decorators::$func)));
)+
)
}
macro_rules! register_derives {
($registry:expr, $($name:expr => $func:ident),+) => (
$($registry.register_custom_derive(Symbol::intern($name),
SyntaxExtension::MultiDecorator(Box::new(decorators::$func)));
)+
)
}
macro_rules! register_lints {
($registry:expr, $($item:ident),+) => ($(
$registry.register_late_lint_pass(Box::new(lints::$item::default()));
)+)
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
if env::var(DEBUG_ENV_VAR).is_ok() {
::rocket::logger::init(::rocket::LoggingLevel::Debug);
}
reg.register_macro("routes", macros::routes);
reg.register_macro("errors", macros::errors);
register_derives!(reg,
"derive_FromForm" => from_form_derive
);
register_decorators!(reg,
"error" => error_decorator,
"route" => route_decorator,
"get" => get_decorator,
"put" => put_decorator,
"post" => post_decorator,
"delete" => delete_decorator,
"head" => head_decorator,
"patch" => patch_decorator,
"options" => options_decorator
);
register_lints!(reg, RocketLint);
}