diff options
author | 2017-07-14 18:54:54 -0500 | |
---|---|---|
committer | 2017-07-14 18:57:02 -0500 | |
commit | 98596554b3d88a7619bdbc3ac7462a95b7263e96 (patch) | |
tree | b04a8e1e6011f741e045044389e6189d49abf78a /macros/src/lib.rs | |
parent | 59afbf02aa06d976dfd22df4cb87fadf6027a0fb (diff) | |
download | rtic-98596554b3d88a7619bdbc3ac7462a95b7263e96.tar.gz rtic-98596554b3d88a7619bdbc3ac7462a95b7263e96.tar.zst rtic-98596554b3d88a7619bdbc3ac7462a95b7263e96.zip |
split macro parser into its own crate and improve error handling / reporting
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r-- | macros/src/lib.rs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 10839eeb..467cbb93 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,26 +1,44 @@ -#![deny(warnings)] #![feature(proc_macro)] #![recursion_limit = "128"] +#[macro_use] +extern crate error_chain; extern crate proc_macro; #[macro_use] extern crate quote; +extern crate rtfm_syntax; extern crate syn; +use proc_macro::TokenStream; +use rtfm_syntax::App; + +use error::*; + +mod analyze; mod check; -mod syntax; +mod error; mod trans; -mod util; - -use proc_macro::TokenStream; #[proc_macro] pub fn rtfm(ts: TokenStream) -> TokenStream { + match run(ts) { + Err(e) => panic!("{}", error_chain::ChainedError::display(&e)), + Ok(ts) => ts, + } +} + +fn run(ts: TokenStream) -> Result<TokenStream> { let input = format!("{}", ts); - let app = syntax::parse::app(&input); - let ceilings = util::compute_ceilings(&app); - check::resources(&app.resources, &ceilings); + 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); - format!("{}", trans::app(&app, &ceilings)).parse().unwrap() + Ok(format!("{}", tokens) + .parse() + .map_err(|_| "BUG: error parsing the generated code")?) } |