mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 14:25:18 +01:00
split macro parser into its own crate and improve error handling / reporting
This commit is contained in:
parent
59afbf02aa
commit
98596554b3
10 changed files with 511 additions and 961 deletions
|
|
@ -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;
|
||||
|
||||
mod check;
|
||||
mod syntax;
|
||||
mod trans;
|
||||
mod util;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use rtfm_syntax::App;
|
||||
|
||||
use error::*;
|
||||
|
||||
mod analyze;
|
||||
mod check;
|
||||
mod error;
|
||||
mod trans;
|
||||
|
||||
#[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",
|
||||
)?;
|
||||
|
||||
format!("{}", trans::app(&app, &ceilings)).parse().unwrap()
|
||||
let ownerships = analyze::app(&app);
|
||||
let tokens = trans::app(&app, &ownerships);
|
||||
|
||||
Ok(format!("{}", tokens)
|
||||
.parse()
|
||||
.map_err(|_| "BUG: error parsing the generated code")?)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue