From 33e37e351a163a58c0b39d869d0100fa201f1f40 Mon Sep 17 00:00:00 2001 From: Yousuf Al-Obaidi Date: Wed, 23 Apr 2025 08:43:13 +0200 Subject: [PATCH] Fix sequence with parameter as function delay --- .../declarations/assertion_declarations.rs | 34 +++++++++++++++--- sv-parser-parser/src/expressions/primaries.rs | 35 +++++++++++++++++++ sv-parser-parser/src/tests.rs | 5 +++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/sv-parser-parser/src/declarations/assertion_declarations.rs b/sv-parser-parser/src/declarations/assertion_declarations.rs index d7594fcc..df416038 100644 --- a/sv-parser-parser/src/declarations/assertion_declarations.rs +++ b/sv-parser-parser/src/declarations/assertion_declarations.rs @@ -724,8 +724,10 @@ pub(crate) fn sequence_expr(s: Span) -> IResult { #[tracable_parser] #[packrat_parser] pub(crate) fn sequence_expr_cycle_delay_expr(s: Span) -> IResult { - let (s, a) = cycle_delay_range(s)?; - let (s, b) = sequence_expr(s)?; + let (s, (a, b)) = alt(( + pair(cycle_delay_range, sequence_expr), + pair(cycle_delay_range_2, sequence_expr), + ))(s)?; let (s, c) = many0(pair(cycle_delay_range, sequence_expr))(s)?; Ok(( s, @@ -738,8 +740,10 @@ pub(crate) fn sequence_expr_cycle_delay_expr(s: Span) -> IResult IResult { let (s, a) = sequence_expr(s)?; - let (s, b) = cycle_delay_range(s)?; - let (s, c) = sequence_expr(s)?; + let (s, (b, c)) = alt(( + pair(cycle_delay_range, sequence_expr), + pair(cycle_delay_range_2, sequence_expr), + ))(s)?; let (s, d) = many0(pair(cycle_delay_range, sequence_expr))(s)?; Ok(( s, @@ -853,6 +857,17 @@ pub(crate) fn cycle_delay_range(s: Span) -> IResult { ))(s) } +#[tracable_parser] +#[packrat_parser] +pub(crate) fn cycle_delay_range_2(s: Span) -> IResult { + alt(( + cycle_delay_range_primary_no_function, + cycle_delay_range_expression, + cycle_delay_range_asterisk, + cycle_delay_range_plus, + ))(s) +} + #[tracable_parser] #[packrat_parser] pub(crate) fn cycle_delay_range_primary(s: Span) -> IResult { @@ -864,6 +879,17 @@ pub(crate) fn cycle_delay_range_primary(s: Span) -> IResult IResult { + let (s, a) = symbol("##")(s)?; + let (s, b) = constant_primary_no_function(s)?; + Ok(( + s, + CycleDelayRange::Primary(Box::new(CycleDelayRangePrimary { nodes: (a, b) })), + )) +} + #[tracable_parser] #[packrat_parser] pub(crate) fn cycle_delay_range_expression(s: Span) -> IResult { diff --git a/sv-parser-parser/src/expressions/primaries.rs b/sv-parser-parser/src/expressions/primaries.rs index 1b75e547..5f25dbab 100644 --- a/sv-parser-parser/src/expressions/primaries.rs +++ b/sv-parser-parser/src/expressions/primaries.rs @@ -41,6 +41,41 @@ pub(crate) fn constant_primary(s: Span) -> IResult { ))(s) } +#[tracable_parser] +#[packrat_parser] +pub(crate) fn constant_primary_no_function(s: Span) -> IResult { + alt(( + // BNF-WA + map(keyword("$"), |x| ConstantPrimary::Dollar(Box::new(x))), + map(keyword("null"), |x| ConstantPrimary::Null(Box::new(x))), + map(constant_assignment_pattern_expression, |x| { + ConstantPrimary::ConstantAssignmentPatternExpression(Box::new(x)) + }), + map(constant_cast, |x| { + ConstantPrimary::ConstantCast(Box::new(x)) + }), + map(primary_literal, |x| { + ConstantPrimary::PrimaryLiteral(Box::new(x)) + }), + constant_primary_mintypmax_expression, + constant_primary_ps_parameter, + constant_primary_specparam, + map(genvar_identifier, |x| { + ConstantPrimary::GenvarIdentifier(Box::new(x)) + }), + constant_primary_formal_port, + constant_primary_enum, + constant_primary_concatenation, + constant_primary_multiple_concatenation, + map(constant_let_expression, |x| { + ConstantPrimary::ConstantLetExpression(Box::new(x)) + }), + map(type_reference, |x| { + ConstantPrimary::TypeReference(Box::new(x)) + }), + ))(s) +} + #[tracable_parser] #[packrat_parser] pub(crate) fn constant_primary_without_cast(s: Span) -> IResult { diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index 2a3d8b85..bb0105fb 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -15905,6 +15905,11 @@ mod spec { ); } + #[test] + fn test_sequence_constant_primary_param() { + test!(sequence_expr, "##MY_PARAM (in2 == in3)", Ok((_, _))); + } + #[test] fn clause36() { test!(