scarf_parser/parser/source_text/
system_verilog_source_text.rs

1// =======================================================================
2// system_verilog_source_text.rs
3// =======================================================================
4// Parsing for 1800-2023 A.1.2
5
6use crate::*;
7use chumsky::prelude::*;
8use scarf_syntax::*;
9
10pub(crate) fn attribute_instance_vec_parser<'a, I>()
11-> impl Parser<'a, I, Vec<AttributeInstance<'a>>, ParserError<'a>>
12where
13    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
14{
15    attribute_instance_parser()
16        .repeated()
17        .collect::<Vec<AttributeInstance>>()
18}
19
20pub fn source_text_parser<'a, I>() -> impl Parser<'a, I, SourceText<'a>, ParserError<'a>>
21where
22    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
23{
24    extra_node_parser()
25        .then(timeunits_declaration_parser().or_not())
26        .then(
27            description_parser()
28                .repeated()
29                .collect::<Vec<Description<'a>>>(),
30        )
31        .map(|((a, b), c)| SourceText(a, b, c))
32}
33
34pub fn description_parser<'a, I>() -> impl Parser<'a, I, Description<'a>, ParserError<'a>>
35where
36    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
37{
38    let description_package_item_parser = attribute_instance_vec_parser()
39        .then(package_item_parser())
40        .map(|(a, b)| DescriptionPackageItem(a, b));
41    let description_bind_directive_parser = attribute_instance_vec_parser()
42        .then(bind_directive_parser())
43        .map(|(a, b)| DescriptionBindDirective(a, b));
44    choice((
45        module_declaration_parser().map(|a| Description::ModuleDeclaration(Box::new(a))),
46        udp_declaration_parser().map(|a| Description::UdpDeclaration(Box::new(a))),
47        interface_declaration_parser().map(|a| Description::InterfaceDeclaration(Box::new(a))),
48        program_declaration_parser().map(|a| Description::ProgramDeclaration(Box::new(a))),
49        package_declaration_parser().map(|a| Description::PackageDeclaration(Box::new(a))),
50        description_package_item_parser.map(|a| Description::DescriptionPackageItem(Box::new(a))),
51        description_bind_directive_parser
52            .map(|a| Description::DescriptionBindDirective(Box::new(a))),
53        config_declaration_parser().map(|a| Description::ConfigDeclaration(Box::new(a))),
54    ))
55    .boxed()
56}
57
58pub fn module_declaration_parser<'a, I>()
59-> impl Parser<'a, I, ModuleDeclaration<'a>, ParserError<'a>>
60where
61    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
62{
63    choice((
64        module_declaration_nonansi_parser()
65            .map(|a| ModuleDeclaration::ModuleDeclarationNonansi(Box::new(a))),
66        module_declaration_ansi_parser()
67            .map(|a| ModuleDeclaration::ModuleDeclarationAnsi(Box::new(a))),
68        module_declaration_wildcard_parser()
69            .map(|a| ModuleDeclaration::ModuleDeclarationWildcard(Box::new(a))),
70        module_declaration_extern_nonansi_parser()
71            .map(|a| ModuleDeclaration::ModuleDeclarationExternNonansi(Box::new(a))),
72        module_declaration_extern_ansi_parser()
73            .map(|a| ModuleDeclaration::ModuleDeclarationExternAnsi(Box::new(a))),
74    ))
75}
76
77pub fn module_declaration_nonansi_parser<'a, I>()
78-> impl Parser<'a, I, ModuleDeclarationNonansi<'a>, ParserError<'a>>
79where
80    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
81{
82    module_nonansi_header_parser()
83        .then(timeunits_declaration_parser().or_not())
84        .then(
85            module_item_parser()
86                .repeated()
87                .collect::<Vec<NonPortProgramItem>>(),
88        )
89        .then(token(Token::Endmodule))
90        .then(
91            token(Token::Colon)
92                .then(module_identifier_parser())
93                .or_not(),
94        )
95        .map(|((((a, b), c), d), e)| ModuleDeclarationNonansi(a, b, c, d, e))
96}
97
98pub fn module_declaration_ansi_parser<'a, I>()
99-> impl Parser<'a, I, ModuleDeclarationAnsi<'a>, ParserError<'a>>
100where
101    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
102{
103    module_ansi_header_parser()
104        .then(timeunits_declaration_parser().or_not())
105        .then(
106            non_port_module_item_parser()
107                .repeated()
108                .collect::<Vec<NonPortProgramItem>>(),
109        )
110        .then(token(Token::Endmodule))
111        .then(
112            token(Token::Colon)
113                .then(module_identifier_parser())
114                .or_not(),
115        )
116        .map(|((((a, b), c), d), e)| ModuleDeclarationAnsi(a, b, c, d, e))
117        .boxed()
118}
119
120pub fn module_nonansi_header_parser<'a, I>()
121-> impl Parser<'a, I, ModuleNonansiHeader<'a>, ParserError<'a>>
122where
123    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
124{
125    attribute_instance_vec_parser()
126        .then(module_keyword_parser())
127        .then(lifetime_parser().or_not())
128        .then(module_identifier_parser())
129        .then(
130            package_import_declaration_parser()
131                .repeated()
132                .collect::<Vec<PackageImportDeclaration>>(),
133        )
134        .then(parameter_port_list_parser().or_not())
135        .then(list_of_ports_parser())
136        .then(token(Token::SColon))
137        .map(|(((((((a, b), c), d), e), f), g), h)| ModuleNonansiHeader(a, b, c, d, e, f, g, h))
138        .boxed()
139}
140
141pub fn module_ansi_header_parser<'a, I>()
142-> impl Parser<'a, I, ModuleAnsiHeader<'a>, ParserError<'a>>
143where
144    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
145{
146    attribute_instance_vec_parser()
147        .then(module_keyword_parser())
148        .then(lifetime_parser().or_not())
149        .then(module_identifier_parser())
150        .then(
151            package_import_declaration_parser()
152                .repeated()
153                .collect::<Vec<PackageImportDeclaration>>(),
154        )
155        .then(parameter_port_list_parser().or_not())
156        .then(list_of_port_declarations_parser().or_not())
157        .then(token(Token::SColon))
158        .map(|(((((((a, b), c), d), e), f), g), h)| ModuleAnsiHeader(a, b, c, d, e, f, g, h))
159        .boxed()
160}
161
162pub fn module_declaration_wildcard_parser<'a, I>()
163-> impl Parser<'a, I, ModuleDeclarationWildcard<'a>, ParserError<'a>>
164where
165    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
166{
167    attribute_instance_vec_parser()
168        .then(module_keyword_parser())
169        .then(lifetime_parser().or_not())
170        .then(module_identifier_parser())
171        .then(token(Token::Paren))
172        .then(token(Token::Period))
173        .then(token(Token::StarEparen))
174        .then(token(Token::SColon))
175        .then(timeunits_declaration_parser().or_not())
176        .then(
177            module_item_parser()
178                .repeated()
179                .collect::<Vec<ProgramItem>>(),
180        )
181        .then(token(Token::Endmodule))
182        .then(
183            token(Token::Colon)
184                .then(module_identifier_parser())
185                .or_not(),
186        )
187        .map(|(((((((((((a, b), c), d), e), f), g), h), i), j), k), l)| {
188            ModuleDeclarationWildcard(a, b, c, d, e, f, g, h, i, j, k, l)
189        })
190        .boxed()
191}
192
193pub fn module_declaration_extern_nonansi_parser<'a, I>()
194-> impl Parser<'a, I, ModuleDeclarationExternNonansi<'a>, ParserError<'a>>
195where
196    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
197{
198    token(Token::Extern)
199        .then(module_nonansi_header_parser())
200        .map(|(a, b)| ModuleDeclarationExternNonansi(a, b))
201}
202
203pub fn module_declaration_extern_ansi_parser<'a, I>()
204-> impl Parser<'a, I, ModuleDeclarationExternAnsi<'a>, ParserError<'a>>
205where
206    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
207{
208    token(Token::Extern)
209        .then(module_ansi_header_parser())
210        .map(|(a, b)| ModuleDeclarationExternAnsi(a, b))
211}
212
213pub fn module_keyword_parser<'a, I>() -> impl Parser<'a, I, ModuleKeyword<'a>, ParserError<'a>>
214where
215    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
216{
217    choice((
218        token(Token::Module).map(|a| ModuleKeyword::Module(a)),
219        token(Token::Macromodule).map(|a| ModuleKeyword::Macromodule(a)),
220    ))
221}
222
223pub fn interface_declaration_parser<'a, I>()
224-> impl Parser<'a, I, InterfaceDeclaration<'a>, ParserError<'a>>
225where
226    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
227{
228    choice((
229        interface_declaration_nonansi_parser()
230            .map(|a| InterfaceDeclaration::InterfaceDeclarationNonansi(Box::new(a))),
231        interface_declaration_ansi_parser()
232            .map(|a| InterfaceDeclaration::InterfaceDeclarationAnsi(Box::new(a))),
233        interface_declaration_wildcard_parser()
234            .map(|a| InterfaceDeclaration::InterfaceDeclarationWildcard(Box::new(a))),
235        interface_declaration_extern_nonansi_parser()
236            .map(|a| InterfaceDeclaration::InterfaceDeclarationExternNonansi(Box::new(a))),
237        interface_declaration_extern_ansi_parser()
238            .map(|a| InterfaceDeclaration::InterfaceDeclarationExternAnsi(Box::new(a))),
239    ))
240}
241
242pub fn interface_declaration_nonansi_parser<'a, I>()
243-> impl Parser<'a, I, InterfaceDeclarationNonansi<'a>, ParserError<'a>>
244where
245    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
246{
247    interface_nonansi_header_parser()
248        .then(timeunits_declaration_parser().or_not())
249        .then(
250            interface_item_parser()
251                .repeated()
252                .collect::<Vec<NonPortProgramItem>>(),
253        )
254        .then(token(Token::Endinterface))
255        .then(
256            token(Token::Colon)
257                .then(interface_identifier_parser())
258                .or_not(),
259        )
260        .map(|((((a, b), c), d), e)| InterfaceDeclarationNonansi(a, b, c, d, e))
261        .boxed()
262}
263
264pub fn interface_declaration_ansi_parser<'a, I>()
265-> impl Parser<'a, I, InterfaceDeclarationAnsi<'a>, ParserError<'a>>
266where
267    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
268{
269    interface_ansi_header_parser()
270        .then(timeunits_declaration_parser().or_not())
271        .then(
272            non_port_interface_item_parser()
273                .repeated()
274                .collect::<Vec<NonPortProgramItem>>(),
275        )
276        .then(token(Token::Endinterface))
277        .then(
278            token(Token::Colon)
279                .then(interface_identifier_parser())
280                .or_not(),
281        )
282        .map(|((((a, b), c), d), e)| InterfaceDeclarationAnsi(a, b, c, d, e))
283        .boxed()
284}
285
286pub fn interface_declaration_wildcard_parser<'a, I>()
287-> impl Parser<'a, I, InterfaceDeclarationWildcard<'a>, ParserError<'a>>
288where
289    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
290{
291    attribute_instance_vec_parser()
292        .then(token(Token::Interface))
293        .then(interface_identifier_parser())
294        .then(token(Token::Paren))
295        .then(token(Token::Period))
296        .then(token(Token::StarEparen))
297        .then(token(Token::SColon))
298        .then(timeunits_declaration_parser().or_not())
299        .then(
300            interface_item_parser()
301                .repeated()
302                .collect::<Vec<ProgramItem>>(),
303        )
304        .then(token(Token::Endinterface))
305        .then(
306            token(Token::Colon)
307                .then(interface_identifier_parser())
308                .or_not(),
309        )
310        .map(|((((((((((a, b), c), d), e), f), g), h), i), j), k)| {
311            InterfaceDeclarationWildcard(a, b, c, d, e, f, g, h, i, j, k)
312        })
313        .boxed()
314}
315
316pub fn interface_declaration_extern_nonansi_parser<'a, I>()
317-> impl Parser<'a, I, InterfaceDeclarationExternNonansi<'a>, ParserError<'a>>
318where
319    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
320{
321    token(Token::Extern)
322        .then(interface_nonansi_header_parser())
323        .map(|(a, b)| InterfaceDeclarationExternNonansi(a, b))
324}
325
326pub fn interface_declaration_extern_ansi_parser<'a, I>()
327-> impl Parser<'a, I, InterfaceDeclarationExternAnsi<'a>, ParserError<'a>>
328where
329    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
330{
331    token(Token::Extern)
332        .then(interface_ansi_header_parser())
333        .map(|(a, b)| InterfaceDeclarationExternAnsi(a, b))
334}
335
336pub fn interface_nonansi_header_parser<'a, I>()
337-> impl Parser<'a, I, InterfaceNonansiHeader<'a>, ParserError<'a>>
338where
339    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
340{
341    attribute_instance_vec_parser()
342        .then(token(Token::Interface))
343        .then(lifetime_parser().or_not())
344        .then(interface_identifier_parser())
345        .then(
346            package_import_declaration_parser()
347                .repeated()
348                .collect::<Vec<PackageImportDeclaration>>(),
349        )
350        .then(parameter_port_list_parser().or_not())
351        .then(list_of_ports_parser())
352        .then(token(Token::SColon))
353        .map(|(((((((a, b), c), d), e), f), g), h)| InterfaceNonansiHeader(a, b, c, d, e, f, g, h))
354        .boxed()
355}
356
357pub fn interface_ansi_header_parser<'a, I>()
358-> impl Parser<'a, I, InterfaceAnsiHeader<'a>, ParserError<'a>>
359where
360    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
361{
362    attribute_instance_vec_parser()
363        .then(token(Token::Interface))
364        .then(lifetime_parser().or_not())
365        .then(interface_identifier_parser())
366        .then(
367            package_import_declaration_parser()
368                .repeated()
369                .collect::<Vec<PackageImportDeclaration>>(),
370        )
371        .then(parameter_port_list_parser().or_not())
372        .then(list_of_port_declarations_parser().or_not())
373        .then(token(Token::SColon))
374        .map(|(((((((a, b), c), d), e), f), g), h)| InterfaceAnsiHeader(a, b, c, d, e, f, g, h))
375        .boxed()
376}
377
378pub fn program_declaration_parser<'a, I>()
379-> impl Parser<'a, I, ProgramDeclaration<'a>, ParserError<'a>>
380where
381    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
382{
383    choice((
384        program_declaration_nonansi_parser()
385            .map(|a| ProgramDeclaration::ProgramDeclarationNonansi(Box::new(a))),
386        program_declaration_ansi_parser()
387            .map(|a| ProgramDeclaration::ProgramDeclarationAnsi(Box::new(a))),
388        program_declaration_wildcard_parser()
389            .map(|a| ProgramDeclaration::ProgramDeclarationWildcard(Box::new(a))),
390        program_declaration_extern_nonansi_parser()
391            .map(|a| ProgramDeclaration::ProgramDeclarationExternNonansi(Box::new(a))),
392        program_declaration_extern_ansi_parser()
393            .map(|a| ProgramDeclaration::ProgramDeclarationExternAnsi(Box::new(a))),
394    ))
395}
396
397pub fn program_declaration_nonansi_parser<'a, I>()
398-> impl Parser<'a, I, ProgramDeclarationNonansi<'a>, ParserError<'a>>
399where
400    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
401{
402    program_nonansi_header_parser()
403        .then(timeunits_declaration_parser().or_not())
404        .then(
405            program_item_parser()
406                .repeated()
407                .collect::<Vec<NonPortProgramItem>>(),
408        )
409        .then(token(Token::Endprogram))
410        .then(
411            token(Token::Colon)
412                .then(program_identifier_parser())
413                .or_not(),
414        )
415        .map(|((((a, b), c), d), e)| ProgramDeclarationNonansi(a, b, c, d, e))
416        .boxed()
417}
418
419pub fn program_declaration_ansi_parser<'a, I>()
420-> impl Parser<'a, I, ProgramDeclarationAnsi<'a>, ParserError<'a>>
421where
422    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
423{
424    program_ansi_header_parser()
425        .then(timeunits_declaration_parser().or_not())
426        .then(
427            non_port_program_item_parser()
428                .repeated()
429                .collect::<Vec<NonPortProgramItem>>(),
430        )
431        .then(token(Token::Endprogram))
432        .then(
433            token(Token::Colon)
434                .then(program_identifier_parser())
435                .or_not(),
436        )
437        .map(|((((a, b), c), d), e)| ProgramDeclarationAnsi(a, b, c, d, e))
438        .boxed()
439}
440
441pub fn program_declaration_wildcard_parser<'a, I>()
442-> impl Parser<'a, I, ProgramDeclarationWildcard<'a>, ParserError<'a>>
443where
444    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
445{
446    attribute_instance_vec_parser()
447        .then(token(Token::Program))
448        .then(program_identifier_parser())
449        .then(token(Token::Paren))
450        .then(token(Token::Period))
451        .then(token(Token::StarEparen))
452        .then(token(Token::SColon))
453        .then(timeunits_declaration_parser().or_not())
454        .then(
455            program_item_parser()
456                .repeated()
457                .collect::<Vec<ProgramItem>>(),
458        )
459        .then(token(Token::Endprogram))
460        .then(
461            token(Token::Colon)
462                .then(program_identifier_parser())
463                .or_not(),
464        )
465        .map(|((((((((((a, b), c), d), e), f), g), h), i), j), k)| {
466            ProgramDeclarationWildcard(a, b, c, d, e, f, g, h, i, j, k)
467        })
468        .boxed()
469}
470
471pub fn program_declaration_extern_nonansi_parser<'a, I>()
472-> impl Parser<'a, I, ProgramDeclarationExternNonansi<'a>, ParserError<'a>>
473where
474    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
475{
476    token(Token::Extern)
477        .then(program_nonansi_header_parser())
478        .map(|(a, b)| ProgramDeclarationExternNonansi(a, b))
479}
480
481pub fn program_declaration_extern_ansi_parser<'a, I>()
482-> impl Parser<'a, I, ProgramDeclarationExternAnsi<'a>, ParserError<'a>>
483where
484    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
485{
486    token(Token::Extern)
487        .then(program_ansi_header_parser())
488        .map(|(a, b)| ProgramDeclarationExternAnsi(a, b))
489}
490
491pub fn program_nonansi_header_parser<'a, I>()
492-> impl Parser<'a, I, ProgramNonansiHeader<'a>, ParserError<'a>>
493where
494    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
495{
496    attribute_instance_vec_parser()
497        .then(token(Token::Program))
498        .then(lifetime_parser().or_not())
499        .then(program_identifier_parser())
500        .then(
501            package_import_declaration_parser()
502                .repeated()
503                .collect::<Vec<PackageImportDeclaration>>(),
504        )
505        .then(parameter_port_list_parser().or_not())
506        .then(list_of_ports_parser())
507        .then(token(Token::SColon))
508        .map(|(((((((a, b), c), d), e), f), g), h)| ProgramNonansiHeader(a, b, c, d, e, f, g, h))
509        .boxed()
510}
511
512pub fn program_ansi_header_parser<'a, I>()
513-> impl Parser<'a, I, ProgramAnsiHeader<'a>, ParserError<'a>>
514where
515    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
516{
517    attribute_instance_vec_parser()
518        .then(token(Token::Program))
519        .then(lifetime_parser().or_not())
520        .then(program_identifier_parser())
521        .then(
522            package_import_declaration_parser()
523                .repeated()
524                .collect::<Vec<PackageImportDeclaration>>(),
525        )
526        .then(parameter_port_list_parser().or_not())
527        .then(list_of_port_declarations_parser().or_not())
528        .then(token(Token::SColon))
529        .map(|(((((((a, b), c), d), e), f), g), h)| ProgramAnsiHeader(a, b, c, d, e, f, g, h))
530        .boxed()
531}
532
533pub fn checker_declaration_parser<'a, I>()
534-> impl Parser<'a, I, CheckerDeclaration<'a>, ParserError<'a>>
535where
536    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
537{
538    let checker_declaration_port_list_parser = token(Token::Paren)
539        .then(checker_port_list_parser())
540        .then(token(Token::EParen))
541        .map(|((a, b), c)| (a, b, c));
542    let checker_declaration_item_parser = attribute_instance_vec_parser()
543        .then(checker_or_generate_item_parser())
544        .repeated()
545        .collect::<Vec<(Vec<AttributeInstance>, CheckerOrGenerateItem)>>();
546    token(Token::Checker)
547        .then(checker_identifier_parser())
548        .then(checker_declaration_port_list_parser.or_not())
549        .then(token(Token::SColon))
550        .then(checker_declaration_item_parser)
551        .then(token(Token::Endchecker))
552        .then(
553            token(Token::Colon)
554                .then(checker_identifier_parser())
555                .or_not(),
556        )
557        .map(|((((((a, b), c), d), e), f), g)| CheckerDeclaration(a, b, c, d, e, f, g))
558        .boxed()
559}
560
561pub fn class_declaration_parser<'a, I>() -> impl Parser<'a, I, ClassDeclaration<'a>, ParserError<'a>>
562where
563    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
564{
565    let class_declaration_extension_parser = token(Token::Extends)
566        .then(class_type_parser())
567        .then(
568            token(Token::Paren)
569                .then(choice((
570                    list_of_arguments_parser()
571                        .map(|a| ClassDeclarationExtensionArguments::ListOfArguments(Box::new(a))),
572                    token(Token::Default)
573                        .map(|metadata| ClassDeclarationExtensionArguments::Default(metadata)),
574                )))
575                .then(token(Token::EParen))
576                .map(|((a, b), c)| (a, b, c))
577                .or_not(),
578        )
579        .map(|((a, b), c)| (a, b, c));
580    let class_declaration_implementation_parser = token(Token::Implements)
581        .then(interface_class_type_parser())
582        .then(
583            token(Token::Comma)
584                .then(interface_class_type_parser())
585                .repeated()
586                .collect::<Vec<(Metadata<'a>, InterfaceClassType)>>(),
587        )
588        .map(|((a, b), c)| (a, b, c));
589    token(Token::Virtual)
590        .or_not()
591        .then(token(Token::Class))
592        .then(final_specifier_parser().or_not())
593        .then(class_identifier_parser())
594        .then(parameter_port_list_parser().or_not())
595        .then(class_declaration_extension_parser.or_not())
596        .then(class_declaration_implementation_parser.or_not())
597        .then(token(Token::SColon))
598        .then(class_item_parser().repeated().collect::<Vec<ClassItem>>())
599        .then(token(Token::Endclass))
600        .then(token(Token::Colon).then(class_identifier_parser()).or_not())
601        .map(|((((((((((a, b), c), d), e), f), g), h), i), j), k)| {
602            ClassDeclaration(a, b, c, d, e, f, g, h, i, j, k)
603        })
604        .boxed()
605}
606
607pub fn interface_class_declaration_parser<'a, I>()
608-> impl Parser<'a, I, InterfaceClassDeclaration<'a>, ParserError<'a>>
609where
610    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
611{
612    let interface_class_declaration_extension_parser = token(Token::Extends)
613        .then(interface_class_type_parser())
614        .then(
615            token(Token::Comma)
616                .then(interface_class_type_parser())
617                .repeated()
618                .collect::<Vec<(Metadata<'a>, InterfaceClassType)>>(),
619        )
620        .map(|((a, b), c)| (a, b, c));
621    token(Token::Interface)
622        .then(token(Token::Class))
623        .then(class_identifier_parser())
624        .then(parameter_port_list_parser().or_not())
625        .then(interface_class_declaration_extension_parser.or_not())
626        .then(token(Token::SColon))
627        .then(
628            interface_class_item_parser()
629                .repeated()
630                .collect::<Vec<InterfaceClassItem>>(),
631        )
632        .then(token(Token::Endclass))
633        .then(token(Token::Colon).then(class_identifier_parser()).or_not())
634        .map(|((((((((a, b), c), d), e), f), g), h), i)| {
635            InterfaceClassDeclaration(a, b, c, d, e, f, g, h, i)
636        })
637        .boxed()
638}
639
640pub fn package_declaration_parser<'a, I>()
641-> impl Parser<'a, I, PackageDeclaration<'a>, ParserError<'a>>
642where
643    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
644{
645    let attribute_package_items_parser = attribute_instance_vec_parser()
646        .then(package_item_parser())
647        .repeated()
648        .collect::<Vec<(Vec<AttributeInstance>, PackageItem)>>();
649    attribute_instance_vec_parser()
650        .then(token(Token::Package))
651        .then(lifetime_parser().or_not())
652        .then(package_identifier_parser())
653        .then(token(Token::SColon))
654        .then(timeunits_declaration_parser().or_not())
655        .then(attribute_package_items_parser)
656        .then(token(Token::Endpackage))
657        .then(
658            token(Token::Colon)
659                .then(package_identifier_parser())
660                .or_not(),
661        )
662        .map(|((((((((a, b), c), d), e), f), g), h), i)| {
663            PackageDeclaration(a, b, c, d, e, f, g, h, i)
664        })
665        .boxed()
666}
667
668pub fn timeunits_declaration_parser<'a, I>()
669-> impl Parser<'a, I, TimeunitsDeclaration<'a>, ParserError<'a>>
670where
671    I: ValueInput<'a, Token = Token<'a>, Span = ParserSpan>,
672{
673    let timeunit_parser = token(Token::Timeunit)
674        .then(time_literal_parser())
675        .then(token(Token::Slash).then(time_literal_parser()).or_not())
676        .then(token(Token::SColon))
677        .map(|(((a, b), c), d)| TimeunitsDeclaration::Timeunit(a, b, c, d));
678    let timeprecision_parser = token(Token::Timeprecision)
679        .then(time_literal_parser())
680        .then(token(Token::SColon))
681        .map(|((a, b), c)| TimeunitsDeclaration::Timeprecision(a, b, c));
682    let timeunitprecision_parser = token(Token::Timeunit)
683        .then(time_literal_parser())
684        .then(token(Token::SColon))
685        .then(token(Token::Timeprecision))
686        .then(time_literal_parser())
687        .then(token(Token::SColon))
688        .map(|(((((a, b), c), d), e), f)| {
689            TimeunitsDeclaration::Timeunitprecision(a, b, c, d, e, f)
690        });
691    let timeprecisionunit_parser = token(Token::Timeprecision)
692        .then(time_literal_parser())
693        .then(token(Token::SColon))
694        .then(token(Token::Timeunit))
695        .then(time_literal_parser())
696        .then(token(Token::SColon))
697        .map(|(((((a, b), c), d), e), f)| {
698            TimeunitsDeclaration::Timeprecisionunit(a, b, c, d, e, f)
699        });
700    choice((
701        timeunit_parser,
702        timeprecision_parser,
703        timeunitprecision_parser,
704        timeprecisionunit_parser,
705    ))
706    .boxed()
707}