1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use crate::*;

// -----------------------------------------------------------------------------

#[tracable_parser]
#[packrat_parser]
pub(crate) fn statement_or_null(s: Span) -> IResult<Span, StatementOrNull> {
    alt((
        map(statement, |x| StatementOrNull::Statement(Box::new(x))),
        statement_or_null_attribute,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn statement_or_null_attribute(s: Span) -> IResult<Span, StatementOrNull> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = symbol(";")(s)?;
    Ok((
        s,
        StatementOrNull::Attribute(Box::new(StatementOrNullAttribute { nodes: (a, b) })),
    ))
}

#[recursive_parser]
#[tracable_parser]
#[packrat_parser]
pub(crate) fn statement(s: Span) -> IResult<Span, Statement> {
    let (s, a) = opt(pair(
        block_identifier,
        terminated(symbol(":"), peek(not(symbol(":")))),
    ))(s)?;
    let (s, b) = many0(attribute_instance)(s)?;
    let (s, c) = statement_item(s)?;
    Ok((s, Statement { nodes: (a, b, c) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn statement_item(s: Span) -> IResult<Span, StatementItem> {
    alt((
        map(pair(blocking_assignment, symbol(";")), |x| {
            StatementItem::BlockingAssignment(Box::new(x))
        }),
        map(pair(nonblocking_assignment, symbol(";")), |x| {
            StatementItem::NonblockingAssignment(Box::new(x))
        }),
        map(pair(procedural_continuous_assignment, symbol(";")), |x| {
            StatementItem::ProceduralContinuousAssignment(Box::new(x))
        }),
        map(case_statement, |x| {
            StatementItem::CaseStatement(Box::new(x))
        }),
        map(conditional_statement, |x| {
            StatementItem::ConditionalStatement(Box::new(x))
        }),
        map(pair(inc_or_dec_expression, symbol(";")), |x| {
            StatementItem::IncOrDecExpression(Box::new(x))
        }),
        map(subroutine_call_statement, |x| {
            StatementItem::SubroutineCallStatement(Box::new(x))
        }),
        map(disable_statement, |x| {
            StatementItem::DisableStatement(Box::new(x))
        }),
        map(event_trigger, |x| StatementItem::EventTrigger(Box::new(x))),
        map(loop_statement, |x| {
            StatementItem::LoopStatement(Box::new(x))
        }),
        map(jump_statement, |x| {
            StatementItem::JumpStatement(Box::new(x))
        }),
        map(par_block, |x| StatementItem::ParBlock(Box::new(x))),
        map(procedural_timing_control_statement, |x| {
            StatementItem::ProceduralTimingControlStatement(Box::new(x))
        }),
        map(seq_block, |x| StatementItem::SeqBlock(Box::new(x))),
        map(wait_statement, |x| {
            StatementItem::WaitStatement(Box::new(x))
        }),
        map(procedural_assertion_statement, |x| {
            StatementItem::ProceduralAssertionStatement(Box::new(x))
        }),
        map(pair(clocking_drive, symbol(";")), |x| {
            StatementItem::ClockingDrive(Box::new(x))
        }),
        map(randsequence_statement, |x| {
            StatementItem::RandsequenceStatement(Box::new(x))
        }),
        map(randcase_statement, |x| {
            StatementItem::RandcaseStatement(Box::new(x))
        }),
        map(expect_property_statement, |x| {
            StatementItem::ExpectPropertyStatement(Box::new(x))
        }),
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn function_statement(s: Span) -> IResult<Span, FunctionStatement> {
    let (s, a) = statement(s)?;
    Ok((s, FunctionStatement { nodes: (a,) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn function_statement_or_null(s: Span) -> IResult<Span, FunctionStatementOrNull> {
    alt((
        map(function_statement, |x| {
            FunctionStatementOrNull::Statement(Box::new(x))
        }),
        function_statement_or_null_attribute,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn function_statement_or_null_attribute(
    s: Span,
) -> IResult<Span, FunctionStatementOrNull> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = symbol(";")(s)?;
    Ok((
        s,
        FunctionStatementOrNull::Attribute(Box::new(FunctionStatementOrNullAttribute {
            nodes: (a, b),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn variable_identifier_list(s: Span) -> IResult<Span, VariableIdentifierList> {
    let (s, a) = list(symbol(","), variable_identifier)(s)?;
    Ok((s, VariableIdentifierList { nodes: (a,) }))
}