62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
use nom::{
|
|
branch::alt,
|
|
combinator::map,
|
|
multi::{many1, separated_list0},
|
|
};
|
|
|
|
use crate::parser::{
|
|
adt::{state, struct_def, StateBlock, StructBlock},
|
|
comb::{comb_block, CombBlock},
|
|
declaration,
|
|
proc::ProcBlock,
|
|
tokens::{token, TokenKind as tk, TokenSpan},
|
|
IResult, NetDecl,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub enum PortDirection {
|
|
Input,
|
|
Output,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct PortDecl<'a> {
|
|
pub direction: PortDirection,
|
|
pub net: NetDecl<'a>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Module<'a> {
|
|
pub items: Vec<ModuleItem<'a>>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum ModuleItem<'a> {
|
|
Comb(CombBlock<'a>),
|
|
Proc(ProcBlock<'a>),
|
|
State(StateBlock<'a>),
|
|
Struct(StructBlock<'a>),
|
|
}
|
|
|
|
fn port_decl(i: TokenSpan) -> IResult<TokenSpan, PortDecl> {
|
|
map(declaration, |net| PortDecl {
|
|
direction: PortDirection::Input,
|
|
net,
|
|
})(i)
|
|
}
|
|
|
|
pub fn inputs_list(input: TokenSpan) -> IResult<TokenSpan, Vec<PortDecl>> {
|
|
separated_list0(token(tk::Comma), port_decl)(input)
|
|
}
|
|
|
|
pub fn module(input: TokenSpan) -> IResult<TokenSpan, Module> {
|
|
map(
|
|
many1(alt((
|
|
map(state, ModuleItem::State),
|
|
map(struct_def, ModuleItem::Struct),
|
|
map(comb_block, ModuleItem::Comb),
|
|
))),
|
|
|items| Module { items },
|
|
)(input)
|
|
}
|