Compare commits

..

No commits in common. "c1dc524cab5dcd1e5794ba1604d1f251a0d81d86" and "dfae432055de068c12b72103bdcb3ac9e9fc71f5" have entirely different histories.

5 changed files with 47 additions and 81 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -1,5 +1,3 @@
pub mod adt;
pub mod comb;
pub mod declaration; pub mod declaration;
pub mod error; pub mod error;
pub mod expression; pub mod expression;

View File

@ -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::{ use crate::parser::{
declaration, assign_statement, declaration,
proc::ProcBlock, proc::{proc_block, ProcBlock},
tokens::{token, TokenKind as tk, TokenSpan}, tokens::{token, TokenKind as tk, TokenSpan},
Assign, IResult, NetDecl, Span, typename, Assign, IResult, NetDecl, Span,
}; };
#[derive(Debug)] #[derive(Debug)]
@ -39,12 +45,46 @@ fn port_decl(i: TokenSpan) -> IResult<TokenSpan, PortDecl> {
})(i) })(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) separated_list0(token(tk::Comma), port_decl)(input)
} }
pub fn module(_input: TokenSpan) -> IResult<TokenSpan, Module> { fn assign_item(input: TokenSpan) -> IResult<TokenSpan, Assign> {
todo!(); 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)] #[cfg(test)]

View File

@ -14,7 +14,6 @@ use nom::{
}; };
use std::fmt; use std::fmt;
#[derive(Clone)]
pub struct Token<'a> { pub struct Token<'a> {
span: Span<'a>, span: Span<'a>,
kind: TokenKind, kind: TokenKind,
@ -78,9 +77,7 @@ pub enum TokenKind {
Module, Module,
Assign, Assign,
Match, Match,
State,
Proc, Proc,
Comb,
// Error // Error
Error, Error,
} }
@ -209,8 +206,6 @@ fn lex_keywords(input: Span) -> IResult<Span, Token> {
map(tag("assign"), |_| TokenKind::Assign), map(tag("assign"), |_| TokenKind::Assign),
map(tag("match"), |_| TokenKind::Match), map(tag("match"), |_| TokenKind::Match),
map(tag("proc"), |_| TokenKind::Proc), map(tag("proc"), |_| TokenKind::Proc),
map(tag("comb"), |_| TokenKind::Comb),
map(tag("state"), |_| TokenKind::Proc),
))), ))),
|(span, kind)| Token::new(span, kind), |(span, kind)| Token::new(span, kind),
)(input) )(input)