sv_parser_parser/behavioral_statements/
statements.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn statement_or_null(s: Span) -> IResult<Span, StatementOrNull> {
8    alt((
9        map(statement, |x| StatementOrNull::Statement(Box::new(x))),
10        statement_or_null_attribute,
11    ))(s)
12}
13
14#[tracable_parser]
15#[packrat_parser]
16pub(crate) fn statement_or_null_attribute(s: Span) -> IResult<Span, StatementOrNull> {
17    let (s, (a, b)) = many_till(attribute_instance, symbol(";"))(s)?;
18    Ok((
19        s,
20        StatementOrNull::Attribute(Box::new(StatementOrNullAttribute { nodes: (a, b) })),
21    ))
22}
23
24#[recursive_parser]
25#[tracable_parser]
26#[packrat_parser]
27pub(crate) fn statement(s: Span) -> IResult<Span, Statement> {
28    let (s, a) = opt(pair(
29        block_identifier,
30        terminated(symbol(":"), peek(not(symbol(":")))),
31    ))(s)?;
32    let (s, b) = many0(attribute_instance)(s)?;
33    let (s, c) = statement_item(s)?;
34    Ok((s, Statement { nodes: (a, b, c) }))
35}
36
37#[tracable_parser]
38#[packrat_parser]
39pub(crate) fn statement_item(s: Span) -> IResult<Span, StatementItem> {
40    alt((
41        map(pair(blocking_assignment, symbol(";")), |x| {
42            StatementItem::BlockingAssignment(Box::new(x))
43        }),
44        map(pair(nonblocking_assignment, symbol(";")), |x| {
45            StatementItem::NonblockingAssignment(Box::new(x))
46        }),
47        map(pair(procedural_continuous_assignment, symbol(";")), |x| {
48            StatementItem::ProceduralContinuousAssignment(Box::new(x))
49        }),
50        map(case_statement, |x| {
51            StatementItem::CaseStatement(Box::new(x))
52        }),
53        map(conditional_statement, |x| {
54            StatementItem::ConditionalStatement(Box::new(x))
55        }),
56        map(pair(inc_or_dec_expression, symbol(";")), |x| {
57            StatementItem::IncOrDecExpression(Box::new(x))
58        }),
59        map(subroutine_call_statement, |x| {
60            StatementItem::SubroutineCallStatement(Box::new(x))
61        }),
62        map(disable_statement, |x| {
63            StatementItem::DisableStatement(Box::new(x))
64        }),
65        map(event_trigger, |x| StatementItem::EventTrigger(Box::new(x))),
66        map(loop_statement, |x| {
67            StatementItem::LoopStatement(Box::new(x))
68        }),
69        map(jump_statement, |x| {
70            StatementItem::JumpStatement(Box::new(x))
71        }),
72        map(par_block, |x| StatementItem::ParBlock(Box::new(x))),
73        map(procedural_timing_control_statement, |x| {
74            StatementItem::ProceduralTimingControlStatement(Box::new(x))
75        }),
76        map(seq_block, |x| StatementItem::SeqBlock(Box::new(x))),
77        map(wait_statement, |x| {
78            StatementItem::WaitStatement(Box::new(x))
79        }),
80        map(procedural_assertion_statement, |x| {
81            StatementItem::ProceduralAssertionStatement(Box::new(x))
82        }),
83        map(pair(clocking_drive, symbol(";")), |x| {
84            StatementItem::ClockingDrive(Box::new(x))
85        }),
86        map(randsequence_statement, |x| {
87            StatementItem::RandsequenceStatement(Box::new(x))
88        }),
89        map(randcase_statement, |x| {
90            StatementItem::RandcaseStatement(Box::new(x))
91        }),
92        map(expect_property_statement, |x| {
93            StatementItem::ExpectPropertyStatement(Box::new(x))
94        }),
95    ))(s)
96}
97
98#[tracable_parser]
99#[packrat_parser]
100pub(crate) fn function_statement(s: Span) -> IResult<Span, FunctionStatement> {
101    let (s, a) = statement(s)?;
102    Ok((s, FunctionStatement { nodes: (a,) }))
103}
104
105#[tracable_parser]
106#[packrat_parser]
107pub(crate) fn function_statement_or_null(s: Span) -> IResult<Span, FunctionStatementOrNull> {
108    alt((
109        map(function_statement, |x| {
110            FunctionStatementOrNull::Statement(Box::new(x))
111        }),
112        function_statement_or_null_attribute,
113    ))(s)
114}
115
116#[tracable_parser]
117#[packrat_parser]
118pub(crate) fn function_statement_or_null_attribute(
119    s: Span,
120) -> IResult<Span, FunctionStatementOrNull> {
121    let (s, (a, b)) = many_till(attribute_instance, symbol(";"))(s)?;
122    Ok((
123        s,
124        FunctionStatementOrNull::Attribute(Box::new(FunctionStatementOrNullAttribute {
125            nodes: (a, b),
126        })),
127    ))
128}
129
130#[tracable_parser]
131#[packrat_parser]
132pub(crate) fn variable_identifier_list(s: Span) -> IResult<Span, VariableIdentifierList> {
133    let (s, a) = list(symbol(","), variable_identifier)(s)?;
134    Ok((s, VariableIdentifierList { nodes: (a,) }))
135}