Compare commits
No commits in common. "c1dc524cab5dcd1e5794ba1604d1f251a0d81d86" and "dfae432055de068c12b72103bdcb3ac9e9fc71f5" have entirely different histories.
c1dc524cab
...
dfae432055
|
@ -1,30 +0,0 @@
|
|||
use super::declaration::{declaration, NetDecl};
|
||||
use super::tokens::{token, Token, TokenKind as tk, TokenSpan};
|
||||
use super::IResult;
|
||||
use nom::multi::many0;
|
||||
use nom::sequence::tuple;
|
||||
use nom::{
|
||||
combinator::{cut, map},
|
||||
sequence::{delimited, preceded},
|
||||
};
|
||||
|
||||
pub struct StateBlock<'a> {
|
||||
name: Token<'a>,
|
||||
items: Vec<NetDecl<'a>>,
|
||||
}
|
||||
|
||||
pub fn state(input: TokenSpan) -> IResult<TokenSpan, StateBlock> {
|
||||
map(
|
||||
preceded(
|
||||
token(tk::State),
|
||||
cut(tuple((
|
||||
token(tk::Ident),
|
||||
delimited(token(tk::LBrace), many0(declaration), token(tk::RBrace)),
|
||||
))),
|
||||
),
|
||||
|(name, items)| StateBlock {
|
||||
name: name.clone(),
|
||||
items,
|
||||
},
|
||||
)(input)
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
use super::module::inputs_list;
|
||||
use super::tokens::TokenKind as tk;
|
||||
use crate::parser::tokens::token;
|
||||
use crate::parser::typename;
|
||||
use crate::parser::IResult;
|
||||
use crate::parser::Module;
|
||||
use crate::parser::TokenSpan;
|
||||
use nom::combinator::cut;
|
||||
use nom::combinator::map;
|
||||
use nom::multi::many0;
|
||||
use nom::sequence::delimited;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
pub fn comb_block(input: TokenSpan) -> IResult<TokenSpan, Module> {
|
||||
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)| Module {
|
||||
// TODO: bring back returns
|
||||
name: name.span(),
|
||||
ports: inputs,
|
||||
items: todo!(),
|
||||
},
|
||||
)(input)
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
pub mod adt;
|
||||
pub mod comb;
|
||||
pub mod declaration;
|
||||
pub mod error;
|
||||
pub mod expression;
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
use nom::{combinator::map, multi::separated_list0};
|
||||
use nom::{
|
||||
branch::alt,
|
||||
combinator::{cut, map},
|
||||
error::context,
|
||||
multi::{many0, separated_list0},
|
||||
sequence::{delimited, preceded, tuple},
|
||||
};
|
||||
|
||||
use crate::parser::{
|
||||
declaration,
|
||||
proc::ProcBlock,
|
||||
assign_statement, declaration,
|
||||
proc::{proc_block, ProcBlock},
|
||||
tokens::{token, TokenKind as tk, TokenSpan},
|
||||
Assign, IResult, NetDecl, Span,
|
||||
typename, Assign, IResult, NetDecl, Span,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -39,12 +45,46 @@ fn port_decl(i: TokenSpan) -> IResult<TokenSpan, PortDecl> {
|
|||
})(i)
|
||||
}
|
||||
|
||||
pub fn inputs_list(input: TokenSpan) -> IResult<TokenSpan, Vec<PortDecl>> {
|
||||
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> {
|
||||
todo!();
|
||||
fn assign_item(input: TokenSpan) -> IResult<TokenSpan, Assign> {
|
||||
context(
|
||||
"assignment",
|
||||
delimited(
|
||||
token(tk::Assign),
|
||||
cut(assign_statement),
|
||||
cut(token(tk::Semicolon)),
|
||||
),
|
||||
)(input)
|
||||
}
|
||||
|
||||
fn module_item(input: TokenSpan) -> IResult<TokenSpan, ModuleItem> {
|
||||
alt((
|
||||
map(assign_item, ModuleItem::Assign),
|
||||
map(proc_block, ModuleItem::Proc),
|
||||
))(input)
|
||||
}
|
||||
|
||||
pub fn module(input: TokenSpan) -> IResult<TokenSpan, Module> {
|
||||
map(
|
||||
preceded(
|
||||
token(tk::Module),
|
||||
cut(tuple((
|
||||
token(tk::Ident),
|
||||
delimited(token(tk::LParen), inputs_list, token(tk::RParen)),
|
||||
preceded(token(tk::RArrow), typename),
|
||||
delimited(token(tk::LBrace), many0(module_item), token(tk::RBrace)),
|
||||
))),
|
||||
),
|
||||
|(name, inputs, _ret, items)| Module {
|
||||
// TODO: bring back returns
|
||||
name: name.span(),
|
||||
ports: inputs,
|
||||
items,
|
||||
},
|
||||
)(input)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -14,7 +14,6 @@ use nom::{
|
|||
};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Token<'a> {
|
||||
span: Span<'a>,
|
||||
kind: TokenKind,
|
||||
|
@ -78,9 +77,7 @@ pub enum TokenKind {
|
|||
Module,
|
||||
Assign,
|
||||
Match,
|
||||
State,
|
||||
Proc,
|
||||
Comb,
|
||||
// Error
|
||||
Error,
|
||||
}
|
||||
|
@ -209,8 +206,6 @@ fn lex_keywords(input: Span) -> IResult<Span, Token> {
|
|||
map(tag("assign"), |_| TokenKind::Assign),
|
||||
map(tag("match"), |_| TokenKind::Match),
|
||||
map(tag("proc"), |_| TokenKind::Proc),
|
||||
map(tag("comb"), |_| TokenKind::Comb),
|
||||
map(tag("state"), |_| TokenKind::Proc),
|
||||
))),
|
||||
|(span, kind)| Token::new(span, kind),
|
||||
)(input)
|
||||
|
|
Loading…
Reference in New Issue