sv_parser_parser/declarations/
port_declarations.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn inout_declaration(s: Span) -> IResult<Span, InoutDeclaration> {
8    let (s, a) = keyword("inout")(s)?;
9    let (s, b) = net_port_type(s)?;
10    let (s, c) = list_of_port_identifiers(s)?;
11    Ok((s, InoutDeclaration { nodes: (a, b, c) }))
12}
13
14#[tracable_parser]
15#[packrat_parser]
16pub(crate) fn input_declaration(s: Span) -> IResult<Span, InputDeclaration> {
17    alt((input_declaration_net, input_declaration_variable))(s)
18}
19
20#[tracable_parser]
21#[packrat_parser]
22pub(crate) fn input_declaration_net(s: Span) -> IResult<Span, InputDeclaration> {
23    let (s, a) = keyword("input")(s)?;
24    let (s, b) = net_port_type(s)?;
25    let (s, c) = list_of_port_identifiers(s)?;
26    Ok((
27        s,
28        InputDeclaration::Net(Box::new(InputDeclarationNet { nodes: (a, b, c) })),
29    ))
30}
31
32#[tracable_parser]
33#[packrat_parser]
34pub(crate) fn input_declaration_variable(s: Span) -> IResult<Span, InputDeclaration> {
35    let (s, a) = keyword("input")(s)?;
36    let (s, b) = variable_port_type(s)?;
37    let (s, c) = list_of_variable_identifiers(s)?;
38    Ok((
39        s,
40        InputDeclaration::Variable(Box::new(InputDeclarationVariable { nodes: (a, b, c) })),
41    ))
42}
43
44#[tracable_parser]
45#[packrat_parser]
46pub(crate) fn output_declaration(s: Span) -> IResult<Span, OutputDeclaration> {
47    alt((output_declaration_net, output_declaration_variable))(s)
48}
49
50#[tracable_parser]
51#[packrat_parser]
52pub(crate) fn output_declaration_net(s: Span) -> IResult<Span, OutputDeclaration> {
53    let (s, a) = keyword("output")(s)?;
54    let (s, b) = net_port_type(s)?;
55    let (s, c) = list_of_port_identifiers(s)?;
56    Ok((
57        s,
58        OutputDeclaration::Net(Box::new(OutputDeclarationNet { nodes: (a, b, c) })),
59    ))
60}
61
62#[tracable_parser]
63#[packrat_parser]
64pub(crate) fn output_declaration_variable(s: Span) -> IResult<Span, OutputDeclaration> {
65    let (s, a) = keyword("output")(s)?;
66    let (s, b) = variable_port_type(s)?;
67    let (s, c) = list_of_variable_port_identifiers(s)?;
68    Ok((
69        s,
70        OutputDeclaration::Variable(Box::new(OutputDeclarationVariable { nodes: (a, b, c) })),
71    ))
72}
73
74#[tracable_parser]
75#[packrat_parser]
76pub(crate) fn interface_port_declaration(s: Span) -> IResult<Span, InterfacePortDeclaration> {
77    let (s, a) = interface_identifier(s)?;
78    let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?;
79    let (s, c) = list_of_interface_identifiers(s)?;
80    Ok((s, InterfacePortDeclaration { nodes: (a, b, c) }))
81}
82
83#[tracable_parser]
84#[packrat_parser]
85pub(crate) fn ref_declaration(s: Span) -> IResult<Span, RefDeclaration> {
86    let (s, a) = keyword("ref")(s)?;
87    let (s, b) = variable_port_type(s)?;
88    let (s, c) = list_of_variable_identifiers(s)?;
89    Ok((s, RefDeclaration { nodes: (a, b, c) }))
90}