diff --git a/README.md b/README.md index 958f6f4..18eced3 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ A parser library for System Verilog. | declaration | task_declarations | x | x | | | declaration | block_item_declarations | x | x | | | declaration | interface_declarations | x | x | | -| declaration | assertion_declarations | x | | | -| declaration | covergroup_declarations | | | | -| declaration | let_declarations | | | | +| declaration | assertion_declarations | x | x | | +| declaration | covergroup_declarations | x | x | | +| declaration | let_declarations | x | x | | | primitive_instance | primitive_instantiation_and_instances | x | x | | | primitive_instance | primitive_strengths | x | x | x | | primitive_instance | primitive_terminals | x | x | | @@ -44,7 +44,7 @@ A parser library for System Verilog. | udp_declaration_and_instantiation | udp_declaration | | | | | udp_declaration_and_instantiation | udp_ports | | | | | udp_declaration_and_instantiation | udp_body | | | | -| udp_declaration_and_instantiation | udp_instantiation | | | | +| udp_declaration_and_instantiation | udp_instantiation | x | x | | | behavioral_statements | continuous_assignment_and_net_alias | x | x | | | behavioral_statements | procedural_blocks_and_assignments | x | x | | | behavioral_statements | parallel_and_sequential_blocks | x | x | | diff --git a/src/parser/declarations/assertion_declarations.rs b/src/parser/declarations/assertion_declarations.rs index efbc638..affcf15 100644 --- a/src/parser/declarations/assertion_declarations.rs +++ b/src/parser/declarations/assertion_declarations.rs @@ -1,9 +1,10 @@ use crate::ast::*; use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; // ----------------------------------------------------------------------------- @@ -23,11 +24,11 @@ pub struct ConcurrentAssertionItemStatement<'a> { #[derive(Debug, Node)] pub enum ConcurrentAssertionStatement<'a> { - AssertProperty(AssertPropertyStatement<'a>), - AssumeProperty(AssumePropertyStatement<'a>), - CoverProperty(CoverPropertyStatement<'a>), - CoverSequence(CoverSequenceStatement<'a>), - RestrictProperty(RestrictPropertyStatement<'a>), + AssertPropertyStatement(AssertPropertyStatement<'a>), + AssumePropertyStatement(AssumePropertyStatement<'a>), + CoverPropertyStatement(CoverPropertyStatement<'a>), + CoverSequenceStatement(CoverSequenceStatement<'a>), + RestrictPropertyStatement(RestrictPropertyStatement<'a>), } #[derive(Debug, Node)] @@ -62,12 +63,7 @@ pub struct CoverPropertyStatement<'a> { #[derive(Debug, Node)] pub struct ExpectPropertyStatement<'a> { - pub nodes: ( - Symbol<'a>, - Symbol<'a>, - Paren<'a, PropertySpec<'a>>, - ActionBlock<'a>, - ), + pub nodes: (Symbol<'a>, Paren<'a, PropertySpec<'a>>, ActionBlock<'a>), } #[derive(Debug, Node)] @@ -175,7 +171,7 @@ pub struct PropertyPortList<'a> { pub struct PropertyPortItem<'a> { pub nodes: ( Vec>, - Option<(Symbol<'a>, Option>)>, + Option<(Local<'a>, Option>)>, PropertyFormalType<'a>, FormalPortIdentifier<'a>, Vec>, @@ -313,7 +309,7 @@ pub struct PropertyExprFollowedByNonoverlapped<'a> { pub struct PropertyExprNexttime<'a> { pub nodes: ( Symbol<'a>, - Option>>, + Option>>, PropertyExpr<'a>, ), } @@ -322,7 +318,7 @@ pub struct PropertyExprNexttime<'a> { pub struct PropertyExprSNexttime<'a> { pub nodes: ( Symbol<'a>, - Option>>, + Option>>, PropertyExpr<'a>, ), } @@ -331,7 +327,7 @@ pub struct PropertyExprSNexttime<'a> { pub struct PropertyExprAlways<'a> { pub nodes: ( Symbol<'a>, - Option>>, + Option>>, PropertyExpr<'a>, ), } @@ -340,21 +336,21 @@ pub struct PropertyExprAlways<'a> { pub struct PropertyExprSAlways<'a> { pub nodes: ( Symbol<'a>, - Option>>, + Bracket<'a, CycleDelayConstRangeExpression<'a>>, PropertyExpr<'a>, ), } #[derive(Debug, Node)] pub struct PropertyExprEventually<'a> { - pub nodes: (Symbol<'a>, Paren<'a, ConstantRange<'a>>, PropertyExpr<'a>), + pub nodes: (Symbol<'a>, Bracket<'a, ConstantRange<'a>>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprSEventually<'a> { pub nodes: ( Symbol<'a>, - Option>>, + Option>>, PropertyExpr<'a>, ), } @@ -475,7 +471,7 @@ pub struct SequencePortList<'a> { pub struct SequencePortItem<'a> { pub nodes: ( Vec>, - Option<(Symbol<'a>, Option>)>, + Option<(Local<'a>, Option>)>, SequenceFormalType<'a>, FormalPortIdentifier<'a>, Vec>, @@ -696,7 +692,7 @@ pub enum ConsecutiveRepetition<'a> { #[derive(Debug, Node)] pub struct ConsecutiveRepetitionExpression<'a> { - pub nodes: (Bracket<'a, (Symbol<'a>, ConstOrRangeExpression<'a>)>), + pub nodes: (Bracket<'a, (Symbol<'a>, ConstOrRangeExpression<'a>)>,), } #[derive(Debug, Node)] @@ -761,167 +757,1040 @@ pub struct AssertionVariableDeclaration<'a> { // ----------------------------------------------------------------------------- pub fn concurrent_assertion_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + concurrent_assertion_item_statement, + map(checker_instantiation, |x| { + ConcurrentAssertionItem::CheckerInstantiation(x) + }), + ))(s) +} + +pub fn concurrent_assertion_item_statement(s: Span) -> IResult { + let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?; + let (s, b) = concurrent_assertion_statement(s)?; + Ok(( + s, + ConcurrentAssertionItem::Statement(ConcurrentAssertionItemStatement { nodes: (a, b) }), + )) } pub fn concurrent_assertion_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(assert_property_statement, |x| { + ConcurrentAssertionStatement::AssertPropertyStatement(x) + }), + map(assume_property_statement, |x| { + ConcurrentAssertionStatement::AssumePropertyStatement(x) + }), + map(cover_property_statement, |x| { + ConcurrentAssertionStatement::CoverPropertyStatement(x) + }), + map(cover_sequence_statement, |x| { + ConcurrentAssertionStatement::CoverSequenceStatement(x) + }), + map(restrict_property_statement, |x| { + ConcurrentAssertionStatement::RestrictPropertyStatement(x) + }), + ))(s) } pub fn assert_property_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("assert")(s)?; + let (s, b) = symbol("property")(s)?; + let (s, c) = paren(property_spec)(s)?; + let (s, d) = action_block(s)?; + Ok(( + s, + AssertPropertyStatement { + nodes: (a, b, c, d), + }, + )) } pub fn assume_property_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("assume")(s)?; + let (s, b) = symbol("property")(s)?; + let (s, c) = paren(property_spec)(s)?; + let (s, d) = action_block(s)?; + Ok(( + s, + AssumePropertyStatement { + nodes: (a, b, c, d), + }, + )) } pub fn cover_property_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("cover")(s)?; + let (s, b) = symbol("property")(s)?; + let (s, c) = paren(property_spec)(s)?; + let (s, d) = statement_or_null(s)?; + Ok(( + s, + CoverPropertyStatement { + nodes: (a, b, c, d), + }, + )) } pub fn expect_property_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("expect")(s)?; + let (s, b) = paren(property_spec)(s)?; + let (s, c) = action_block(s)?; + Ok((s, ExpectPropertyStatement { nodes: (a, b, c) })) } pub fn cover_sequence_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("cover")(s)?; + let (s, b) = symbol("sequence")(s)?; + let (s, c) = paren(triple( + opt(clocking_event), + opt(triple( + symbol("disable"), + symbol("iff"), + paren(expression_or_dist), + )), + sequence_expr, + ))(s)?; + let (s, d) = statement_or_null(s)?; + Ok(( + s, + CoverSequenceStatement { + nodes: (a, b, c, d), + }, + )) } pub fn restrict_property_statement(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("restrict")(s)?; + let (s, b) = symbol("property")(s)?; + let (s, c) = paren(property_spec)(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + RestrictPropertyStatement { + nodes: (a, b, c, d), + }, + )) } pub fn property_instance(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = ps_or_hierarchical_property_identifier(s)?; + let (s, b) = opt(paren(opt(property_list_of_arguments)))(s)?; + Ok((s, PropertyInstance { nodes: (a, b) })) } pub fn property_list_of_arguments(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + property_list_of_arguments_ordered, + property_list_of_arguments_named, + ))(s) +} + +pub fn property_list_of_arguments_ordered(s: Span) -> IResult { + let (s, a) = list(symbol(","), opt(property_actual_arg))(s)?; + let (s, b) = many0(tuple(( + symbol(","), + symbol("."), + identifier, + paren(opt(property_actual_arg)), + )))(s)?; + Ok(( + s, + PropertyListOfArguments::Ordered(PropertyListOfArgumentsOrdered { nodes: (a, b) }), + )) +} + +pub fn property_list_of_arguments_named(s: Span) -> IResult { + let (s, a) = list( + symbol(","), + triple(symbol("."), identifier, paren(opt(property_actual_arg))), + )(s)?; + Ok(( + s, + PropertyListOfArguments::Named(PropertyListOfArgumentsNamed { nodes: (a,) }), + )) } pub fn property_actual_arg(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(property_expr, |x| PropertyActualArg::PropertyExpr(x)), + map(sequence_actual_arg, |x| { + PropertyActualArg::SequenceActualArg(x) + }), + ))(s) } pub fn assertion_item_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(property_declaration, |x| { + AssertionItemDeclaration::PropertyDeclaration(x) + }), + map(sequence_declaration, |x| { + AssertionItemDeclaration::SequenceDeclaration(x) + }), + map(let_declaration, |x| { + AssertionItemDeclaration::LetDeclaration(x) + }), + ))(s) } pub fn property_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("property")(s)?; + let (s, b) = property_identifier(s)?; + let (s, c) = opt(paren(opt(property_port_list)))(s)?; + let (s, d) = symbol(";")(s)?; + let (s, e) = many0(assertion_variable_declaration)(s)?; + let (s, f) = property_spec(s)?; + let (s, g) = opt(symbol(";"))(s)?; + let (s, h) = symbol("endproperty")(s)?; + let (s, i) = opt(pair(symbol(":"), property_identifier))(s)?; + Ok(( + s, + PropertyDeclaration { + nodes: (a, b, c, d, e, f, g, h, i), + }, + )) } pub fn property_port_list(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = list(symbol(","), property_port_item)(s)?; + Ok((s, PropertyPortList { nodes: (a,) })) } pub fn property_port_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = opt(pair(local, opt(property_lvar_port_direction)))(s)?; + let (s, c) = property_formal_type(s)?; + let (s, d) = formal_port_identifier(s)?; + let (s, e) = many0(variable_dimension)(s)?; + let (s, f) = opt(pair(symbol("="), property_actual_arg))(s)?; + Ok(( + s, + PropertyPortItem { + nodes: (a, b, c, d, e, f), + }, + )) } pub fn property_lvar_port_direction(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("input")(s)?; + Ok((s, PropertyLvarPortDirection::Input(a))) } pub fn property_formal_type(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(sequence_formal_type, |x| { + PropertyFormalType::SequenceFormalType(x) + }), + map(symbol("property"), |x| PropertyFormalType::Property(x)), + ))(s) } pub fn property_spec(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = opt(clocking_event)(s)?; + let (s, b) = opt(triple( + symbol("disable"), + symbol("iff"), + paren(expression_or_dist), + ))(s)?; + let (s, c) = property_expr(s)?; + Ok((s, PropertySpec { nodes: (a, b, c) })) } pub fn property_expr(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + alt(( + map(sequence_expr, |x| PropertyExpr::SequenceExpr(x)), + property_expr_strong, + property_expr_weak, + property_expr_paren, + property_expr_not, + property_expr_or, + property_expr_and, + property_expr_implication_overlapped, + property_expr_implication_nonoverlapped, + property_expr_if, + property_expr_case, + property_expr_followed_by_overlapped, + property_expr_followed_by_nonoverlapped, + property_expr_nexttime, + property_expr_s_nexttime, + )), + alt(( + property_expr_always, + property_expr_s_always, + property_expr_eventually, + property_expr_s_eventually, + property_expr_until, + property_expr_s_until, + property_expr_until_with, + property_expr_s_until_with, + property_expr_implies, + property_expr_iff, + property_expr_accept_on, + property_expr_reject_on, + property_expr_sync_accept_on, + property_expr_sync_reject_on, + map(property_instance, |x| { + PropertyExpr::PropertyInstance(Box::new(x)) + }), + property_expr_clocking_event, + )), + ))(s) +} + +pub fn property_expr_strong(s: Span) -> IResult { + let (s, a) = symbol("strong")(s)?; + let (s, b) = paren(sequence_expr)(s)?; + Ok(( + s, + PropertyExpr::Strong(PropertyExprStrong { nodes: (a, b) }), + )) +} + +pub fn property_expr_weak(s: Span) -> IResult { + let (s, a) = symbol("weak")(s)?; + let (s, b) = paren(sequence_expr)(s)?; + Ok(( + s, + PropertyExpr::Strong(PropertyExprStrong { nodes: (a, b) }), + )) +} + +pub fn property_expr_paren(s: Span) -> IResult { + let (s, a) = paren(sequence_expr)(s)?; + Ok(( + s, + PropertyExpr::Paren(Box::new(PropertyExprParen { nodes: (a,) })), + )) +} + +pub fn property_expr_not(s: Span) -> IResult { + let (s, a) = symbol("not")(s)?; + let (s, b) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Not(Box::new(PropertyExprNot { nodes: (a, b) })), + )) +} + +pub fn property_expr_or(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("or")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Or(Box::new(PropertyExprOr { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_and(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("and")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::And(Box::new(PropertyExprAnd { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_implication_overlapped(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("|->")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::ImplicationOverlapped(Box::new(PropertyExprImplicationOverlapped { + nodes: (a, b, c), + })), + )) +} + +pub fn property_expr_implication_nonoverlapped(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("|=>")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::ImplicationNonoverlapped(Box::new(PropertyExprImplicationNonoverlapped { + nodes: (a, b, c), + })), + )) +} + +pub fn property_expr_if(s: Span) -> IResult { + let (s, a) = symbol("if")(s)?; + let (s, b) = paren(expression_or_dist)(s)?; + let (s, c) = property_expr(s)?; + let (s, d) = opt(pair(symbol("else"), property_expr))(s)?; + Ok(( + s, + PropertyExpr::If(Box::new(PropertyExprIf { + nodes: (a, b, c, d), + })), + )) +} + +pub fn property_expr_case(s: Span) -> IResult { + let (s, a) = symbol("case")(s)?; + let (s, b) = paren(expression_or_dist)(s)?; + let (s, c) = property_case_item(s)?; + let (s, d) = many0(property_case_item)(s)?; + let (s, e) = symbol("endcase")(s)?; + Ok(( + s, + PropertyExpr::Case(Box::new(PropertyExprCase { + nodes: (a, b, c, d, e), + })), + )) +} + +pub fn property_expr_followed_by_overlapped(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("#-#")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::FollowedByOverlapped(Box::new(PropertyExprFollowedByOverlapped { + nodes: (a, b, c), + })), + )) +} + +pub fn property_expr_followed_by_nonoverlapped(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("#=#")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::FollowedByNonoverlapped(Box::new(PropertyExprFollowedByNonoverlapped { + nodes: (a, b, c), + })), + )) +} + +pub fn property_expr_nexttime(s: Span) -> IResult { + let (s, a) = symbol("nexttime")(s)?; + let (s, b) = opt(bracket(constant_expression))(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Nexttime(Box::new(PropertyExprNexttime { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_s_nexttime(s: Span) -> IResult { + let (s, a) = symbol("s_nexttime")(s)?; + let (s, b) = opt(bracket(constant_expression))(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SNexttime(Box::new(PropertyExprSNexttime { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_always(s: Span) -> IResult { + let (s, a) = symbol("always")(s)?; + let (s, b) = opt(bracket(cycle_delay_const_range_expression))(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Always(Box::new(PropertyExprAlways { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_s_always(s: Span) -> IResult { + let (s, a) = symbol("s_always")(s)?; + let (s, b) = bracket(cycle_delay_const_range_expression)(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SAlways(Box::new(PropertyExprSAlways { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_eventually(s: Span) -> IResult { + let (s, a) = symbol("eventually")(s)?; + let (s, b) = bracket(constant_range)(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Eventually(Box::new(PropertyExprEventually { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_s_eventually(s: Span) -> IResult { + let (s, a) = symbol("s_eventually")(s)?; + let (s, b) = opt(bracket(cycle_delay_const_range_expression))(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SEventually(Box::new(PropertyExprSEventually { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_until(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("until")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Until(Box::new(PropertyExprUntil { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_s_until(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("s_until")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SUntil(Box::new(PropertyExprSUntil { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_until_with(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("until_with")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::UntilWith(Box::new(PropertyExprUntilWith { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_s_until_with(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("s_until_with")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SUntilWith(Box::new(PropertyExprSUntilWith { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_implies(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("implies")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Implies(Box::new(PropertyExprImplies { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_iff(s: Span) -> IResult { + let (s, a) = property_expr(s)?; + let (s, b) = symbol("iff")(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::Iff(Box::new(PropertyExprIff { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_accept_on(s: Span) -> IResult { + let (s, a) = symbol("accept_on")(s)?; + let (s, b) = paren(expression_or_dist)(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::AcceptOn(Box::new(PropertyExprAcceptOn { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_reject_on(s: Span) -> IResult { + let (s, a) = symbol("reject_on")(s)?; + let (s, b) = paren(expression_or_dist)(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::RejectOn(Box::new(PropertyExprRejectOn { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_sync_accept_on(s: Span) -> IResult { + let (s, a) = symbol("sync_accept_on")(s)?; + let (s, b) = paren(expression_or_dist)(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SyncAcceptOn(Box::new(PropertyExprSyncAcceptOn { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_sync_reject_on(s: Span) -> IResult { + let (s, a) = symbol("sync_reject_on")(s)?; + let (s, b) = paren(expression_or_dist)(s)?; + let (s, c) = property_expr(s)?; + Ok(( + s, + PropertyExpr::SyncRejectOn(Box::new(PropertyExprSyncRejectOn { nodes: (a, b, c) })), + )) +} + +pub fn property_expr_clocking_event(s: Span) -> IResult { + let (s, a) = clocking_event(s)?; + let (s, b) = property_expr(s)?; + Ok(( + s, + PropertyExpr::ClockingEvent(Box::new(PropertyExprClockingEvent { nodes: (a, b) })), + )) } pub fn property_case_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt((property_case_item_nondefault, property_case_item_default))(s) +} + +pub fn property_case_item_nondefault(s: Span) -> IResult { + let (s, a) = list(symbol(","), expression_or_dist)(s)?; + let (s, b) = symbol(":")(s)?; + let (s, c) = property_expr(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + PropertyCaseItem::Nondefault(PropertyCaseItemNondefault { + nodes: (a, b, c, d), + }), + )) +} + +pub fn property_case_item_default(s: Span) -> IResult { + let (s, a) = symbol("default")(s)?; + let (s, b) = opt(symbol(":"))(s)?; + let (s, c) = property_expr(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + PropertyCaseItem::Default(PropertyCaseItemDefault { + nodes: (a, b, c, d), + }), + )) } pub fn sequence_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("sequence")(s)?; + let (s, b) = sequence_identifier(s)?; + let (s, c) = opt(paren(opt(sequence_port_list)))(s)?; + let (s, d) = symbol(";")(s)?; + let (s, e) = many0(assertion_variable_declaration)(s)?; + let (s, f) = sequence_expr(s)?; + let (s, g) = opt(symbol(";"))(s)?; + let (s, h) = symbol("endsequence")(s)?; + let (s, i) = opt(pair(symbol(":"), sequence_identifier))(s)?; + Ok(( + s, + SequenceDeclaration { + nodes: (a, b, c, d, e, f, g, h, i), + }, + )) } pub fn sequence_port_list(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = list(symbol(","), sequence_port_item)(s)?; + Ok((s, SequencePortList { nodes: (a,) })) } pub fn sequence_port_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = opt(pair(local, opt(sequence_lvar_port_direction)))(s)?; + let (s, c) = sequence_formal_type(s)?; + let (s, d) = formal_port_identifier(s)?; + let (s, e) = many0(variable_dimension)(s)?; + let (s, f) = opt(pair(symbol("="), sequence_actual_arg))(s)?; + Ok(( + s, + SequencePortItem { + nodes: (a, b, c, d, e, f), + }, + )) } pub fn sequence_lvar_port_direction(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(symbol("input"), |x| SequenceLvarPortDirection::Input(x)), + map(symbol("inout"), |x| SequenceLvarPortDirection::Inout(x)), + map(symbol("output"), |x| SequenceLvarPortDirection::Output(x)), + ))(s) } pub fn sequence_formal_type(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(data_type_or_implicit, |x| { + SequenceFormalType::DataTypeOrImplicit(x) + }), + map(symbol("sequence"), |x| SequenceFormalType::Sequence(x)), + map(symbol("untyped"), |x| SequenceFormalType::Untyped(x)), + ))(s) } pub fn sequence_expr(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + sequence_expr_cycle_delay_expr, + sequence_expr_expr_cycle_delay_expr, + sequence_expr_expression, + sequence_expr_instance, + sequence_expr_paren, + sequence_expr_and, + sequence_expr_intersect, + sequence_expr_or, + sequence_expr_first_match, + sequence_expr_throughout, + sequence_expr_within, + sequence_expr_clocking_event, + ))(s) +} + +pub fn sequence_expr_cycle_delay_expr(s: Span) -> IResult { + let (s, a) = cycle_delay_range(s)?; + let (s, b) = sequence_expr(s)?; + let (s, c) = many0(pair(cycle_delay_range, sequence_expr))(s)?; + Ok(( + s, + SequenceExpr::CycleDelayExpr(Box::new(SequenceExprCycleDelayExpr { nodes: (a, b, c) })), + )) +} + +pub fn sequence_expr_expr_cycle_delay_expr(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = cycle_delay_range(s)?; + let (s, c) = sequence_expr(s)?; + let (s, d) = many0(pair(cycle_delay_range, sequence_expr))(s)?; + Ok(( + s, + SequenceExpr::ExprCycleDelayExpr(Box::new(SequenceExprExprCycleDelayExpr { + nodes: (a, b, c, d), + })), + )) +} + +pub fn sequence_expr_expression(s: Span) -> IResult { + let (s, a) = expression_or_dist(s)?; + let (s, b) = opt(boolean_abbrev)(s)?; + Ok(( + s, + SequenceExpr::Expression(SequenceExprExpression { nodes: (a, b) }), + )) +} + +pub fn sequence_expr_instance(s: Span) -> IResult { + let (s, a) = sequence_instance(s)?; + let (s, b) = opt(sequence_abbrev)(s)?; + Ok(( + s, + SequenceExpr::Instance(Box::new(SequenceExprInstance { nodes: (a, b) })), + )) +} + +pub fn sequence_expr_paren(s: Span) -> IResult { + let (s, a) = paren(pair( + sequence_expr, + many0(pair(symbol(","), sequence_match_item)), + ))(s)?; + let (s, b) = opt(sequence_abbrev)(s)?; + Ok(( + s, + SequenceExpr::Paren(Box::new(SequenceExprParen { nodes: (a, b) })), + )) +} + +pub fn sequence_expr_and(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("and")(s)?; + let (s, c) = sequence_expr(s)?; + Ok(( + s, + SequenceExpr::And(Box::new(SequenceExprAnd { nodes: (a, b, c) })), + )) +} + +pub fn sequence_expr_intersect(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("intersect")(s)?; + let (s, c) = sequence_expr(s)?; + Ok(( + s, + SequenceExpr::Intersect(Box::new(SequenceExprIntersect { nodes: (a, b, c) })), + )) +} + +pub fn sequence_expr_or(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("or")(s)?; + let (s, c) = sequence_expr(s)?; + Ok(( + s, + SequenceExpr::Or(Box::new(SequenceExprOr { nodes: (a, b, c) })), + )) +} + +pub fn sequence_expr_first_match(s: Span) -> IResult { + let (s, a) = symbol("first_match")(s)?; + let (s, b) = paren(pair( + sequence_expr, + many0(pair(symbol(","), sequence_match_item)), + ))(s)?; + Ok(( + s, + SequenceExpr::FirstMatch(Box::new(SequenceExprFirstMatch { nodes: (a, b) })), + )) +} + +pub fn sequence_expr_throughout(s: Span) -> IResult { + let (s, a) = expression_or_dist(s)?; + let (s, b) = symbol("throughout")(s)?; + let (s, c) = sequence_expr(s)?; + Ok(( + s, + SequenceExpr::Throughout(Box::new(SequenceExprThroughout { nodes: (a, b, c) })), + )) +} + +pub fn sequence_expr_within(s: Span) -> IResult { + let (s, a) = sequence_expr(s)?; + let (s, b) = symbol("within")(s)?; + let (s, c) = sequence_expr(s)?; + Ok(( + s, + SequenceExpr::Within(Box::new(SequenceExprWithin { nodes: (a, b, c) })), + )) +} + +pub fn sequence_expr_clocking_event(s: Span) -> IResult { + let (s, a) = clocking_event(s)?; + let (s, b) = sequence_expr(s)?; + Ok(( + s, + SequenceExpr::ClockingEvent(Box::new(SequenceExprClockingEvent { nodes: (a, b) })), + )) } pub fn cycle_delay_range(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + cycle_delay_range_primary, + cycle_delay_range_expression, + cycle_delay_range_asterisk, + cycle_delay_range_plus, + ))(s) +} + +pub fn cycle_delay_range_primary(s: Span) -> IResult { + let (s, a) = symbol("##")(s)?; + let (s, b) = constant_primary(s)?; + Ok(( + s, + CycleDelayRange::Primary(CycleDelayRangePrimary { nodes: (a, b) }), + )) +} + +pub fn cycle_delay_range_expression(s: Span) -> IResult { + let (s, a) = symbol("##")(s)?; + let (s, b) = bracket(cycle_delay_const_range_expression)(s)?; + Ok(( + s, + CycleDelayRange::Expression(CycleDelayRangeExpression { nodes: (a, b) }), + )) +} + +pub fn cycle_delay_range_asterisk(s: Span) -> IResult { + let (s, a) = symbol("##")(s)?; + let (s, b) = bracket(symbol("*"))(s)?; + Ok(( + s, + CycleDelayRange::Asterisk(CycleDelayRangeAsterisk { nodes: (a, b) }), + )) +} + +pub fn cycle_delay_range_plus(s: Span) -> IResult { + let (s, a) = symbol("##")(s)?; + let (s, b) = bracket(symbol("+"))(s)?; + Ok(( + s, + CycleDelayRange::Plus(CycleDelayRangePlus { nodes: (a, b) }), + )) } pub fn sequence_method_call(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = sequence_instance(s)?; + let (s, b) = symbol(".")(s)?; + let (s, c) = method_identifier(s)?; + Ok((s, SequenceMethodCall { nodes: (a, b, c) })) } pub fn sequence_match_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(operator_assignment, |x| { + SequenceMatchItem::OperatorAssignment(x) + }), + map(inc_or_dec_expression, |x| { + SequenceMatchItem::IncOrDecExpression(x) + }), + map(subroutine_call, |x| SequenceMatchItem::SubroutineCall(x)), + ))(s) } pub fn sequence_instance(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = ps_or_hierarchical_sequence_identifier(s)?; + let (s, b) = opt(paren(opt(sequence_list_of_arguments)))(s)?; + Ok((s, SequenceInstance { nodes: (a, b) })) } pub fn sequence_list_of_arguments(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + sequence_list_of_arguments_ordered, + sequence_list_of_arguments_named, + ))(s) +} + +pub fn sequence_list_of_arguments_ordered(s: Span) -> IResult { + let (s, a) = list(symbol(","), opt(sequence_actual_arg))(s)?; + let (s, b) = many0(tuple(( + symbol(","), + symbol("."), + identifier, + paren(opt(sequence_actual_arg)), + )))(s)?; + Ok(( + s, + SequenceListOfArguments::Ordered(SequenceListOfArgumentsOrdered { nodes: (a, b) }), + )) +} + +pub fn sequence_list_of_arguments_named(s: Span) -> IResult { + let (s, a) = list( + symbol(","), + triple(symbol("."), identifier, paren(opt(sequence_actual_arg))), + )(s)?; + Ok(( + s, + SequenceListOfArguments::Named(SequenceListOfArgumentsNamed { nodes: (a,) }), + )) } pub fn sequence_actual_arg(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(event_expression, |x| SequenceActualArg::EventExpression(x)), + map(sequence_expr, |x| SequenceActualArg::SequenceExpr(x)), + ))(s) } pub fn boolean_abbrev(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(consecutive_repetition, |x| { + BooleanAbbrev::ConsecutiveRepetition(x) + }), + map(non_consecutive_repetition, |x| { + BooleanAbbrev::NonConsecutiveRepetition(x) + }), + map(goto_repetition, |x| BooleanAbbrev::GotoRepetition(x)), + ))(s) } pub fn sequence_abbrev(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = consecutive_repetition(s)?; + Ok((s, SequenceAbbrev { nodes: (a,) })) } pub fn consecutive_repetition(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + consecutive_repetition_expression, + consecutive_repetition_asterisk, + consecutive_repetition_plus, + ))(s) +} + +pub fn consecutive_repetition_expression(s: Span) -> IResult { + let (s, a) = bracket(pair(symbol("*"), const_or_range_expression))(s)?; + Ok(( + s, + ConsecutiveRepetition::Expression(ConsecutiveRepetitionExpression { nodes: (a,) }), + )) +} + +pub fn consecutive_repetition_asterisk(s: Span) -> IResult { + let (s, a) = bracket(symbol("*"))(s)?; + Ok(( + s, + ConsecutiveRepetition::Asterisk(ConsecutiveRepetitionAsterisk { nodes: (a,) }), + )) +} + +pub fn consecutive_repetition_plus(s: Span) -> IResult { + let (s, a) = bracket(symbol("+"))(s)?; + Ok(( + s, + ConsecutiveRepetition::Plus(ConsecutiveRepetitionPlus { nodes: (a,) }), + )) } pub fn non_consecutive_repetition(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = bracket(pair(symbol("="), const_or_range_expression))(s)?; + Ok((s, NonConsecutiveRepetition { nodes: (a,) })) } pub fn goto_repetition(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = bracket(pair(symbol("->"), const_or_range_expression))(s)?; + Ok((s, GotoRepetition { nodes: (a,) })) } pub fn const_or_range_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(constant_expression, |x| { + ConstOrRangeExpression::ConstantExpression(x) + }), + map(cycle_delay_const_range_expression, |x| { + ConstOrRangeExpression::CycleDelayConstRangeExpression(x) + }), + ))(s) } pub fn cycle_delay_const_range_expression( s: Span, ) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + cycle_delay_const_range_expression_binary, + cycle_delay_const_range_expression_dollar, + ))(s) +} + +pub fn cycle_delay_const_range_expression_binary( + s: Span, +) -> IResult { + let (s, a) = constant_expression(s)?; + let (s, b) = symbol(":")(s)?; + let (s, c) = constant_expression(s)?; + Ok(( + s, + CycleDelayConstRangeExpression::Binary(CycleDelayConstRangeExpressionBinary { + nodes: (a, b, c), + }), + )) +} + +pub fn cycle_delay_const_range_expression_dollar( + s: Span, +) -> IResult { + let (s, a) = constant_expression(s)?; + let (s, b) = symbol(":")(s)?; + let (s, c) = symbol("$")(s)?; + Ok(( + s, + CycleDelayConstRangeExpression::Dollar(CycleDelayConstRangeExpressionDollar { + nodes: (a, b, c), + }), + )) } pub fn expression_or_dist(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = expression(s)?; + let (s, b) = opt(pair(symbol("dist"), brace(dist_list)))(s)?; + Ok((s, ExpressionOrDist { nodes: (a, b) })) } pub fn assertion_variable_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = var_data_type(s)?; + let (s, b) = list_of_variable_decl_assignments(s)?; + let (s, c) = symbol(";")(s)?; + Ok((s, AssertionVariableDeclaration { nodes: (a, b, c) })) } diff --git a/src/parser/declarations/covergroup_declarations.rs b/src/parser/declarations/covergroup_declarations.rs index f62855a..1beeb4a 100644 --- a/src/parser/declarations/covergroup_declarations.rs +++ b/src/parser/declarations/covergroup_declarations.rs @@ -1,20 +1,24 @@ use crate::ast::*; use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; // ----------------------------------------------------------------------------- #[derive(Debug, Node)] pub struct CovergroupDeclaration<'a> { pub nodes: ( - Identifier<'a>, - Option>, + Symbol<'a>, + CovergroupIdentifier<'a>, + Option>>>, Option>, + Symbol<'a>, Vec>, - Identifier<'a>, + Symbol<'a>, + Option<(Symbol<'a>, CovergroupIdentifier<'a>)>, ), } @@ -31,7 +35,7 @@ pub struct CoverageSpecOrOptionSpec<'a> { #[derive(Debug, Node)] pub struct CoverageSpecOrOptionOption<'a> { - pub nodes: (Vec>, CoverageOption<'a>), + pub nodes: (Vec>, CoverageOption<'a>, Symbol<'a>), } #[derive(Debug, Node)] @@ -42,12 +46,24 @@ pub enum CoverageOption<'a> { #[derive(Debug, Node)] pub struct CoverageOptionOption<'a> { - pub nodes: (Identifier<'a>, Expression<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + MemberIdentifier<'a>, + Symbol<'a>, + Expression<'a>, + ), } #[derive(Debug, Node)] pub struct CoverageOptionTypeOption<'a> { - pub nodes: (Identifier<'a>, ConstantExpression<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + MemberIdentifier<'a>, + Symbol<'a>, + ConstantExpression<'a>, + ), } #[derive(Debug, Node)] @@ -65,12 +81,17 @@ pub enum CoverageEvent<'a> { #[derive(Debug, Node)] pub struct CoverageEventSample<'a> { - pub nodes: (Option>,), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Symbol<'a>, + Paren<'a, Option>>, + ), } #[derive(Debug, Node)] pub struct CoverageEventAt<'a> { - pub nodes: (BlockEventExpression<'a>,), + pub nodes: (Symbol<'a>, Paren<'a, BlockEventExpression<'a>>), } #[derive(Debug, Node)] @@ -82,23 +103,27 @@ pub enum BlockEventExpression<'a> { #[derive(Debug, Node)] pub struct BlockEventExpressionOr<'a> { - pub nodes: (BlockEventExpression<'a>, BlockEventExpression<'a>), + pub nodes: ( + BlockEventExpression<'a>, + Symbol<'a>, + BlockEventExpression<'a>, + ), } #[derive(Debug, Node)] pub struct BlockEventExpressionBegin<'a> { - pub nodes: (HierarchicalBtfIdentifier<'a>,), + pub nodes: (Symbol<'a>, HierarchicalBtfIdentifier<'a>), } #[derive(Debug, Node)] pub struct BlockEventExpressionEnd<'a> { - pub nodes: (HierarchicalBtfIdentifier<'a>,), + pub nodes: (Symbol<'a>, HierarchicalBtfIdentifier<'a>), } #[derive(Debug, Node)] pub enum HierarchicalBtfIdentifier<'a> { - Tf(Identifier<'a>), - Block(Identifier<'a>), + HierarchicalTfIdentifier(HierarchicalTfIdentifier<'a>), + HierarchicalBlockIdentifier(HierarchicalBlockIdentifier<'a>), Method(HierarchicalBtfIdentifierMethod<'a>), } @@ -106,22 +131,27 @@ pub enum HierarchicalBtfIdentifier<'a> { pub struct HierarchicalBtfIdentifierMethod<'a> { pub nodes: ( Option>, - Identifier<'a>, + MethodIdentifier<'a>, ), } #[derive(Debug, Node)] pub enum HierarchicalIdentifierOrClassScope<'a> { - HierarchicalIdentifier(HierarchicalIdentifier<'a>), + HierarchicalIdentifier((HierarchicalIdentifier<'a>, Symbol<'a>)), ClassScope(ClassScope<'a>), } #[derive(Debug, Node)] pub struct CoverPoint<'a> { pub nodes: ( - Option<(Option>, Identifier<'a>)>, + Option<( + Option>, + CoverPointIdentifier<'a>, + Symbol<'a>, + )>, + Symbol<'a>, Expression<'a>, - Option>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, BinsOrEmpty<'a>, ), } @@ -134,12 +164,20 @@ pub enum BinsOrEmpty<'a> { #[derive(Debug, Node)] pub struct BinsOrEmptyNonEmpty<'a> { - pub nodes: (Vec>, Vec>), + pub nodes: ( + Brace< + 'a, + ( + Vec>, + Vec<(BinsOrOptions<'a>, Symbol<'a>)>, + ), + >, + ), } #[derive(Debug, Node)] pub enum BinsOrOptions<'a> { - Option(CoverageOption<'a>), + CoverageOption(CoverageOption<'a>), Covergroup(BinsOrOptionsCovergroup<'a>), CoverPoint(BinsOrOptionsCoverPoint<'a>), SetCovergroup(BinsOrOptionsSetCovergroup<'a>), @@ -153,11 +191,12 @@ pub struct BinsOrOptionsCovergroup<'a> { pub nodes: ( Option>, BinsKeyword<'a>, - Identifier<'a>, - Option>, - CovergroupRangeList<'a>, - Option>, - Option>, + BinIdentifier<'a>, + Option>>>, + Symbol<'a>, + Brace<'a, CovergroupRangeList<'a>>, + Option<(Symbol<'a>, Paren<'a, WithCovergroupExpression<'a>>)>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, ), } @@ -171,11 +210,13 @@ pub struct BinsOrOptionsCoverPoint<'a> { pub nodes: ( Option>, BinsKeyword<'a>, - Identifier<'a>, - Option>, - Identifier<'a>, - Option>, - Option>, + BinIdentifier<'a>, + Option>>>, + Symbol<'a>, + CoverPointIdentifier<'a>, + Symbol<'a>, + Paren<'a, WithCovergroupExpression<'a>>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, ), } @@ -184,10 +225,11 @@ pub struct BinsOrOptionsSetCovergroup<'a> { pub nodes: ( Option>, BinsKeyword<'a>, - Identifier<'a>, - Option>, + BinIdentifier<'a>, + Option>>>, + Symbol<'a>, SetCovergroupExpression<'a>, - Option>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, ), } @@ -196,9 +238,11 @@ pub struct BinsOrOptionsTransList<'a> { pub nodes: ( Option>, BinsKeyword<'a>, - Identifier<'a>, + BinIdentifier<'a>, + Option<(Symbol<'a>, Symbol<'a>)>, + Symbol<'a>, TransList<'a>, - Option>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, ), } @@ -206,15 +250,24 @@ pub struct BinsOrOptionsTransList<'a> { pub struct BinsOrOptionsDefault<'a> { pub nodes: ( BinsKeyword<'a>, - Identifier<'a>, - Option>, - Option>, + BinIdentifier<'a>, + Option>>>, + Symbol<'a>, + Symbol<'a>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, ), } #[derive(Debug, Node)] pub struct BinsOrOptionsDefaultSequence<'a> { - pub nodes: (BinsKeyword<'a>, Identifier<'a>, Option>), + pub nodes: ( + BinsKeyword<'a>, + BinIdentifier<'a>, + Symbol<'a>, + Symbol<'a>, + Symbol<'a>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, + ), } #[derive(Debug, Node)] @@ -226,35 +279,35 @@ pub enum BinsKeyword<'a> { #[derive(Debug, Node)] pub struct TransList<'a> { - pub nodes: (Vec>,), + pub nodes: (List, Paren<'a, TransSet<'a>>>,), } #[derive(Debug, Node)] pub struct TransSet<'a> { - pub nodes: (TransRangeList<'a>, Vec>), + pub nodes: (List, TransRangeList<'a>>,), } #[derive(Debug, Node)] pub enum TransRangeList<'a> { - Single(TransItem<'a>), + TransItem(TransItem<'a>), Asterisk(TransRangeListAsterisk<'a>), - Right(TransRangeListRight<'a>), + Arrow(TransRangeListArrow<'a>), Equal(TransRangeListEqual<'a>), } #[derive(Debug, Node)] pub struct TransRangeListAsterisk<'a> { - pub nodes: (TransItem<'a>, RepeatRange<'a>), + pub nodes: (TransItem<'a>, Bracket<'a, (Symbol<'a>, RepeatRange<'a>)>), } #[derive(Debug, Node)] -pub struct TransRangeListRight<'a> { - pub nodes: (TransItem<'a>, RepeatRange<'a>), +pub struct TransRangeListArrow<'a> { + pub nodes: (TransItem<'a>, Bracket<'a, (Symbol<'a>, RepeatRange<'a>)>), } #[derive(Debug, Node)] pub struct TransRangeListEqual<'a> { - pub nodes: (TransItem<'a>, RepeatRange<'a>), + pub nodes: (TransItem<'a>, Bracket<'a, (Symbol<'a>, RepeatRange<'a>)>), } #[derive(Debug, Node)] @@ -264,34 +317,39 @@ pub struct TransItem<'a> { #[derive(Debug, Node)] pub enum RepeatRange<'a> { - Single(CovergroupExpression<'a>), + CovergroupExpression(CovergroupExpression<'a>), Binary(RepeatRangeBinary<'a>), } #[derive(Debug, Node)] pub struct RepeatRangeBinary<'a> { - pub nodes: (CovergroupExpression<'a>, CovergroupExpression<'a>), + pub nodes: ( + CovergroupExpression<'a>, + Symbol<'a>, + CovergroupExpression<'a>, + ), } #[derive(Debug, Node)] pub struct CoverCross<'a> { pub nodes: ( - Option>, + Option<(CrossIdentifier<'a>, Symbol<'a>)>, + Symbol<'a>, ListOfCrossItems<'a>, - Option>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, CrossBody<'a>, ), } #[derive(Debug, Node)] pub struct ListOfCrossItems<'a> { - pub nodes: (CrossItem<'a>, CrossItem<'a>, Option>), + pub nodes: (CrossItem<'a>, List, CrossItem<'a>>), } #[derive(Debug, Node)] pub enum CrossItem<'a> { - CoverPointIdentifier(Identifier<'a>), - VariableIdentifier(Identifier<'a>), + CoverPointIdentifier(CoverPointIdentifier<'a>), + VariableIdentifier(VariableIdentifier<'a>), } #[derive(Debug, Node)] @@ -302,13 +360,13 @@ pub enum CrossBody<'a> { #[derive(Debug, Node)] pub struct CrossBodyNonEmpty<'a> { - pub nodes: (Vec>), + pub nodes: (Brace<'a, Vec<(CrossBodyItem<'a>, Symbol<'a>)>>,), } #[derive(Debug, Node)] pub enum CrossBodyItem<'a> { FunctionDeclaration(FunctionDeclaration<'a>), - BinsSelectionOrOption(BinsSelectionOrOption<'a>), + BinsSelectionOrOption((BinsSelectionOrOption<'a>, Symbol<'a>)), } #[derive(Debug, Node)] @@ -331,9 +389,10 @@ pub struct BinsSelectionOrOptionBins<'a> { pub struct BinsSelection<'a> { pub nodes: ( BinsKeyword<'a>, - Identifier<'a>, + BinIdentifier<'a>, + Symbol<'a>, SelectExpression<'a>, - Option>, + Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>, ), } @@ -345,36 +404,37 @@ pub enum SelectExpression<'a> { Or(Box>), Paren(Box>), With(Box>), - CrossIdentifier(Identifier<'a>), + CrossIdentifier(CrossIdentifier<'a>), CrossSet(SelectExpressionCrossSet<'a>), } #[derive(Debug, Node)] pub struct SelectExpressionNot<'a> { - pub nodes: (SelectCondition<'a>,), + pub nodes: (Symbol<'a>, SelectCondition<'a>), } #[derive(Debug, Node)] pub struct SelectExpressionAnd<'a> { - pub nodes: (SelectExpression<'a>, SelectExpression<'a>), + pub nodes: (SelectExpression<'a>, Symbol<'a>, SelectExpression<'a>), } #[derive(Debug, Node)] pub struct SelectExpressionOr<'a> { - pub nodes: (SelectExpression<'a>, SelectExpression<'a>), + pub nodes: (SelectExpression<'a>, Symbol<'a>, SelectExpression<'a>), } #[derive(Debug, Node)] pub struct SelectExpressionParen<'a> { - pub nodes: (SelectExpression<'a>,), + pub nodes: (Paren<'a, SelectExpression<'a>>,), } #[derive(Debug, Node)] pub struct SelectExpressionWith<'a> { pub nodes: ( SelectExpression<'a>, - WithCovergroupExpression<'a>, - Option>, + Symbol<'a>, + Paren<'a, WithCovergroupExpression<'a>>, + Option<(Symbol<'a>, IntegerCovergroupExpression<'a>)>, ), } @@ -382,40 +442,56 @@ pub struct SelectExpressionWith<'a> { pub struct SelectExpressionCrossSet<'a> { pub nodes: ( CrossSetExpression<'a>, - Option>, + Option<(Symbol<'a>, IntegerCovergroupExpression<'a>)>, ), } #[derive(Debug, Node)] pub struct SelectCondition<'a> { - pub nodes: (BinsExpression<'a>, Option>), + pub nodes: ( + Symbol<'a>, + Paren<'a, BinsExpression<'a>>, + Option<(Symbol<'a>, Brace<'a, CovergroupRangeList<'a>>)>, + ), } #[derive(Debug, Node)] pub enum BinsExpression<'a> { - VariableIdentifier(Identifier<'a>), + VariableIdentifier(VariableIdentifier<'a>), CoverPoint(BinsExpressionCoverPoint<'a>), } #[derive(Debug, Node)] pub struct BinsExpressionCoverPoint<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: ( + CoverPointIdentifier<'a>, + Option<(Symbol<'a>, BinIdentifier<'a>)>, + ), } #[derive(Debug, Node)] pub struct CovergroupRangeList<'a> { - pub nodes: (Vec>,), + pub nodes: (List, CovergroupValueRange<'a>>,), } #[derive(Debug, Node)] pub enum CovergroupValueRange<'a> { - Single(CovergroupExpression<'a>), + CovergroupExpression(CovergroupExpression<'a>), Binary(CovergroupValueRangeBinary<'a>), } #[derive(Debug, Node)] pub struct CovergroupValueRangeBinary<'a> { - pub nodes: (CovergroupExpression<'a>, CovergroupExpression<'a>), + pub nodes: ( + Bracket< + 'a, + ( + CovergroupExpression<'a>, + Symbol<'a>, + CovergroupExpression<'a>, + ), + >, + ), } #[derive(Debug, Node)] @@ -446,133 +522,644 @@ pub struct CovergroupExpression<'a> { // ----------------------------------------------------------------------------- pub fn covergroup_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("covergroup")(s)?; + let (s, b) = covergroup_identifier(s)?; + let (s, c) = opt(paren(opt(tf_port_list)))(s)?; + let (s, d) = opt(coverage_event)(s)?; + let (s, e) = symbol(";")(s)?; + let (s, f) = many0(coverage_spec_or_option)(s)?; + let (s, g) = symbol("endgroup")(s)?; + let (s, h) = opt(pair(symbol(":"), covergroup_identifier))(s)?; + Ok(( + s, + CovergroupDeclaration { + nodes: (a, b, c, d, e, f, g, h), + }, + )) } pub fn coverage_spec_or_option(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt((coverage_spec_or_option_spec, coverage_spec_or_option_option))(s) +} + +pub fn coverage_spec_or_option_spec(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = coverage_spec(s)?; + Ok(( + s, + CoverageSpecOrOption::Spec(CoverageSpecOrOptionSpec { nodes: (a, b) }), + )) +} + +pub fn coverage_spec_or_option_option(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = coverage_option(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + CoverageSpecOrOption::Option(CoverageSpecOrOptionOption { nodes: (a, b, c) }), + )) } pub fn coverage_option(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt((coverage_option_option, coverage_option_type_option))(s) +} + +pub fn coverage_option_option(s: Span) -> IResult { + let (s, a) = symbol("option")(s)?; + let (s, b) = symbol(".")(s)?; + let (s, c) = member_identifier(s)?; + let (s, d) = symbol("=")(s)?; + let (s, e) = expression(s)?; + Ok(( + s, + CoverageOption::Option(CoverageOptionOption { + nodes: (a, b, c, d, e), + }), + )) +} + +pub fn coverage_option_type_option(s: Span) -> IResult { + let (s, a) = symbol("type_option")(s)?; + let (s, b) = symbol(".")(s)?; + let (s, c) = member_identifier(s)?; + let (s, d) = symbol("=")(s)?; + let (s, e) = constant_expression(s)?; + Ok(( + s, + CoverageOption::TypeOption(CoverageOptionTypeOption { + nodes: (a, b, c, d, e), + }), + )) } pub fn coverage_spec(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(cover_point, |x| CoverageSpec::CoverPoint(x)), + map(cover_cross, |x| CoverageSpec::CoverCross(x)), + ))(s) } pub fn coverage_event(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(clocking_event, |x| CoverageEvent::ClockingEvent(x)), + coverage_event_sample, + coverage_event_at, + ))(s) +} + +pub fn coverage_event_sample(s: Span) -> IResult { + let (s, a) = symbol("with")(s)?; + let (s, b) = symbol("function")(s)?; + let (s, c) = symbol("sample")(s)?; + let (s, d) = paren(opt(tf_port_list))(s)?; + Ok(( + s, + CoverageEvent::Sample(CoverageEventSample { + nodes: (a, b, c, d), + }), + )) +} + +pub fn coverage_event_at(s: Span) -> IResult { + let (s, a) = symbol("@@")(s)?; + let (s, b) = paren(block_event_expression)(s)?; + Ok((s, CoverageEvent::At(CoverageEventAt { nodes: (a, b) }))) } pub fn block_event_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + block_event_expression_or, + block_event_expression_begin, + block_event_expression_end, + ))(s) +} + +pub fn block_event_expression_or(s: Span) -> IResult { + let (s, a) = block_event_expression(s)?; + let (s, b) = symbol("or")(s)?; + let (s, c) = block_event_expression(s)?; + Ok(( + s, + BlockEventExpression::Or(Box::new(BlockEventExpressionOr { nodes: (a, b, c) })), + )) +} + +pub fn block_event_expression_begin(s: Span) -> IResult { + let (s, a) = symbol("begin")(s)?; + let (s, b) = hierarchical_btf_identifier(s)?; + Ok(( + s, + BlockEventExpression::Begin(BlockEventExpressionBegin { nodes: (a, b) }), + )) +} + +pub fn block_event_expression_end(s: Span) -> IResult { + let (s, a) = symbol("end")(s)?; + let (s, b) = hierarchical_btf_identifier(s)?; + Ok(( + s, + BlockEventExpression::End(BlockEventExpressionEnd { nodes: (a, b) }), + )) } pub fn hierarchical_btf_identifier(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(hierarchical_tf_identifier, |x| { + HierarchicalBtfIdentifier::HierarchicalTfIdentifier(x) + }), + map(hierarchical_block_identifier, |x| { + HierarchicalBtfIdentifier::HierarchicalBlockIdentifier(x) + }), + hierarchical_btf_identifier_method, + ))(s) +} + +pub fn hierarchical_btf_identifier_method(s: Span) -> IResult { + let (s, a) = opt(hierarchical_identifier_or_class_scope)(s)?; + let (s, b) = method_identifier(s)?; + Ok(( + s, + HierarchicalBtfIdentifier::Method(HierarchicalBtfIdentifierMethod { nodes: (a, b) }), + )) +} + +pub fn hierarchical_identifier_or_class_scope( + s: Span, +) -> IResult { + alt(( + map(pair(hierarchical_identifier, symbol(".")), |x| { + HierarchicalIdentifierOrClassScope::HierarchicalIdentifier(x) + }), + map(class_scope, |x| { + HierarchicalIdentifierOrClassScope::ClassScope(x) + }), + ))(s) } pub fn cover_point(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = opt(triple( + opt(data_type_or_implicit), + cover_point_identifier, + symbol(":"), + ))(s)?; + let (s, b) = symbol("coverpoint")(s)?; + let (s, c) = expression(s)?; + let (s, d) = opt(pair(symbol("iff"), paren(expression)))(s)?; + let (s, e) = bins_or_empty(s)?; + Ok(( + s, + CoverPoint { + nodes: (a, b, c, d, e), + }, + )) } pub fn bins_or_empty(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + bins_or_empty_non_empty, + map(symbol(";"), |x| BinsOrEmpty::Empty(x)), + ))(s) +} + +pub fn bins_or_empty_non_empty(s: Span) -> IResult { + let (s, a) = brace(pair( + many0(attribute_instance), + many0(pair(bins_or_options, symbol(";"))), + ))(s)?; + Ok(( + s, + BinsOrEmpty::NonEmpty(BinsOrEmptyNonEmpty { nodes: (a,) }), + )) } pub fn bins_or_options(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(coverage_option, |x| BinsOrOptions::CoverageOption(x)), + bins_or_options_covergroup, + bins_or_options_cover_point, + bins_or_options_set_covergroup, + bins_or_options_trans_list, + bins_or_options_default, + bins_or_options_default_sequence, + ))(s) +} + +pub fn bins_or_options_covergroup(s: Span) -> IResult { + let (s, a) = opt(wildcard)(s)?; + let (s, b) = bins_keyword(s)?; + let (s, c) = bin_identifier(s)?; + let (s, d) = opt(bracket(opt(covergroup_expression)))(s)?; + let (s, e) = symbol("=")(s)?; + let (s, f) = brace(covergroup_range_list)(s)?; + let (s, g) = opt(pair(symbol("with"), paren(with_covergroup_expression)))(s)?; + let (s, h) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsOrOptions::Covergroup(BinsOrOptionsCovergroup { + nodes: (a, b, c, d, e, f, g, h), + }), + )) +} + +pub fn wildcard(s: Span) -> IResult { + let (s, a) = symbol("wildcard")(s)?; + Ok((s, Wildcard { nodes: (a,) })) +} + +pub fn bins_or_options_cover_point(s: Span) -> IResult { + let (s, a) = opt(wildcard)(s)?; + let (s, b) = bins_keyword(s)?; + let (s, c) = bin_identifier(s)?; + let (s, d) = opt(bracket(opt(covergroup_expression)))(s)?; + let (s, e) = symbol("=")(s)?; + let (s, f) = cover_point_identifier(s)?; + let (s, g) = symbol("with")(s)?; + let (s, h) = paren(with_covergroup_expression)(s)?; + let (s, i) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsOrOptions::CoverPoint(BinsOrOptionsCoverPoint { + nodes: (a, b, c, d, e, f, g, h, i), + }), + )) +} + +pub fn bins_or_options_set_covergroup(s: Span) -> IResult { + let (s, a) = opt(wildcard)(s)?; + let (s, b) = bins_keyword(s)?; + let (s, c) = bin_identifier(s)?; + let (s, d) = opt(bracket(opt(covergroup_expression)))(s)?; + let (s, e) = symbol("=")(s)?; + let (s, f) = set_covergroup_expression(s)?; + let (s, g) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsOrOptions::SetCovergroup(BinsOrOptionsSetCovergroup { + nodes: (a, b, c, d, e, f, g), + }), + )) +} + +pub fn bins_or_options_trans_list(s: Span) -> IResult { + let (s, a) = opt(wildcard)(s)?; + let (s, b) = bins_keyword(s)?; + let (s, c) = bin_identifier(s)?; + let (s, d) = opt(pair(symbol("["), symbol("]")))(s)?; + let (s, e) = symbol("=")(s)?; + let (s, f) = trans_list(s)?; + let (s, g) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsOrOptions::TransList(BinsOrOptionsTransList { + nodes: (a, b, c, d, e, f, g), + }), + )) +} + +pub fn bins_or_options_default(s: Span) -> IResult { + let (s, a) = bins_keyword(s)?; + let (s, b) = bin_identifier(s)?; + let (s, c) = opt(bracket(opt(covergroup_expression)))(s)?; + let (s, d) = symbol("=")(s)?; + let (s, e) = symbol("default")(s)?; + let (s, f) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsOrOptions::Default(BinsOrOptionsDefault { + nodes: (a, b, c, d, e, f), + }), + )) +} + +pub fn bins_or_options_default_sequence(s: Span) -> IResult { + let (s, a) = bins_keyword(s)?; + let (s, b) = bin_identifier(s)?; + let (s, c) = symbol("=")(s)?; + let (s, d) = symbol("default")(s)?; + let (s, e) = symbol("sequence")(s)?; + let (s, f) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsOrOptions::DefaultSequence(BinsOrOptionsDefaultSequence { + nodes: (a, b, c, d, e, f), + }), + )) } pub fn bins_keyword(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(symbol("bins"), |x| BinsKeyword::Bins(x)), + map(symbol("illegal_bins"), |x| BinsKeyword::IllegalBins(x)), + map(symbol("ignore_bins"), |x| BinsKeyword::IgnoreBins(x)), + ))(s) } pub fn trans_list(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = list(symbol(","), paren(trans_set))(s)?; + Ok((s, TransList { nodes: (a,) })) } pub fn trans_set(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = list(symbol("=>"), trans_range_list)(s)?; + Ok((s, TransSet { nodes: (a,) })) } pub fn trans_range_list(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(trans_item, |x| TransRangeList::TransItem(x)), + trans_range_list_asterisk, + trans_range_list_arrow, + trans_range_list_equal, + ))(s) +} + +pub fn trans_range_list_asterisk(s: Span) -> IResult { + let (s, a) = trans_item(s)?; + let (s, b) = bracket(pair(symbol("*"), repeat_range))(s)?; + Ok(( + s, + TransRangeList::Asterisk(TransRangeListAsterisk { nodes: (a, b) }), + )) +} + +pub fn trans_range_list_arrow(s: Span) -> IResult { + let (s, a) = trans_item(s)?; + let (s, b) = bracket(pair(symbol("->"), repeat_range))(s)?; + Ok(( + s, + TransRangeList::Arrow(TransRangeListArrow { nodes: (a, b) }), + )) +} + +pub fn trans_range_list_equal(s: Span) -> IResult { + let (s, a) = trans_item(s)?; + let (s, b) = bracket(pair(symbol("="), repeat_range))(s)?; + Ok(( + s, + TransRangeList::Equal(TransRangeListEqual { nodes: (a, b) }), + )) } pub fn trans_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = covergroup_range_list(s)?; + Ok((s, TransItem { nodes: (a,) })) } pub fn repeat_range(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(covergroup_expression, |x| { + RepeatRange::CovergroupExpression(x) + }), + repeat_range_binary, + ))(s) +} + +pub fn repeat_range_binary(s: Span) -> IResult { + let (s, a) = covergroup_expression(s)?; + let (s, b) = symbol(":")(s)?; + let (s, c) = covergroup_expression(s)?; + Ok(( + s, + RepeatRange::Binary(RepeatRangeBinary { nodes: (a, b, c) }), + )) } pub fn cover_cross(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = opt(pair(cross_identifier, symbol(":")))(s)?; + let (s, b) = symbol("cross")(s)?; + let (s, c) = list_of_cross_items(s)?; + let (s, d) = opt(pair(symbol("iff"), paren(expression)))(s)?; + let (s, e) = cross_body(s)?; + Ok(( + s, + CoverCross { + nodes: (a, b, c, d, e), + }, + )) } pub fn list_of_cross_items(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = cross_item(s)?; + let (s, b) = list(symbol(","), cross_item)(s)?; + Ok((s, ListOfCrossItems { nodes: (a, b) })) } pub fn cross_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(cover_point_identifier, |x| { + CrossItem::CoverPointIdentifier(x) + }), + map(variable_identifier, |x| CrossItem::VariableIdentifier(x)), + ))(s) } pub fn cross_body(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + cross_body_non_empty, + map(symbol(";"), |x| CrossBody::Empty(x)), + ))(s) +} + +pub fn cross_body_non_empty(s: Span) -> IResult { + let (s, a) = brace(many0(pair(cross_body_item, symbol(";"))))(s)?; + Ok((s, CrossBody::NonEmpty(CrossBodyNonEmpty { nodes: (a,) }))) } pub fn cross_body_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(function_declaration, |x| { + CrossBodyItem::FunctionDeclaration(x) + }), + map(pair(bins_selection_or_option, symbol(";")), |x| { + CrossBodyItem::BinsSelectionOrOption(x) + }), + ))(s) } pub fn bins_selection_or_option(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + bins_selection_or_option_coverage, + bins_selection_or_option_bins, + ))(s) +} + +pub fn bins_selection_or_option_coverage(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = coverage_option(s)?; + Ok(( + s, + BinsSelectionOrOption::Coverage(BinsSelectionOrOptionCoverage { nodes: (a, b) }), + )) +} + +pub fn bins_selection_or_option_bins(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = bins_selection(s)?; + Ok(( + s, + BinsSelectionOrOption::Bins(BinsSelectionOrOptionBins { nodes: (a, b) }), + )) } pub fn bins_selection(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = bins_keyword(s)?; + let (s, b) = bin_identifier(s)?; + let (s, c) = symbol("=")(s)?; + let (s, d) = select_expression(s)?; + let (s, e) = opt(pair(symbol("iff"), paren(expression)))(s)?; + Ok(( + s, + BinsSelection { + nodes: (a, b, c, d, e), + }, + )) } pub fn select_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(select_condition, |x| SelectExpression::SelectCondition(x)), + select_expression_not, + select_expression_and, + select_expression_or, + select_expression_paren, + select_expression_with, + map(cross_identifier, |x| SelectExpression::CrossIdentifier(x)), + select_expression_cross_set, + ))(s) +} + +pub fn select_expression_not(s: Span) -> IResult { + let (s, a) = symbol("!")(s)?; + let (s, b) = select_condition(s)?; + Ok(( + s, + SelectExpression::Not(SelectExpressionNot { nodes: (a, b) }), + )) +} + +pub fn select_expression_and(s: Span) -> IResult { + let (s, a) = select_expression(s)?; + let (s, b) = symbol("&&")(s)?; + let (s, c) = select_expression(s)?; + Ok(( + s, + SelectExpression::And(Box::new(SelectExpressionAnd { nodes: (a, b, c) })), + )) +} + +pub fn select_expression_or(s: Span) -> IResult { + let (s, a) = select_expression(s)?; + let (s, b) = symbol("||")(s)?; + let (s, c) = select_expression(s)?; + Ok(( + s, + SelectExpression::Or(Box::new(SelectExpressionOr { nodes: (a, b, c) })), + )) +} + +pub fn select_expression_paren(s: Span) -> IResult { + let (s, a) = paren(select_expression)(s)?; + Ok(( + s, + SelectExpression::Paren(Box::new(SelectExpressionParen { nodes: (a,) })), + )) +} + +pub fn select_expression_with(s: Span) -> IResult { + let (s, a) = select_expression(s)?; + let (s, b) = symbol("with")(s)?; + let (s, c) = paren(with_covergroup_expression)(s)?; + let (s, d) = opt(pair(symbol("matches"), integer_covergroup_expression))(s)?; + Ok(( + s, + SelectExpression::With(Box::new(SelectExpressionWith { + nodes: (a, b, c, d), + })), + )) +} + +pub fn select_expression_cross_set(s: Span) -> IResult { + let (s, a) = cross_set_expression(s)?; + let (s, b) = opt(pair(symbol("matches"), integer_covergroup_expression))(s)?; + Ok(( + s, + SelectExpression::CrossSet(SelectExpressionCrossSet { nodes: (a, b) }), + )) } pub fn select_condition(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("binsof")(s)?; + let (s, b) = paren(bins_expression)(s)?; + let (s, c) = opt(pair(symbol("intersect"), brace(covergroup_range_list)))(s)?; + Ok((s, SelectCondition { nodes: (a, b, c) })) } pub fn bins_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(variable_identifier, |x| { + BinsExpression::VariableIdentifier(x) + }), + bins_expression_cover_point, + ))(s) +} + +pub fn bins_expression_cover_point(s: Span) -> IResult { + let (s, a) = cover_point_identifier(s)?; + let (s, b) = opt(pair(symbol("."), bin_identifier))(s)?; + Ok(( + s, + BinsExpression::CoverPoint(BinsExpressionCoverPoint { nodes: (a, b) }), + )) } pub fn covergroup_range_list(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = list(symbol(","), covergroup_value_range)(s)?; + Ok((s, CovergroupRangeList { nodes: (a,) })) } pub fn covergroup_value_range(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(covergroup_expression, |x| { + CovergroupValueRange::CovergroupExpression(x) + }), + covergroup_value_range_binary, + ))(s) +} + +pub fn covergroup_value_range_binary(s: Span) -> IResult { + let (s, a) = bracket(triple( + covergroup_expression, + symbol(":"), + covergroup_expression, + ))(s)?; + Ok(( + s, + CovergroupValueRange::Binary(CovergroupValueRangeBinary { nodes: (a,) }), + )) } pub fn with_covergroup_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = covergroup_expression(s)?; + Ok((s, WithCovergroupExpression { nodes: (a,) })) } pub fn set_covergroup_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = covergroup_expression(s)?; + Ok((s, SetCovergroupExpression { nodes: (a,) })) } pub fn integer_covergroup_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = covergroup_expression(s)?; + Ok((s, IntegerCovergroupExpression { nodes: (a,) })) } pub fn cross_set_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = covergroup_expression(s)?; + Ok((s, CrossSetExpression { nodes: (a,) })) } pub fn covergroup_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = expression(s)?; + Ok((s, CovergroupExpression { nodes: (a,) })) } diff --git a/src/parser/declarations/let_declarations.rs b/src/parser/declarations/let_declarations.rs index 0a6e206..31802c7 100644 --- a/src/parser/declarations/let_declarations.rs +++ b/src/parser/declarations/let_declarations.rs @@ -1,15 +1,23 @@ use crate::ast::*; use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; // ----------------------------------------------------------------------------- #[derive(Debug, Node)] pub struct LetDeclaration<'a> { - pub nodes: (LetIdentifier<'a>, Option>, Expression<'a>), + pub nodes: ( + Symbol<'a>, + LetIdentifier<'a>, + Option>>>, + Symbol<'a>, + Expression<'a>, + Symbol<'a>, + ), } #[derive(Debug, Node)] @@ -19,7 +27,7 @@ pub struct LetIdentifier<'a> { #[derive(Debug, Node)] pub struct LetPortList<'a> { - pub nodes: (Vec>,), + pub nodes: (List, LetPortItem<'a>>,), } #[derive(Debug, Node)] @@ -27,9 +35,9 @@ pub struct LetPortItem<'a> { pub nodes: ( Vec>, LetFormalType<'a>, - Identifier<'a>, + FormalPortIdentifier<'a>, Vec>, - Option>, + Option<(Symbol<'a>, Expression<'a>)>, ), } @@ -44,7 +52,7 @@ pub struct LetExpression<'a> { pub nodes: ( Option>, LetIdentifier<'a>, - Option>, + Option>>>, ), } @@ -57,14 +65,28 @@ pub enum LetListOfArguments<'a> { #[derive(Debug, Node)] pub struct LetListOfArgumentsOrdered<'a> { pub nodes: ( - Vec>, - Vec<(Identifier<'a>, LetActualArg<'a>)>, + List, Option>>, + Vec<( + Symbol<'a>, + Symbol<'a>, + Identifier<'a>, + Paren<'a, Option>>, + )>, ), } #[derive(Debug, Node)] pub struct LetListOfArgumentsNamed<'a> { - pub nodes: (Vec<(Identifier<'a>, LetActualArg<'a>)>,), + pub nodes: ( + List< + Symbol<'a>, + ( + Symbol<'a>, + Identifier<'a>, + Paren<'a, Option>>, + ), + >, + ), } #[derive(Debug, Node)] @@ -75,33 +97,90 @@ pub struct LetActualArg<'a> { // ----------------------------------------------------------------------------- pub fn let_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("let")(s)?; + let (s, b) = let_identifier(s)?; + let (s, c) = opt(paren(opt(let_port_list)))(s)?; + let (s, d) = symbol("=")(s)?; + let (s, e) = expression(s)?; + let (s, f) = symbol(";")(s)?; + Ok(( + s, + LetDeclaration { + nodes: (a, b, c, d, e, f), + }, + )) } pub fn let_identifier(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = identifier(s)?; + Ok((s, LetIdentifier { nodes: (a,) })) } pub fn let_port_list(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = list(symbol(","), let_port_item)(s)?; + Ok((s, LetPortList { nodes: (a,) })) } pub fn let_port_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = let_formal_type(s)?; + let (s, c) = formal_port_identifier(s)?; + let (s, d) = many0(variable_dimension)(s)?; + let (s, e) = opt(pair(symbol("="), expression))(s)?; + Ok(( + s, + LetPortItem { + nodes: (a, b, c, d, e), + }, + )) } pub fn let_formal_type(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(data_type_or_implicit, |x| { + LetFormalType::DataTypeOrImplicit(x) + }), + map(symbol("untyped"), |x| LetFormalType::Untyped(x)), + ))(s) } pub fn let_expression(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = opt(package_scope)(s)?; + let (s, b) = let_identifier(s)?; + let (s, c) = opt(paren(opt(let_list_of_arguments)))(s)?; + Ok((s, LetExpression { nodes: (a, b, c) })) } pub fn let_list_of_arguments(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt((let_list_of_arguments_ordered, let_list_of_arguments_named))(s) +} + +pub fn let_list_of_arguments_ordered(s: Span) -> IResult { + let (s, a) = list(symbol(","), opt(let_actual_arg))(s)?; + let (s, b) = many0(tuple(( + symbol(","), + symbol("."), + identifier, + paren(opt(let_actual_arg)), + )))(s)?; + Ok(( + s, + LetListOfArguments::Ordered(LetListOfArgumentsOrdered { nodes: (a, b) }), + )) +} + +pub fn let_list_of_arguments_named(s: Span) -> IResult { + let (s, a) = list( + symbol(","), + triple(symbol("."), identifier, paren(opt(let_actual_arg))), + )(s)?; + Ok(( + s, + LetListOfArguments::Named(LetListOfArgumentsNamed { nodes: (a,) }), + )) } pub fn let_actual_arg(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = expression(s)?; + Ok((s, LetActualArg { nodes: (a,) })) } diff --git a/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs b/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs index dfaab3b..3a95d70 100644 --- a/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs +++ b/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs @@ -1,19 +1,62 @@ use crate::ast::*; use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; // ----------------------------------------------------------------------------- #[derive(Debug, Node)] pub struct UdpInstantiation<'a> { - pub nodes: (Identifier<'a>,), + pub nodes: ( + UdpIdentifier<'a>, + Option>, + Option>, + List, UdpInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct UdpInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + OutputTerminal<'a>, + Symbol<'a>, + InputTerminal<'a>, + Vec<(Symbol<'a>, InputTerminal<'a>)>, + ), + >, + ), } // ----------------------------------------------------------------------------- pub fn udp_instantiation(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = udp_identifier(s)?; + let (s, b) = opt(drive_strength)(s)?; + let (s, c) = opt(delay2)(s)?; + let (s, d) = list(symbol(","), udp_instance)(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + UdpInstantiation { + nodes: (a, b, c, d, e), + }, + )) +} + +pub fn udp_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + output_terminal, + symbol(","), + input_terminal, + many0(pair(symbol(","), input_terminal)), + )))(s)?; + Ok((s, UdpInstance { nodes: (a, b) })) }