sv_parser_parser/udp_declaration_and_instantiation/
udp_ports.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn udp_port_list(s: Span) -> IResult<Span, UdpPortList> {
8    let (s, a) = output_port_identifier(s)?;
9    let (s, b) = symbol(",")(s)?;
10    let (s, c) = list(symbol(","), input_port_identifier)(s)?;
11    Ok((s, UdpPortList { nodes: (a, b, c) }))
12}
13
14#[tracable_parser]
15#[packrat_parser]
16pub(crate) fn udp_declaration_port_list(s: Span) -> IResult<Span, UdpDeclarationPortList> {
17    let (s, a) = udp_output_declaration(s)?;
18    let (s, b) = symbol(",")(s)?;
19    let (s, c) = list(symbol(","), udp_input_declaration)(s)?;
20    Ok((s, UdpDeclarationPortList { nodes: (a, b, c) }))
21}
22
23#[tracable_parser]
24#[packrat_parser]
25pub(crate) fn udp_port_declaration(s: Span) -> IResult<Span, UdpPortDeclaration> {
26    alt((
27        map(pair(udp_output_declaration, symbol(";")), |x| {
28            UdpPortDeclaration::UdpOutputDeclaration(Box::new(x))
29        }),
30        map(pair(udp_input_declaration, symbol(";")), |x| {
31            UdpPortDeclaration::UdpInputDeclaration(Box::new(x))
32        }),
33        map(pair(udp_reg_declaration, symbol(";")), |x| {
34            UdpPortDeclaration::UdpRegDeclaration(Box::new(x))
35        }),
36    ))(s)
37}
38
39#[tracable_parser]
40#[packrat_parser]
41pub(crate) fn udp_output_declaration(s: Span) -> IResult<Span, UdpOutputDeclaration> {
42    alt((udp_output_declaration_nonreg, udp_output_declaration_reg))(s)
43}
44
45#[tracable_parser]
46#[packrat_parser]
47pub(crate) fn udp_output_declaration_nonreg(s: Span) -> IResult<Span, UdpOutputDeclaration> {
48    let (s, (a, b)) = many_till(attribute_instance, keyword("output"))(s)?;
49    let (s, c) = port_identifier(s)?;
50    Ok((
51        s,
52        UdpOutputDeclaration::Nonreg(Box::new(UdpOutputDeclarationNonreg { nodes: (a, b, c) })),
53    ))
54}
55
56#[tracable_parser]
57#[packrat_parser]
58pub(crate) fn udp_output_declaration_reg(s: Span) -> IResult<Span, UdpOutputDeclaration> {
59    let (s, (a, b)) = many_till(attribute_instance, keyword("output"))(s)?;
60    let (s, c) = keyword("reg")(s)?;
61    let (s, d) = port_identifier(s)?;
62    let (s, e) = opt(pair(symbol("="), constant_expression))(s)?;
63    Ok((
64        s,
65        UdpOutputDeclaration::Reg(Box::new(UdpOutputDeclarationReg {
66            nodes: (a, b, c, d, e),
67        })),
68    ))
69}
70
71#[tracable_parser]
72#[packrat_parser]
73pub(crate) fn udp_input_declaration(s: Span) -> IResult<Span, UdpInputDeclaration> {
74    let (s, (a, b)) = many_till(attribute_instance, keyword("input"))(s)?;
75    let (s, c) = list_of_udp_port_identifiers(s)?;
76    Ok((s, UdpInputDeclaration { nodes: (a, b, c) }))
77}
78
79#[tracable_parser]
80#[packrat_parser]
81pub(crate) fn udp_reg_declaration(s: Span) -> IResult<Span, UdpRegDeclaration> {
82    let (s, (a, b)) = many_till(attribute_instance, keyword("reg"))(s)?;
83    let (s, c) = variable_identifier(s)?;
84    Ok((s, UdpRegDeclaration { nodes: (a, b, c) }))
85}