Skip to content

Commit 8898c1b

Browse files
authored
Merge pull request #114 from yousifBilal/constant-primary-in-cycle-delay-sequence
Fix sequence with parameter as cycle delay
2 parents e3ac78c + 33e37e3 commit 8898c1b

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

sv-parser-parser/src/declarations/assertion_declarations.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,10 @@ pub(crate) fn sequence_expr(s: Span) -> IResult<Span, SequenceExpr> {
724724
#[tracable_parser]
725725
#[packrat_parser]
726726
pub(crate) fn sequence_expr_cycle_delay_expr(s: Span) -> IResult<Span, SequenceExpr> {
727-
let (s, a) = cycle_delay_range(s)?;
728-
let (s, b) = sequence_expr(s)?;
727+
let (s, (a, b)) = alt((
728+
pair(cycle_delay_range, sequence_expr),
729+
pair(cycle_delay_range_2, sequence_expr),
730+
))(s)?;
729731
let (s, c) = many0(pair(cycle_delay_range, sequence_expr))(s)?;
730732
Ok((
731733
s,
@@ -738,8 +740,10 @@ pub(crate) fn sequence_expr_cycle_delay_expr(s: Span) -> IResult<Span, SequenceE
738740
#[packrat_parser]
739741
pub(crate) fn sequence_expr_expr_cycle_delay_expr(s: Span) -> IResult<Span, SequenceExpr> {
740742
let (s, a) = sequence_expr(s)?;
741-
let (s, b) = cycle_delay_range(s)?;
742-
let (s, c) = sequence_expr(s)?;
743+
let (s, (b, c)) = alt((
744+
pair(cycle_delay_range, sequence_expr),
745+
pair(cycle_delay_range_2, sequence_expr),
746+
))(s)?;
743747
let (s, d) = many0(pair(cycle_delay_range, sequence_expr))(s)?;
744748
Ok((
745749
s,
@@ -853,6 +857,17 @@ pub(crate) fn cycle_delay_range(s: Span) -> IResult<Span, CycleDelayRange> {
853857
))(s)
854858
}
855859

860+
#[tracable_parser]
861+
#[packrat_parser]
862+
pub(crate) fn cycle_delay_range_2(s: Span) -> IResult<Span, CycleDelayRange> {
863+
alt((
864+
cycle_delay_range_primary_no_function,
865+
cycle_delay_range_expression,
866+
cycle_delay_range_asterisk,
867+
cycle_delay_range_plus,
868+
))(s)
869+
}
870+
856871
#[tracable_parser]
857872
#[packrat_parser]
858873
pub(crate) fn cycle_delay_range_primary(s: Span) -> IResult<Span, CycleDelayRange> {
@@ -864,6 +879,17 @@ pub(crate) fn cycle_delay_range_primary(s: Span) -> IResult<Span, CycleDelayRang
864879
))
865880
}
866881

882+
#[tracable_parser]
883+
#[packrat_parser]
884+
pub(crate) fn cycle_delay_range_primary_no_function(s: Span) -> IResult<Span, CycleDelayRange> {
885+
let (s, a) = symbol("##")(s)?;
886+
let (s, b) = constant_primary_no_function(s)?;
887+
Ok((
888+
s,
889+
CycleDelayRange::Primary(Box::new(CycleDelayRangePrimary { nodes: (a, b) })),
890+
))
891+
}
892+
867893
#[tracable_parser]
868894
#[packrat_parser]
869895
pub(crate) fn cycle_delay_range_expression(s: Span) -> IResult<Span, CycleDelayRange> {

sv-parser-parser/src/expressions/primaries.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@ pub(crate) fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> {
4141
))(s)
4242
}
4343

44+
#[tracable_parser]
45+
#[packrat_parser]
46+
pub(crate) fn constant_primary_no_function(s: Span) -> IResult<Span, ConstantPrimary> {
47+
alt((
48+
// BNF-WA
49+
map(keyword("$"), |x| ConstantPrimary::Dollar(Box::new(x))),
50+
map(keyword("null"), |x| ConstantPrimary::Null(Box::new(x))),
51+
map(constant_assignment_pattern_expression, |x| {
52+
ConstantPrimary::ConstantAssignmentPatternExpression(Box::new(x))
53+
}),
54+
map(constant_cast, |x| {
55+
ConstantPrimary::ConstantCast(Box::new(x))
56+
}),
57+
map(primary_literal, |x| {
58+
ConstantPrimary::PrimaryLiteral(Box::new(x))
59+
}),
60+
constant_primary_mintypmax_expression,
61+
constant_primary_ps_parameter,
62+
constant_primary_specparam,
63+
map(genvar_identifier, |x| {
64+
ConstantPrimary::GenvarIdentifier(Box::new(x))
65+
}),
66+
constant_primary_formal_port,
67+
constant_primary_enum,
68+
constant_primary_concatenation,
69+
constant_primary_multiple_concatenation,
70+
map(constant_let_expression, |x| {
71+
ConstantPrimary::ConstantLetExpression(Box::new(x))
72+
}),
73+
map(type_reference, |x| {
74+
ConstantPrimary::TypeReference(Box::new(x))
75+
}),
76+
))(s)
77+
}
78+
4479
#[tracable_parser]
4580
#[packrat_parser]
4681
pub(crate) fn constant_primary_without_cast(s: Span) -> IResult<Span, ConstantPrimary> {

sv-parser-parser/src/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15895,6 +15895,11 @@ mod spec {
1589515895
);
1589615896
}
1589715897

15898+
#[test]
15899+
fn test_sequence_constant_primary_param() {
15900+
test!(sequence_expr, "##MY_PARAM (in2 == in3)", Ok((_, _)));
15901+
}
15902+
1589815903
#[test]
1589915904
fn clause36() {
1590015905
test!(

0 commit comments

Comments
 (0)