1use crate::*;
2
3#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn parameter_port_list(s: Span) -> IResult<Span, ParameterPortList> {
8 alt((
9 parameter_port_list_assignment,
10 parameter_port_list_declaration,
11 parameter_port_list_empty,
12 ))(s)
13}
14
15#[tracable_parser]
16#[packrat_parser]
17pub(crate) fn parameter_port_list_assignment(s: Span) -> IResult<Span, ParameterPortList> {
18 let (s, a) = symbol("#")(s)?;
19 let (s, b) = paren(pair(
20 list_of_param_assignments,
21 many0(pair(symbol(","), parameter_port_declaration)),
22 ))(s)?;
23 Ok((
24 s,
25 ParameterPortList::Assignment(Box::new(ParameterPortListAssignment { nodes: (a, b) })),
26 ))
27}
28
29#[tracable_parser]
30#[packrat_parser]
31pub(crate) fn parameter_port_list_declaration(s: Span) -> IResult<Span, ParameterPortList> {
32 let (s, a) = symbol("#")(s)?;
33 let (s, b) = paren(list(symbol(","), parameter_port_declaration))(s)?;
34 Ok((
35 s,
36 ParameterPortList::Declaration(Box::new(ParameterPortListDeclaration { nodes: (a, b) })),
37 ))
38}
39
40#[tracable_parser]
41#[packrat_parser]
42pub(crate) fn parameter_port_list_empty(s: Span) -> IResult<Span, ParameterPortList> {
43 let (s, a) = symbol("#")(s)?;
44 let (s, b) = symbol("(")(s)?;
45 let (s, c) = symbol(")")(s)?;
46 Ok((s, ParameterPortList::Empty(Box::new((a, b, c)))))
47}
48
49#[tracable_parser]
50#[packrat_parser]
51pub(crate) fn parameter_port_declaration(s: Span) -> IResult<Span, ParameterPortDeclaration> {
52 alt((
53 map(parameter_declaration, |x| {
54 ParameterPortDeclaration::ParameterDeclaration(Box::new(x))
55 }),
56 map(local_parameter_declaration, |x| {
57 ParameterPortDeclaration::LocalParameterDeclaration(Box::new(x))
58 }),
59 parameter_port_declaration_param_list,
60 parameter_port_declaration_type_list,
61 ))(s)
62}
63
64#[tracable_parser]
65#[packrat_parser]
66pub(crate) fn parameter_port_declaration_param_list(
67 s: Span,
68) -> IResult<Span, ParameterPortDeclaration> {
69 let (s, a) = data_type(s)?;
70 let (s, b) = list_of_param_assignments(s)?;
71 Ok((
72 s,
73 ParameterPortDeclaration::ParamList(Box::new(ParameterPortDeclarationParamList {
74 nodes: (a, b),
75 })),
76 ))
77}
78
79#[tracable_parser]
80#[packrat_parser]
81pub(crate) fn parameter_port_declaration_type_list(
82 s: Span,
83) -> IResult<Span, ParameterPortDeclaration> {
84 let (s, a) = keyword("type")(s)?;
85 let (s, b) = list_of_type_assignments(s)?;
86 Ok((
87 s,
88 ParameterPortDeclaration::TypeList(Box::new(ParameterPortDeclarationTypeList {
89 nodes: (a, b),
90 })),
91 ))
92}
93
94#[tracable_parser]
95#[packrat_parser]
96pub(crate) fn list_of_ports(s: Span) -> IResult<Span, ListOfPorts> {
97 let (s, a) = paren(list(symbol(","), port))(s)?;
98 Ok((s, ListOfPorts { nodes: (a,) }))
99}
100
101#[tracable_parser]
102#[packrat_parser]
103pub(crate) fn list_of_port_declarations(s: Span) -> IResult<Span, ListOfPortDeclarations> {
104 let (s, a) = paren(opt(list(
105 symbol(","),
106 pair(many0(attribute_instance), ansi_port_declaration),
107 )))(s)?;
108 Ok((s, ListOfPortDeclarations { nodes: (a,) }))
109}
110
111#[tracable_parser]
112#[packrat_parser]
113pub(crate) fn port_declaration(s: Span) -> IResult<Span, PortDeclaration> {
114 alt((
115 port_declaration_inout,
116 port_declaration_input,
117 port_declaration_output,
118 port_declaration_ref,
119 port_declaration_interface,
120 ))(s)
121}
122
123#[tracable_parser]
124#[packrat_parser]
125pub(crate) fn port_declaration_inout(s: Span) -> IResult<Span, PortDeclaration> {
126 let (s, a) = many0(attribute_instance)(s)?;
127 let (s, b) = inout_declaration(s)?;
128 Ok((
129 s,
130 PortDeclaration::Inout(Box::new(PortDeclarationInout { nodes: (a, b) })),
131 ))
132}
133
134#[tracable_parser]
135#[packrat_parser]
136pub(crate) fn port_declaration_input(s: Span) -> IResult<Span, PortDeclaration> {
137 let (s, a) = many0(attribute_instance)(s)?;
138 let (s, b) = input_declaration(s)?;
139 Ok((
140 s,
141 PortDeclaration::Input(Box::new(PortDeclarationInput { nodes: (a, b) })),
142 ))
143}
144
145#[tracable_parser]
146#[packrat_parser]
147pub(crate) fn port_declaration_output(s: Span) -> IResult<Span, PortDeclaration> {
148 let (s, a) = many0(attribute_instance)(s)?;
149 let (s, b) = output_declaration(s)?;
150 Ok((
151 s,
152 PortDeclaration::Output(Box::new(PortDeclarationOutput { nodes: (a, b) })),
153 ))
154}
155
156#[tracable_parser]
157#[packrat_parser]
158pub(crate) fn port_declaration_ref(s: Span) -> IResult<Span, PortDeclaration> {
159 let (s, a) = many0(attribute_instance)(s)?;
160 let (s, b) = ref_declaration(s)?;
161 Ok((
162 s,
163 PortDeclaration::Ref(Box::new(PortDeclarationRef { nodes: (a, b) })),
164 ))
165}
166
167#[tracable_parser]
168#[packrat_parser]
169pub(crate) fn port_declaration_interface(s: Span) -> IResult<Span, PortDeclaration> {
170 let (s, a) = many0(attribute_instance)(s)?;
171 let (s, b) = interface_port_declaration(s)?;
172 Ok((
173 s,
174 PortDeclaration::Interface(Box::new(PortDeclarationInterface { nodes: (a, b) })),
175 ))
176}
177
178#[tracable_parser]
179#[packrat_parser]
180pub(crate) fn port(s: Span) -> IResult<Span, Port> {
181 alt((port_named, port_non_named))(s)
182}
183
184#[recursive_parser]
185#[tracable_parser]
186#[packrat_parser]
187pub(crate) fn port_non_named(s: Span) -> IResult<Span, Port> {
188 let (s, a) = opt(port_expression)(s)?;
189 Ok((s, Port::NonNamed(Box::new(PortNonNamed { nodes: (a,) }))))
190}
191
192#[tracable_parser]
193#[packrat_parser]
194pub(crate) fn port_named(s: Span) -> IResult<Span, Port> {
195 let (s, a) = symbol(".")(s)?;
196 let (s, b) = port_identifier(s)?;
197 let (s, c) = paren(opt(port_expression))(s)?;
198 Ok((s, Port::Named(Box::new(PortNamed { nodes: (a, b, c) }))))
199}
200
201#[tracable_parser]
202#[packrat_parser]
203pub(crate) fn port_expression(s: Span) -> IResult<Span, PortExpression> {
204 alt((
205 map(port_reference, |x| {
206 PortExpression::PortReference(Box::new(x))
207 }),
208 port_expression_named,
209 ))(s)
210}
211
212#[tracable_parser]
213#[packrat_parser]
214pub(crate) fn port_expression_named(s: Span) -> IResult<Span, PortExpression> {
215 let (s, a) = brace(list(symbol(","), port_reference))(s)?;
216 Ok((
217 s,
218 PortExpression::Brace(Box::new(PortExpressionBrace { nodes: (a,) })),
219 ))
220}
221
222#[tracable_parser]
223#[packrat_parser]
224pub(crate) fn port_reference(s: Span) -> IResult<Span, PortReference> {
225 let (s, a) = port_identifier(s)?;
226 let (s, b) = constant_select(s)?;
227 Ok((s, PortReference { nodes: (a, b) }))
228}
229
230#[tracable_parser]
231#[packrat_parser]
232pub(crate) fn port_direction(s: Span) -> IResult<Span, PortDirection> {
233 alt((
234 map(keyword("input"), |x| PortDirection::Input(Box::new(x))),
235 map(keyword("output"), |x| PortDirection::Output(Box::new(x))),
236 map(keyword("inout"), |x| PortDirection::Inout(Box::new(x))),
237 map(keyword("ref"), |x| PortDirection::Ref(Box::new(x))),
238 ))(s)
239}
240
241#[tracable_parser]
242#[packrat_parser]
243pub(crate) fn net_port_header(s: Span) -> IResult<Span, NetPortHeader> {
244 let (s, a) = opt(port_direction)(s)?;
245 let (s, b) = net_port_type(s)?;
246 Ok((s, NetPortHeader { nodes: (a, b) }))
247}
248
249#[tracable_parser]
250#[packrat_parser]
251pub(crate) fn variable_port_header(s: Span) -> IResult<Span, VariablePortHeader> {
252 let (s, a) = opt(port_direction)(s)?;
253 let (s, b) = variable_port_type(s)?;
254 Ok((s, VariablePortHeader { nodes: (a, b) }))
255}
256
257#[tracable_parser]
258#[packrat_parser]
259pub(crate) fn interface_port_header(s: Span) -> IResult<Span, InterfacePortHeader> {
260 alt((
261 interface_port_header_identifier,
262 interface_port_header_interface,
263 ))(s)
264}
265
266#[tracable_parser]
267#[packrat_parser]
268pub(crate) fn interface_port_header_identifier(s: Span) -> IResult<Span, InterfacePortHeader> {
269 let (s, a) = interface_identifier(s)?;
270 let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?;
271 Ok((
272 s,
273 InterfacePortHeader::Identifier(Box::new(InterfacePortHeaderIdentifier { nodes: (a, b) })),
274 ))
275}
276
277#[tracable_parser]
278#[packrat_parser]
279pub(crate) fn interface_port_header_interface(s: Span) -> IResult<Span, InterfacePortHeader> {
280 let (s, a) = keyword("interface")(s)?;
281 let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?;
282 Ok((
283 s,
284 InterfacePortHeader::Interface(Box::new(InterfacePortHeaderInterface { nodes: (a, b) })),
285 ))
286}
287
288#[tracable_parser]
289#[packrat_parser]
290pub(crate) fn ansi_port_declaration(s: Span) -> IResult<Span, AnsiPortDeclaration> {
291 alt((
292 ansi_port_declaration_net,
293 ansi_port_declaration_port,
294 ansi_port_declaration_paren,
295 ))(s)
296}
297
298#[tracable_parser]
299#[packrat_parser]
300pub(crate) fn ansi_port_declaration_net(s: Span) -> IResult<Span, AnsiPortDeclaration> {
301 let (s, a) = opt(net_port_header_or_interface_port_header)(s)?;
302 let (s, b) = port_identifier(s)?;
303 let (s, c) = many0(unpacked_dimension)(s)?;
304 let (s, d) = opt(pair(symbol("="), constant_expression))(s)?;
305 Ok((
306 s,
307 AnsiPortDeclaration::Net(Box::new(AnsiPortDeclarationNet {
308 nodes: (a, b, c, d),
309 })),
310 ))
311}
312
313#[tracable_parser]
314#[packrat_parser]
315pub(crate) fn net_port_header_or_interface_port_header(
316 s: Span,
317) -> IResult<Span, NetPortHeaderOrInterfacePortHeader> {
318 alt((
319 map(interface_port_header, |x| {
320 NetPortHeaderOrInterfacePortHeader::InterfacePortHeader(Box::new(x))
321 }),
322 map(net_port_header, |x| {
323 NetPortHeaderOrInterfacePortHeader::NetPortHeader(Box::new(x))
324 }),
325 ))(s)
326}
327
328#[tracable_parser]
329#[packrat_parser]
330pub(crate) fn ansi_port_declaration_port(s: Span) -> IResult<Span, AnsiPortDeclaration> {
331 let (s, a) = opt(variable_port_header)(s)?;
332 let (s, b) = port_identifier(s)?;
333 let (s, c) = many0(variable_dimension)(s)?;
334 let (s, d) = opt(pair(symbol("="), constant_expression))(s)?;
335 Ok((
336 s,
337 AnsiPortDeclaration::Variable(Box::new(AnsiPortDeclarationVariable {
338 nodes: (a, b, c, d),
339 })),
340 ))
341}
342
343#[tracable_parser]
344#[packrat_parser]
345pub(crate) fn ansi_port_declaration_paren(s: Span) -> IResult<Span, AnsiPortDeclaration> {
346 let (s, a) = opt(port_direction)(s)?;
347 let (s, b) = symbol(".")(s)?;
348 let (s, c) = port_identifier(s)?;
349 let (s, d) = paren(opt(expression))(s)?;
350 Ok((
351 s,
352 AnsiPortDeclaration::Paren(Box::new(AnsiPortDeclarationParen {
353 nodes: (a, b, c, d),
354 })),
355 ))
356}