2017-07-12 06:44:54 +02:00
|
|
|
#![feature(proc_macro)]
|
2017-07-04 18:26:11 +02:00
|
|
|
#![recursion_limit = "128"]
|
|
|
|
|
2017-07-15 01:54:54 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate error_chain;
|
2017-07-04 18:26:11 +02:00
|
|
|
extern crate proc_macro;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate quote;
|
2017-07-15 01:54:54 +02:00
|
|
|
extern crate rtfm_syntax;
|
2017-07-04 18:26:11 +02:00
|
|
|
extern crate syn;
|
|
|
|
|
2017-07-15 01:54:54 +02:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use rtfm_syntax::App;
|
|
|
|
|
|
|
|
use error::*;
|
|
|
|
|
|
|
|
mod analyze;
|
2017-07-04 18:26:11 +02:00
|
|
|
mod check;
|
2017-07-15 01:54:54 +02:00
|
|
|
mod error;
|
2017-07-04 18:26:11 +02:00
|
|
|
mod trans;
|
2017-07-12 06:44:54 +02:00
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn rtfm(ts: TokenStream) -> TokenStream {
|
2017-07-15 01:54:54 +02:00
|
|
|
match run(ts) {
|
|
|
|
Err(e) => panic!("{}", error_chain::ChainedError::display(&e)),
|
|
|
|
Ok(ts) => ts,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(ts: TokenStream) -> Result<TokenStream> {
|
2017-07-04 18:26:11 +02:00
|
|
|
let input = format!("{}", ts);
|
|
|
|
|
2017-07-15 01:54:54 +02:00
|
|
|
let app = check::app(App::parse(&input)
|
|
|
|
.chain_err(|| "parsing the `rtfm!` macro")?).chain_err(
|
|
|
|
|| "checking the application specification",
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let ownerships = analyze::app(&app);
|
|
|
|
let tokens = trans::app(&app, &ownerships);
|
2017-07-04 18:26:11 +02:00
|
|
|
|
2017-07-15 01:54:54 +02:00
|
|
|
Ok(format!("{}", tokens)
|
|
|
|
.parse()
|
|
|
|
.map_err(|_| "BUG: error parsing the generated code")?)
|
2017-07-04 18:26:11 +02:00
|
|
|
}
|