diff --git a/src/lib.rs b/src/lib.rs index 495c6b3135b28405c37fe10e30c7235544507997..7e71047ccd5d54b1ae4f99eec52bc53df6832b8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,8 +117,9 @@ pub enum IpTo { /// `$($Ident: $Ty > $Path,)*` pub type Ips = HashMap<Ident, (Ty, Path)>; -/// `$($Ident: $Ty < $Path,)*` -pub type Ops = HashMap<Ident, (Ty, Path)>; +/// `$($Ident: $Ty = $Expr < $Path,)*` +pub type Ops = HashMap<Ident, (Ty, Expr, Path)>; +//pub type Ops = HashMap<Ident, (Ty, Path)>; /// `crc! { .. }` #[derive(Debug)] diff --git a/src/parse.rs b/src/parse.rs index 1dab965c6b6e9688cdddc88a69789dc341734b21..69699546259a30a71a337df4a816cdc58c42a348 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -8,7 +8,7 @@ use syn::{self, DelimToken, Ident, IntTy, Lit, Path, Token, BinOpToken, use error::*; use {Crc, Crcs, Ips, Ops, App, Idle, Init, Resources, Static, Statics, Task, - Tasks}; + Tasks, Expr}; /// Parses the contents of `app! { $App }` pub fn app(input: &str) -> Result<App> { @@ -575,13 +575,21 @@ fn ops(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Ops> { } let ty = - ::parse::ty(&TokenTree::Token(Token::Lt), &mut tts) + ::parse::ty(&TokenTree::Token(Token::Eq), &mut tts) .chain_err(|| format!("parsing `type` for {:?}", ident))?; + + let expr = + ::parse::expr(&TokenTree::Token(Token::Lt), &mut tts) + .chain_err(|| format!("parsing `type` for {:?}", ident))?; + + + + let path = ::parse::path(&mut tts).chain_err(|| "parsing `path`")?; tts.next(); - ops.insert(ident.clone(), (ty, path)); + ops.insert(ident.clone(), (ty, expr, path)); } Ok(ops) }) @@ -606,3 +614,25 @@ fn ty(token: &TokenTree, tts: &mut Peekable<Iter<TokenTree>>) -> Result<Ty> { Ok(syn::parse_type(&format!("{}", quote!(#(#fragments)*)))?) } + +/// Parses `$Expr ` +fn expr( + token: &TokenTree, + tts: &mut Peekable<Iter<TokenTree>>, +) -> Result<::Expr> { + let mut fragments = vec![]; + loop { + if let Some(tt) = tts.next() { + if tt == token { + break; + } else { + fragments.push(tt); + } + } else { + bail!("expected `{:?}`, found end of macro", token); + } + } + + Ok(quote!(#(#fragments)*)) + +}