52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
use super::{
|
|
declaration::TypeName,
|
|
expression::{expression, Expression},
|
|
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, opt},
|
|
multi::many1,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub struct CombBlock<'a> {
|
|
pub name: Span<'a>,
|
|
pub ports: Vec<PortDecl<'a>>,
|
|
pub genparams: Vec<TypeName<'a>>,
|
|
pub ret: TypeName<'a>,
|
|
pub expr: Expression<'a>,
|
|
}
|
|
|
|
pub fn comb_block(input: TokenSpan) -> IResult<TokenSpan, CombBlock> {
|
|
map(
|
|
preceded(
|
|
token(tk::Comb),
|
|
cut(tuple((
|
|
token(tk::Ident),
|
|
opt(delimited(
|
|
token(tk::LAngle),
|
|
many1(typename),
|
|
token(tk::RAngle),
|
|
)),
|
|
delimited(token(tk::LParen), inputs_list, token(tk::RParen)),
|
|
preceded(token(tk::RArrow), typename),
|
|
delimited(token(tk::LBrace), expression, token(tk::RBrace)),
|
|
))),
|
|
),
|
|
|(name, genparams, inputs, ret, expr)| CombBlock {
|
|
// TODO: bring back returns
|
|
name: name.span(),
|
|
ports: inputs,
|
|
genparams: genparams.into_iter().flatten().collect(),
|
|
ret,
|
|
expr,
|
|
},
|
|
)(input)
|
|
}
|