futilehdl/src/parser/comb.rs

43 lines
1.1 KiB
Rust

use super::{
module::inputs_list,
module::PortDecl,
tokens::{token, TokenKind as tk, TokenSpan},
typename, IResult, Span,
};
use nom::sequence::delimited;
use nom::sequence::preceded;
use nom::sequence::tuple;
use nom::{
combinator::{cut, map},
multi::many0,
};
#[derive(Debug)]
pub struct CombBlock<'a> {
pub name: Span<'a>,
pub ports: Vec<PortDecl<'a>>,
}
pub fn comb_block(input: TokenSpan) -> IResult<TokenSpan, CombBlock> {
map(
preceded(
token(tk::Comb),
cut(tuple((
token(tk::Ident),
delimited(token(tk::LParen), inputs_list, token(tk::RParen)),
preceded(token(tk::RArrow), typename),
delimited(
token(tk::LBrace),
many0(token(tk::Error)),
token(tk::RBrace),
),
))),
),
|(name, inputs, _ret, _items)| CombBlock {
// TODO: bring back returns
name: name.span(),
ports: inputs,
},
)(input)
}