use nom::{ branch::alt, bytes::complete::tag, character::complete::{alpha1, alphanumeric1, char, multispace0, multispace1, u64 as decimal}, combinator::{consumed, map, opt, recognize}, error::{context, ParseError, VerboseError}, multi::{many0, many1, separated_list0}, sequence::{delimited, pair, preceded, separated_pair, terminated, tuple}, }; use crate::parser::{identifier, ws0, Expression, IResult, Span}; #[derive(Debug)] pub struct ProcBlock<'a> { pub net: Span<'a>, pub items: Vec>, } #[derive(Debug)] pub enum ProcStatement<'a> { IfElse(IfElseBlock), Assign, Match(MatchBlock<'a>), } // TODO: postponed because annoying to implement #[derive(Debug)] pub struct IfElseBlock {} #[derive(Debug)] pub struct MatchBlock<'a> { expr: Expression<'a>, arms: Vec<(&'a str, ProcStatement<'a>)>, } /// parse a statement that is valid inside a proc block fn proc_statement(input: Span) -> IResult { map(nom::character::complete::anychar, |_| { ProcStatement::Match(MatchBlock { expr: Expression::Ident("asdf"), arms: Vec::new(), }) })(input) } pub fn proc_block(input: Span) -> IResult { context( "proc block", map( tuple(( ws0(tag("proc")), ws0(delimited(char('('), ws0(identifier), char(')'))), ws0(delimited(char('{'), many0(ws0(proc_statement)), char('}'))), )), |(_, net, items)| ProcBlock { net, items }, ), )(input) }