1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
use crate::*;

// -----------------------------------------------------------------------------

#[tracable_parser]
#[packrat_parser]
pub(crate) fn source_text(s: Span) -> IResult<Span, SourceText> {
    let (s, a) = many0(white_space)(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(description)(s)?;
    Ok((s, SourceText { nodes: (a, b, c) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn description(s: Span) -> IResult<Span, Description> {
    alt((
        map(module_declaration, |x| {
            Description::ModuleDeclaration(Box::new(x))
        }),
        map(udp_declaration, |x| {
            Description::UdpDeclaration(Box::new(x))
        }),
        map(interface_declaration, |x| {
            Description::InterfaceDeclaration(Box::new(x))
        }),
        map(interface_class_declaration, |x| {
            Description::InterfaceClassDeclaration(Box::new(x))
        }),
        map(program_declaration, |x| {
            Description::ProgramDeclaration(Box::new(x))
        }),
        map(package_declaration, |x| {
            Description::PackageDeclaration(Box::new(x))
        }),
        description_package_item,
        description_bind_directive,
        map(config_declaration, |x| {
            Description::ConfigDeclaration(Box::new(x))
        }),
    ))(s)
}

#[recursive_parser]
#[tracable_parser]
#[packrat_parser]
pub(crate) fn description_package_item(s: Span) -> IResult<Span, Description> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = package_item(s)?;
    Ok((
        s,
        Description::PackageItem(Box::new(DescriptionPackageItem { nodes: (a, b) })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn description_bind_directive(s: Span) -> IResult<Span, Description> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = bind_directive(s)?;
    Ok((
        s,
        Description::BindDirective(Box::new(DescriptionBindDirective { nodes: (a, b) })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_nonansi_header(s: Span) -> IResult<Span, ModuleNonansiHeader> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = module_keyword(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = module_identifier(s)?;
    let (s, e) = many0(package_import_declaration)(s)?;
    let (s, f) = opt(parameter_port_list)(s)?;
    let (s, g) = list_of_ports(s)?;
    let (s, h) = symbol(";")(s)?;
    Ok((
        s,
        ModuleNonansiHeader {
            nodes: (a, b, c, d, e, f, g, h),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_ansi_header(s: Span) -> IResult<Span, ModuleAnsiHeader> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = module_keyword(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = module_identifier(s)?;
    let (s, e) = many0(package_import_declaration)(s)?;
    let (s, f) = opt(parameter_port_list)(s)?;
    let (s, g) = opt(list_of_port_declarations)(s)?;
    let (s, h) = symbol(";")(s)?;
    Ok((
        s,
        ModuleAnsiHeader {
            nodes: (a, b, c, d, e, f, g, h),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_declaration(s: Span) -> IResult<Span, ModuleDeclaration> {
    alt((
        module_declaration_nonansi,
        module_declaration_ansi,
        module_declaration_wildcard,
        module_declaration_extern_nonansi,
        module_declaration_extern_ansi,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_declaration_nonansi(s: Span) -> IResult<Span, ModuleDeclaration> {
    let (s, a) = module_nonansi_header(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(module_item)(s)?;
    let (s, d) = keyword("endmodule")(s)?;
    let (s, e) = opt(pair(symbol(":"), module_identifier))(s)?;
    Ok((
        s,
        ModuleDeclaration::Nonansi(Box::new(ModuleDeclarationNonansi {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_declaration_ansi(s: Span) -> IResult<Span, ModuleDeclaration> {
    let (s, a) = module_ansi_header(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(non_port_module_item)(s)?;
    let (s, d) = keyword("endmodule")(s)?;
    let (s, e) = opt(pair(symbol(":"), module_identifier))(s)?;
    Ok((
        s,
        ModuleDeclaration::Ansi(Box::new(ModuleDeclarationAnsi {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_declaration_wildcard(s: Span) -> IResult<Span, ModuleDeclaration> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = module_keyword(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = module_identifier(s)?;
    let (s, e) = paren(symbol(".*"))(s)?;
    let (s, f) = symbol(";")(s)?;
    let (s, g) = opt(timeunits_declaration)(s)?;
    let (s, h) = many0(module_item)(s)?;
    let (s, i) = keyword("endmodule")(s)?;
    let (s, j) = opt(pair(symbol(":"), module_identifier))(s)?;
    Ok((
        s,
        ModuleDeclaration::Wildcard(Box::new(ModuleDeclarationWildcard {
            nodes: (a, b, c, d, e, f, g, h, i, j),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_declaration_extern_nonansi(s: Span) -> IResult<Span, ModuleDeclaration> {
    let (s, a) = keyword("extern")(s)?;
    let (s, b) = module_nonansi_header(s)?;
    Ok((
        s,
        ModuleDeclaration::ExternNonansi(Box::new(ModuleDeclarationExternNonansi {
            nodes: (a, b),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_declaration_extern_ansi(s: Span) -> IResult<Span, ModuleDeclaration> {
    let (s, a) = keyword("extern")(s)?;
    let (s, b) = module_ansi_header(s)?;
    Ok((
        s,
        ModuleDeclaration::ExternAnsi(Box::new(ModuleDeclarationExternAnsi { nodes: (a, b) })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn module_keyword(s: Span) -> IResult<Span, ModuleKeyword> {
    alt((
        map(keyword("module"), |x| ModuleKeyword::Module(Box::new(x))),
        map(keyword("macromodule"), |x| {
            ModuleKeyword::Macromodule(Box::new(x))
        }),
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_declaration(s: Span) -> IResult<Span, InterfaceDeclaration> {
    alt((
        interface_declaration_nonansi,
        interface_declaration_ansi,
        interface_declaration_wildcard,
        interface_declaration_extern_nonansi,
        interface_declaration_extern_ansi,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_declaration_nonansi(s: Span) -> IResult<Span, InterfaceDeclaration> {
    let (s, a) = interface_nonansi_header(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(interface_item)(s)?;
    let (s, d) = keyword("endinterface")(s)?;
    let (s, e) = opt(pair(symbol(":"), interface_identifier))(s)?;
    Ok((
        s,
        InterfaceDeclaration::Nonansi(Box::new(InterfaceDeclarationNonansi {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_declaration_ansi(s: Span) -> IResult<Span, InterfaceDeclaration> {
    let (s, a) = interface_ansi_header(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(non_port_interface_item)(s)?;
    let (s, d) = keyword("endinterface")(s)?;
    let (s, e) = opt(pair(symbol(":"), interface_identifier))(s)?;
    Ok((
        s,
        InterfaceDeclaration::Ansi(Box::new(InterfaceDeclarationAnsi {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_declaration_wildcard(s: Span) -> IResult<Span, InterfaceDeclaration> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("interface")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = interface_identifier(s)?;
    let (s, e) = paren(symbol(".*"))(s)?;
    let (s, f) = symbol(";")(s)?;
    let (s, g) = opt(timeunits_declaration)(s)?;
    let (s, h) = many0(interface_item)(s)?;
    let (s, i) = keyword("endinterface")(s)?;
    let (s, j) = opt(pair(symbol(":"), interface_identifier))(s)?;
    Ok((
        s,
        InterfaceDeclaration::Wildcard(Box::new(InterfaceDeclarationWildcard {
            nodes: (a, b, c, d, e, f, g, h, i, j),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_declaration_extern_nonansi(s: Span) -> IResult<Span, InterfaceDeclaration> {
    let (s, a) = keyword("extern")(s)?;
    let (s, b) = interface_nonansi_header(s)?;
    Ok((
        s,
        InterfaceDeclaration::ExternNonansi(Box::new(InterfaceDeclarationExternNonansi {
            nodes: (a, b),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_declaration_extern_ansi(s: Span) -> IResult<Span, InterfaceDeclaration> {
    let (s, a) = keyword("extern")(s)?;
    let (s, b) = interface_ansi_header(s)?;
    Ok((
        s,
        InterfaceDeclaration::ExternAnsi(Box::new(InterfaceDeclarationExternAnsi {
            nodes: (a, b),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_nonansi_header(s: Span) -> IResult<Span, InterfaceNonansiHeader> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("interface")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = interface_identifier(s)?;
    let (s, e) = many0(package_import_declaration)(s)?;
    let (s, f) = opt(parameter_port_list)(s)?;
    let (s, g) = list_of_ports(s)?;
    let (s, h) = symbol(";")(s)?;
    Ok((
        s,
        InterfaceNonansiHeader {
            nodes: (a, b, c, d, e, f, g, h),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_ansi_header(s: Span) -> IResult<Span, InterfaceAnsiHeader> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("interface")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = interface_identifier(s)?;
    let (s, e) = many0(package_import_declaration)(s)?;
    let (s, f) = opt(parameter_port_list)(s)?;
    let (s, g) = opt(list_of_port_declarations)(s)?;
    let (s, h) = symbol(";")(s)?;
    Ok((
        s,
        InterfaceAnsiHeader {
            nodes: (a, b, c, d, e, f, g, h),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_declaration(s: Span) -> IResult<Span, ProgramDeclaration> {
    alt((
        program_declaration_nonansi,
        program_declaration_ansi,
        program_declaration_wildcard,
        program_declaration_extern_nonansi,
        program_declaration_extern_ansi,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_declaration_nonansi(s: Span) -> IResult<Span, ProgramDeclaration> {
    let (s, a) = program_nonansi_header(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(program_item)(s)?;
    let (s, d) = keyword("endprogram")(s)?;
    let (s, e) = opt(pair(symbol(":"), program_identifier))(s)?;
    Ok((
        s,
        ProgramDeclaration::Nonansi(Box::new(ProgramDeclarationNonansi {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_declaration_ansi(s: Span) -> IResult<Span, ProgramDeclaration> {
    let (s, a) = program_ansi_header(s)?;
    let (s, b) = opt(timeunits_declaration)(s)?;
    let (s, c) = many0(non_port_program_item)(s)?;
    let (s, d) = keyword("endprogram")(s)?;
    let (s, e) = opt(pair(symbol(":"), program_identifier))(s)?;
    Ok((
        s,
        ProgramDeclaration::Ansi(Box::new(ProgramDeclarationAnsi {
            nodes: (a, b, c, d, e),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_declaration_wildcard(s: Span) -> IResult<Span, ProgramDeclaration> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("program")(s)?;
    let (s, c) = program_identifier(s)?;
    let (s, d) = paren(symbol(".*"))(s)?;
    let (s, e) = symbol(";")(s)?;
    let (s, f) = opt(timeunits_declaration)(s)?;
    let (s, g) = many0(program_item)(s)?;
    let (s, h) = keyword("endprogram")(s)?;
    let (s, i) = opt(pair(symbol(":"), program_identifier))(s)?;
    Ok((
        s,
        ProgramDeclaration::Wildcard(Box::new(ProgramDeclarationWildcard {
            nodes: (a, b, c, d, e, f, g, h, i),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_declaration_extern_nonansi(s: Span) -> IResult<Span, ProgramDeclaration> {
    let (s, a) = keyword("extern")(s)?;
    let (s, b) = program_nonansi_header(s)?;
    Ok((
        s,
        ProgramDeclaration::ExternNonansi(Box::new(ProgramDeclarationExternNonansi {
            nodes: (a, b),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_declaration_extern_ansi(s: Span) -> IResult<Span, ProgramDeclaration> {
    let (s, a) = keyword("extern")(s)?;
    let (s, b) = program_ansi_header(s)?;
    Ok((
        s,
        ProgramDeclaration::ExternAnsi(Box::new(ProgramDeclarationExternAnsi { nodes: (a, b) })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_nonansi_header(s: Span) -> IResult<Span, ProgramNonansiHeader> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("prgogram")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = program_identifier(s)?;
    let (s, e) = many0(package_import_declaration)(s)?;
    let (s, f) = opt(parameter_port_list)(s)?;
    let (s, g) = list_of_ports(s)?;
    let (s, h) = symbol(";")(s)?;
    Ok((
        s,
        ProgramNonansiHeader {
            nodes: (a, b, c, d, e, f, g, h),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn program_ansi_header(s: Span) -> IResult<Span, ProgramAnsiHeader> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("program")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = program_identifier(s)?;
    let (s, e) = many0(package_import_declaration)(s)?;
    let (s, f) = opt(parameter_port_list)(s)?;
    let (s, g) = opt(list_of_port_declarations)(s)?;
    let (s, h) = symbol(";")(s)?;
    Ok((
        s,
        ProgramAnsiHeader {
            nodes: (a, b, c, d, e, f, g, h),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn checker_declaration(s: Span) -> IResult<Span, CheckerDeclaration> {
    let (s, a) = keyword("checker")(s)?;
    let (s, b) = checker_identifier(s)?;
    let (s, c) = opt(paren(opt(checker_port_list)))(s)?;
    let (s, d) = symbol(";")(s)?;
    let (s, e) = many0(pair(many0(attribute_instance), checker_or_generate_item))(s)?;
    let (s, f) = keyword("endchecker")(s)?;
    let (s, g) = opt(pair(symbol(":"), checker_identifier))(s)?;
    Ok((
        s,
        CheckerDeclaration {
            nodes: (a, b, c, d, e, f, g),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn class_declaration(s: Span) -> IResult<Span, ClassDeclaration> {
    let (s, a) = opt(map(keyword("virtual"), |x| Virtual { nodes: (x,) }))(s)?;
    let (s, b) = keyword("class")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = class_identifier(s)?;
    let (s, e) = opt(parameter_port_list)(s)?;
    let (s, f) = opt(triple(
        keyword("extends"),
        class_type,
        opt(paren(list_of_arguments)),
    ))(s)?;
    let (s, g) = opt(pair(
        keyword("implements"),
        list(symbol(","), interface_class_type),
    ))(s)?;
    let (s, h) = symbol(";")(s)?;
    let (s, i) = many0(class_item)(s)?;
    let (s, j) = keyword("endclass")(s)?;
    let (s, k) = opt(pair(symbol(":"), class_identifier))(s)?;
    Ok((
        s,
        ClassDeclaration {
            nodes: (a, b, c, d, e, f, g, h, i, j, k),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_class_type(s: Span) -> IResult<Span, InterfaceClassType> {
    let (s, a) = ps_class_identifier(s)?;
    let (s, b) = opt(parameter_value_assignment)(s)?;
    Ok((s, InterfaceClassType { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_class_declaration(s: Span) -> IResult<Span, InterfaceClassDeclaration> {
    let (s, a) = keyword("interface")(s)?;
    let (s, b) = keyword("class")(s)?;
    let (s, c) = class_identifier(s)?;
    let (s, d) = opt(parameter_port_list)(s)?;
    let (s, e) = opt(pair(
        keyword("extends"),
        list(symbol(","), interface_class_type),
    ))(s)?;
    let (s, f) = symbol(";")(s)?;
    let (s, g) = many0(interface_class_item)(s)?;
    let (s, h) = keyword("endclass")(s)?;
    let (s, i) = opt(pair(symbol(":"), class_identifier))(s)?;
    Ok((
        s,
        InterfaceClassDeclaration {
            nodes: (a, b, c, d, e, f, g, h, i),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_class_item(s: Span) -> IResult<Span, InterfaceClassItem> {
    alt((
        map(type_declaration, |x| {
            InterfaceClassItem::TypeDeclaration(Box::new(x))
        }),
        interface_class_item_method,
        map(pair(local_parameter_declaration, symbol(";")), |x| {
            InterfaceClassItem::LocalParameterDeclaration(Box::new(x))
        }),
        map(pair(parameter_declaration, symbol(";")), |x| {
            InterfaceClassItem::ParameterDeclaration(Box::new(x))
        }),
        map(symbol(";"), |x| InterfaceClassItem::Null(Box::new(x))),
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_class_item_method(s: Span) -> IResult<Span, InterfaceClassItem> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = interface_class_method(s)?;
    Ok((
        s,
        InterfaceClassItem::Method(Box::new(InterfaceClassItemMethod { nodes: (a, b) })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn interface_class_method(s: Span) -> IResult<Span, InterfaceClassMethod> {
    let (s, a) = keyword("pure")(s)?;
    let (s, b) = keyword("virtual")(s)?;
    let (s, c) = method_prototype(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        InterfaceClassMethod {
            nodes: (a, b, c, d),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn package_declaration(s: Span) -> IResult<Span, PackageDeclaration> {
    let (s, a) = many0(attribute_instance)(s)?;
    let (s, b) = keyword("package")(s)?;
    let (s, c) = opt(lifetime)(s)?;
    let (s, d) = package_identifier(s)?;
    let (s, e) = symbol(";")(s)?;
    let (s, f) = opt(timeunits_declaration)(s)?;
    let (s, g) = many0(pair(many0(attribute_instance), package_item))(s)?;
    let (s, h) = keyword("endpackage")(s)?;
    let (s, i) = opt(pair(symbol(":"), package_identifier))(s)?;
    Ok((
        s,
        PackageDeclaration {
            nodes: (a, b, c, d, e, f, g, h, i),
        },
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn timeunits_declaration(s: Span) -> IResult<Span, TimeunitsDeclaration> {
    alt((
        timeunits_declaration_timeunit_timeprecision,
        timeunits_declaration_timeunit,
        timeunits_declaration_timeprecision_timeunit,
        timeunits_declaration_timeprecision,
    ))(s)
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn timeunits_declaration_timeunit(s: Span) -> IResult<Span, TimeunitsDeclaration> {
    let (s, a) = keyword("timeunit")(s)?;
    let (s, b) = time_literal(s)?;
    let (s, c) = opt(pair(symbol("/"), time_literal))(s)?;
    let (s, d) = symbol(";")(s)?;
    Ok((
        s,
        TimeunitsDeclaration::Timeunit(Box::new(TimeunitsDeclarationTimeunit {
            nodes: (a, b, c, d),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn timeunits_declaration_timeprecision(s: Span) -> IResult<Span, TimeunitsDeclaration> {
    let (s, a) = keyword("timeprecision")(s)?;
    let (s, b) = time_literal(s)?;
    let (s, c) = symbol(";")(s)?;
    Ok((
        s,
        TimeunitsDeclaration::Timeprecision(Box::new(TimeunitsDeclarationTimeprecision {
            nodes: (a, b, c),
        })),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn timeunits_declaration_timeunit_timeprecision(
    s: Span,
) -> IResult<Span, TimeunitsDeclaration> {
    let (s, a) = keyword("timeunit")(s)?;
    let (s, b) = time_literal(s)?;
    let (s, c) = symbol(";")(s)?;
    let (s, d) = keyword("timeprecision")(s)?;
    let (s, e) = time_literal(s)?;
    let (s, f) = symbol(";")(s)?;
    Ok((
        s,
        TimeunitsDeclaration::TimeunitTimeprecision(Box::new(
            TimeunitsDeclarationTimeunitTimeprecision {
                nodes: (a, b, c, d, e, f),
            },
        )),
    ))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn timeunits_declaration_timeprecision_timeunit(
    s: Span,
) -> IResult<Span, TimeunitsDeclaration> {
    let (s, a) = keyword("timeprecision")(s)?;
    let (s, b) = time_literal(s)?;
    let (s, c) = symbol(";")(s)?;
    let (s, d) = keyword("timeunit")(s)?;
    let (s, e) = time_literal(s)?;
    let (s, f) = symbol(";")(s)?;
    Ok((
        s,
        TimeunitsDeclaration::TimeprecisionTimeunit(Box::new(
            TimeunitsDeclarationTimeprecisionTimeunit {
                nodes: (a, b, c, d, e, f),
            },
        )),
    ))
}