Skip to content
Snippets Groups Projects
Commit 5afe78bf authored by pln's avatar pln
Browse files

ips syntax ok

parent 12e37a3c
Branches
No related tags found
No related merge requests found
......@@ -114,17 +114,8 @@ pub enum IpTo {
Method(Ident),
}
///
#[derive(Debug)]
pub struct Ip {
/// Input port type
ty: Ty,
/// Input port binding
to: IpTo,
}
/// `$($Ident: $Ty,)*`
pub type Ips = HashMap<Ident, Ty>;
/// `$($Ident: $Ty > $Path,)*`
pub type Ips = HashMap<Ident, (Ty, Path)>;
/// `crc! { .. }`
#[derive(Debug)]
......
......@@ -2,7 +2,8 @@ use std::collections::{HashMap, HashSet};
use std::iter::Peekable;
use std::slice::Iter;
use syn::{self, DelimToken, Ident, IntTy, Lit, Path, Token, TokenTree, Ty};
use syn::{self, DelimToken, Ident, IntTy, Lit, Path, Token, BinOpToken,
TokenTree, Ty};
use error::*;
......@@ -503,11 +504,11 @@ fn crcs(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Crcs> {
})
}
/// Parses `$($Ident: $Path,)*`
/// Parses `$($Ident: $Ty > $Path,)*`
fn ip(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Ips> {
::parse::delimited(tts, DelimToken::Brace, |tts| {
let mut ips = HashMap::new();
let mut tts = tts.iter();
let mut tts = tts.iter().peekable();
while let Some(tt) = tts.next() {
let ident = if let &TokenTree::Token(Token::Ident(ref id)) = tt {
id
......@@ -530,7 +531,11 @@ fn ip(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Ips> {
let ty = ::parse::ty(&mut tts).chain_err(|| {
format!("parsing `type` for {:?}", ident)
})?;
ips.insert(ident.clone(), ty);
let path = ::parse::path(&mut tts).chain_err(|| "parsing `path`")?;
tts.next();
ips.insert(ident.clone(), (ty, path));
}
Ok(ips)
......@@ -538,17 +543,18 @@ fn ip(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Ips> {
}
/// Parses `$Ty `
fn ty(tts: &mut Iter<TokenTree>) -> Result<Ty> {
fn ty(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Ty> {
let mut fragments = vec![];
loop {
if let Some(tt) = tts.next() {
if tt == &TokenTree::Token(Token::Comma) {
// if tt == &TokenTree::Token(Token::BinOp(BinOpToken::Minus)) {
if tt == &TokenTree::Token(Token::Gt) {
break;
} else {
fragments.push(tt);
}
} else {
bail!("expected comma, found end of macro");
bail!("expected `>`, found end of macro");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment