sv_parser_parser/declarations/
delays.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn delay3(s: Span) -> IResult<Span, Delay3> {
8    alt((delay3_single, delay3_mintypmax))(s)
9}
10
11#[tracable_parser]
12#[packrat_parser]
13pub(crate) fn delay3_single(s: Span) -> IResult<Span, Delay3> {
14    let (s, a) = symbol("#")(s)?;
15    let (s, b) = delay_value(s)?;
16    Ok((s, Delay3::Single(Box::new(Delay3Single { nodes: (a, b) }))))
17}
18
19#[tracable_parser]
20#[packrat_parser]
21pub(crate) fn delay3_mintypmax(s: Span) -> IResult<Span, Delay3> {
22    let (s, a) = symbol("#")(s)?;
23    let (s, b) = paren(pair(
24        mintypmax_expression,
25        opt(triple(
26            symbol(","),
27            mintypmax_expression,
28            opt(pair(symbol(","), mintypmax_expression)),
29        )),
30    ))(s)?;
31    Ok((
32        s,
33        Delay3::Mintypmax(Box::new(Delay3Mintypmax { nodes: (a, b) })),
34    ))
35}
36
37#[tracable_parser]
38#[packrat_parser]
39pub(crate) fn delay2(s: Span) -> IResult<Span, Delay2> {
40    alt((delay2_single, delay2_mintypmax))(s)
41}
42
43#[tracable_parser]
44#[packrat_parser]
45pub(crate) fn delay2_single(s: Span) -> IResult<Span, Delay2> {
46    let (s, a) = symbol("#")(s)?;
47    let (s, b) = delay_value(s)?;
48    Ok((s, Delay2::Single(Box::new(Delay2Single { nodes: (a, b) }))))
49}
50
51#[tracable_parser]
52#[packrat_parser]
53pub(crate) fn delay2_mintypmax(s: Span) -> IResult<Span, Delay2> {
54    let (s, a) = symbol("#")(s)?;
55    let (s, b) = paren(pair(
56        mintypmax_expression,
57        opt(pair(symbol(","), mintypmax_expression)),
58    ))(s)?;
59    Ok((
60        s,
61        Delay2::Mintypmax(Box::new(Delay2Mintypmax { nodes: (a, b) })),
62    ))
63}
64
65#[tracable_parser]
66#[packrat_parser]
67pub(crate) fn delay_value(s: Span) -> IResult<Span, DelayValue> {
68    alt((
69        map(keyword("1step"), |x| DelayValue::Step1(Box::new(x))),
70        map(time_literal, |x| DelayValue::TimeLiteral(Box::new(x))),
71        map(real_number, |x| DelayValue::RealNumber(Box::new(x))),
72        map(unsigned_number, |x| DelayValue::UnsignedNumber(Box::new(x))),
73        // BNF-WA
74        map(hierarchical_identifier, |x| {
75            DelayValue::HierarchicalIdentifier(Box::new(x))
76        }),
77        map(ps_identifier, |x| DelayValue::PsIdentifier(Box::new(x))),
78    ))(s)
79}